1 17 18 package org.apache.geronimo.transaction; 19 20 import java.io.Serializable ; 21 import javax.transaction.HeuristicMixedException ; 22 import javax.transaction.HeuristicRollbackException ; 23 import javax.transaction.NotSupportedException ; 24 import javax.transaction.RollbackException ; 25 import javax.transaction.SystemException ; 26 import javax.transaction.TransactionManager ; 27 import javax.transaction.UserTransaction ; 28 29 public final class GeronimoUserTransaction implements UserTransaction , Serializable { 30 private static final long serialVersionUID = -7524804683512228998L; 31 private transient TransactionManager transactionManager; 32 33 public GeronimoUserTransaction(TransactionManager transactionManager) { 34 this.transactionManager = transactionManager; 35 } 36 37 boolean isActive() { 38 return transactionManager != null; 39 } 40 41 public void setTransactionManager(TransactionManager transactionManager) { 42 if (this.transactionManager == null) { 43 this.transactionManager = transactionManager; 44 } else if (this.transactionManager != transactionManager) { 45 throw new IllegalStateException ("This user transaction is already associated with another transaction manager"); 46 } 47 } 48 49 50 public int getStatus() throws SystemException { 51 return transactionManager.getStatus(); 52 } 53 54 public void setRollbackOnly() throws IllegalStateException , SystemException { 55 transactionManager.setRollbackOnly(); 56 } 57 58 public void setTransactionTimeout(int seconds) throws SystemException { 59 if (seconds < 0) { 60 throw new SystemException ("transaction timeout must be positive or 0, not " + seconds); 61 } 62 transactionManager.setTransactionTimeout(seconds); 63 } 64 65 public void begin() throws NotSupportedException , SystemException { 66 transactionManager.begin(); 67 } 68 69 public void commit() throws HeuristicMixedException , HeuristicRollbackException , IllegalStateException , RollbackException , SecurityException , SystemException { 70 transactionManager.commit(); 71 } 72 73 public void rollback() throws IllegalStateException , SecurityException , SystemException { 74 transactionManager.rollback(); 75 } 76 } 77 | Popular Tags |