1 16 package com.ibatis.sqlmap.engine.scope; 17 18 import com.ibatis.sqlmap.client.SqlMapClient; 19 import com.ibatis.sqlmap.client.SqlMapExecutor; 20 import com.ibatis.sqlmap.client.SqlMapTransactionManager; 21 import com.ibatis.sqlmap.engine.transaction.Transaction; 22 import com.ibatis.sqlmap.engine.transaction.TransactionState; 23 24 27 public class SessionScope extends BaseScope { 28 29 private static long nextId; 30 31 private long id; 32 33 private SqlMapClient sqlMapClient; 35 private SqlMapExecutor sqlMapExecutor; 36 private SqlMapTransactionManager sqlMapTxMgr; 37 private int requestStackDepth; 38 39 private Transaction transaction; 41 private TransactionState transactionState; 42 43 private TransactionState savedTransactionState; 45 46 private boolean inBatch; 48 49 private Object batch; 51 52 private boolean commitRequired; 53 54 57 public SessionScope() { 58 reset(); 59 } 60 61 66 public SqlMapClient getSqlMapClient() { 67 return sqlMapClient; 68 } 69 70 75 public void setSqlMapClient(SqlMapClient sqlMapClient) { 76 this.sqlMapClient = sqlMapClient; 77 } 78 79 84 public SqlMapExecutor getSqlMapExecutor() { 85 return sqlMapExecutor; 86 } 87 88 93 public void setSqlMapExecutor(SqlMapExecutor sqlMapExecutor) { 94 this.sqlMapExecutor = sqlMapExecutor; 95 } 96 97 102 public SqlMapTransactionManager getSqlMapTxMgr() { 103 return sqlMapTxMgr; 104 } 105 106 111 public void setSqlMapTxMgr(SqlMapTransactionManager sqlMapTxMgr) { 112 this.sqlMapTxMgr = sqlMapTxMgr; 113 } 114 115 120 public boolean isInBatch() { 121 return inBatch; 122 } 123 124 129 public void setInBatch(boolean inBatch) { 130 this.inBatch = inBatch; 131 } 132 133 138 public Transaction getTransaction() { 139 return transaction; 140 } 141 142 147 public void setTransaction(Transaction transaction) { 148 this.transaction = transaction; 149 } 150 151 156 public TransactionState getTransactionState() { 157 return transactionState; 158 } 159 160 165 public void setTransactionState(TransactionState transactionState) { 166 this.transactionState = transactionState; 167 } 168 169 174 public Object getBatch() { 175 return batch; 176 } 177 178 183 public void setBatch(Object batch) { 184 this.batch = batch; 185 } 186 187 192 public int getRequestStackDepth() { 193 return requestStackDepth; 194 } 195 196 199 public void incrementRequestStackDepth() { 200 requestStackDepth++; 201 } 202 203 206 public void decrementRequestStackDepth() { 207 requestStackDepth--; 208 } 209 210 215 public boolean isCommitRequired() { 216 return commitRequired; 217 } 218 219 224 public void setCommitRequired(boolean commitRequired) { 225 this.commitRequired = commitRequired; 226 } 227 228 public void reset() { 229 super.reset(); 230 this.batch = null; 231 sqlMapExecutor = null; 232 sqlMapTxMgr = null; 233 inBatch = false; 234 transaction = null; 235 transactionState = null; 236 batch = null; 237 requestStackDepth = 0; 238 id = getNextId(); 239 } 240 241 public boolean equals(Object parameterObject) { 242 if (this == parameterObject) return true; 243 if (!(parameterObject instanceof SessionScope)) return false; 244 245 final SessionScope sessionScope = (SessionScope) parameterObject; 246 247 if (id != sessionScope.id) return false; 248 249 return true; 250 } 251 252 public int hashCode() { 253 return (int) (id ^ (id >>> 32)); 254 } 255 256 261 public synchronized static long getNextId() { 262 return nextId++; 263 } 264 265 268 public void saveTransactionState() { 269 savedTransactionState = transactionState; 270 } 271 272 275 public void recallTransactionState() { 276 transactionState = savedTransactionState; 277 } 278 } 279 | Popular Tags |