1 22 package org.jboss.ejb3.embedded; 23 24 import java.io.IOException ; 25 import java.io.ObjectInput ; 26 import java.io.ObjectOutput ; 27 import javax.transaction.HeuristicMixedException ; 28 import javax.transaction.HeuristicRollbackException ; 29 import javax.transaction.NotSupportedException ; 30 import javax.transaction.RollbackException ; 31 import javax.transaction.SystemException ; 32 import javax.transaction.Transaction ; 33 import javax.transaction.TransactionManager ; 34 import javax.transaction.UserTransaction ; 35 import org.jboss.logging.Logger; 36 import org.jboss.ejb3.tx.TxUtil; 37 38 44 public final class UserTransactionImpl implements UserTransaction , java.io.Externalizable 45 { 46 protected static Logger log = Logger.getLogger(UserTransactionImpl.class); 47 48 52 private TransactionManager tm; 53 54 public UserTransactionImpl() 55 { 56 } 57 58 public void start() 59 { 60 if (log.isDebugEnabled()) 61 log.debug("new UserTx: " + this); 62 this.tm = TxUtil.getTransactionManager(); 63 } 64 65 public void stop() 66 { 67 this.tm = null; 68 } 69 70 public void begin() 71 throws NotSupportedException , SystemException 72 { 73 tm.begin(); 75 76 Transaction tx = tm.getTransaction(); 77 if (log.isDebugEnabled()) 78 log.debug("UserTx begin: " + tx); 79 80 } 81 82 public void commit() 83 throws RollbackException , HeuristicMixedException , HeuristicRollbackException , 84 SecurityException , IllegalStateException , SystemException 85 { 86 Transaction tx = tm.getTransaction(); 87 if (log.isDebugEnabled()) 88 log.debug("UserTx commit: " + tx); 89 90 tm.commit(); 91 } 92 93 public void rollback() 94 throws IllegalStateException , SecurityException , SystemException 95 { 96 Transaction tx = tm.getTransaction(); 97 if (log.isDebugEnabled()) 98 log.debug("UserTx rollback: " + tx); 99 tm.rollback(); 100 } 101 102 public void setRollbackOnly() 103 throws IllegalStateException , SystemException 104 { 105 Transaction tx = tm.getTransaction(); 106 if (log.isDebugEnabled()) 107 log.debug("UserTx setRollbackOnly: " + tx); 108 109 tm.setRollbackOnly(); 110 } 111 112 public int getStatus() 113 throws SystemException 114 { 115 return tm.getStatus(); 116 } 117 118 122 public void setTransactionTimeout(int seconds) 123 throws SystemException 124 { 125 tm.setTransactionTimeout(seconds); 126 } 127 128 public void writeExternal(ObjectOutput out) throws IOException 129 { 130 } 132 133 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 134 { 135 this.tm = TxUtil.getTransactionManager(); 136 } 137 138 } 139 | Popular Tags |