1 45 46 package org.openejb.core; 47 48 49 import javax.transaction.HeuristicMixedException ; 50 import javax.transaction.HeuristicRollbackException ; 51 import javax.transaction.NotSupportedException ; 52 import javax.transaction.RollbackException ; 53 import javax.transaction.SystemException ; 54 import javax.transaction.TransactionManager ; 55 56 57 69 public class CoreUserTransaction 70 implements javax.transaction.UserTransaction , java.io.Serializable 71 { 72 73 74 79 private transient TransactionManager _txManager; 80 81 private transient final org.apache.log4j.Category txLogger; 82 83 84 87 public CoreUserTransaction(TransactionManager txMngr) 88 { 89 _txManager = txMngr; 90 txLogger=org.apache.log4j.Category.getInstance("Transaction"); 91 } 92 93 public CoreUserTransaction( ){ 94 this(org.openejb.OpenEJB.getTransactionManager()); 95 } 96 97 private TransactionManager transactionManager(){ 98 if(_txManager == null){ 99 _txManager = org.openejb.OpenEJB.getTransactionManager(); 100 } 101 return _txManager; 102 } 103 104 public void begin() 105 throws NotSupportedException , SystemException 106 { 107 transactionManager().begin(); 108 if(txLogger.isInfoEnabled()) { 109 txLogger.info("Started user transaction "+transactionManager().getTransaction()); 110 } 111 } 112 113 114 public void commit() 115 throws RollbackException , HeuristicMixedException , HeuristicRollbackException , 116 SecurityException , IllegalStateException , SystemException 117 { 118 if(txLogger.isInfoEnabled()) { 119 txLogger.info("Committing user transaction "+transactionManager().getTransaction()); 120 } 121 transactionManager().commit(); 122 } 123 124 125 public void rollback() 126 throws IllegalStateException , SecurityException , SystemException 127 { 128 if(txLogger.isInfoEnabled()) { 129 txLogger.info("Rolling back user transaction "+transactionManager().getTransaction()); 130 } 131 transactionManager().rollback(); 132 } 133 134 135 public int getStatus() 136 throws SystemException 137 { 138 int status = transactionManager().getStatus(); 139 if(txLogger.isInfoEnabled()) { 140 txLogger.info("User transaction "+transactionManager().getTransaction()+" has status "+org.openejb.core.TransactionManagerWrapper.getStatus(status)); 141 } 142 return status; 143 } 144 145 146 public void setRollbackOnly()throws javax.transaction.SystemException 147 { 148 if(txLogger.isInfoEnabled()) { 149 txLogger.info("Marking user transaction for rollback: "+transactionManager().getTransaction()); 150 } 151 transactionManager().setRollbackOnly(); 152 } 153 154 155 public void setTransactionTimeout( int seconds ) 156 throws SystemException 157 { 158 transactionManager().setTransactionTimeout( seconds ); 159 } 160 161 162 } | Popular Tags |