1 21 package oracle.toplink.essentials.transaction; 23 24 import javax.transaction.*; 25 import oracle.toplink.essentials.exceptions.TransactionException; 26 27 59 public class JTATransactionController extends AbstractTransactionController { 60 protected TransactionManager transactionManager; 62 63 67 public JTATransactionController() { 68 super(); 69 listenerFactory = (SynchronizationListenerFactory)new JTASynchronizationListener(); 70 try { 71 transactionManager = acquireTransactionManager(); 72 } catch (Exception ex) { 73 throw TransactionException.errorObtainingTransactionManager(ex); 74 } 75 } 76 77 85 protected void registerSynchronization_impl(AbstractSynchronizationListener listener, Object txn) throws Exception { 86 ((Transaction)txn).registerSynchronization((Synchronization)listener); 87 } 88 89 96 protected Object getTransaction_impl() throws Exception { 97 return getTransactionManager().getTransaction(); 98 } 99 100 109 protected Object getTransactionKey_impl(Object transaction) throws Exception { 110 return transaction; 112 } 113 114 121 protected Object getTransactionStatus_impl() throws Exception { 122 return new Integer (getTransactionManager().getStatus()); 123 } 124 125 129 protected void beginTransaction_impl() throws Exception { 130 getTransactionManager().begin(); 131 } 132 133 137 protected void commitTransaction_impl() throws Exception { 138 getTransactionManager().commit(); 139 } 140 141 145 protected void rollbackTransaction_impl() throws Exception { 146 getTransactionManager().rollback(); 147 } 148 149 153 protected void markTransactionForRollback_impl() throws Exception { 154 getTransactionManager().setRollbackOnly(); 155 } 156 157 165 protected boolean canBeginTransaction_impl(Object status) { 166 return getIntStatus(status) == Status.STATUS_NO_TRANSACTION; 167 } 168 169 177 protected boolean canCommitTransaction_impl(Object status) { 178 return getIntStatus(status) == Status.STATUS_ACTIVE; 179 } 180 181 189 protected boolean canRollbackTransaction_impl(Object status) { 190 return getIntStatus(status) == Status.STATUS_ACTIVE; 191 } 192 193 201 protected boolean canIssueSQLToDatabase_impl(Object status) { 202 int stat = getIntStatus(status); 203 return ((stat == Status.STATUS_ACTIVE) || (stat == Status.STATUS_PREPARING)); 204 } 205 206 215 protected boolean canMergeUnitOfWork_impl(Object status) { 216 return getIntStatus(status) == Status.STATUS_COMMITTED; 217 } 218 219 223 public boolean isRolledBack_impl(Object status) { 224 return getIntStatus(status) == Status.STATUS_ROLLEDBACK; 225 } 226 227 241 protected TransactionManager acquireTransactionManager() throws Exception { 242 return null; 243 } 244 245 250 protected int getIntStatus(Object status) { 251 return ((Integer )status).intValue(); 252 } 253 254 261 public TransactionManager getTransactionManager() { 262 return transactionManager; 263 } 264 265 273 public void setTransactionManager(TransactionManager mgr) { 274 transactionManager = mgr; 275 } 276 277 281 static String [] codes = { "STATUS_ACTIVE", "MARKED_ROLLBACK", "PREPARED", "COMMITTED", "ROLLEDBACK", "UNKNOWN", "NO_TRANSACTION", "PREPARING", "COMMITTING", "ROLLING_BACK" }; 282 283 protected String statusToString_impl(Object status) { 284 int statusCode = getIntStatus(status); 285 return codes[statusCode]; 286 } 287 } 288 | Popular Tags |