1 package org.jboss.cache.transaction; 2 3 import javax.transaction.HeuristicMixedException ; 4 import javax.transaction.HeuristicRollbackException ; 5 import javax.transaction.InvalidTransactionException ; 6 import javax.transaction.NotSupportedException ; 7 import javax.transaction.RollbackException ; 8 import javax.transaction.Status ; 9 import javax.transaction.SystemException ; 10 import javax.transaction.Transaction ; 11 import javax.transaction.TransactionManager ; 12 13 19 public class DummyBaseTransactionManager implements TransactionManager , java.io.Serializable  20 { 21 static ThreadLocal <Transaction > thread_local = new ThreadLocal <Transaction >(); 22 private static final long serialVersionUID = -6716097342564237376l; 23 24 35 public void begin() throws NotSupportedException , SystemException  36 { 37 Transaction currentTx; 38 if ((currentTx = getTransaction()) != null) 39 throw new NotSupportedException (Thread.currentThread() + 40 " is already associated with a transaction (" + currentTx + ")"); 41 DummyTransaction tx = new DummyTransaction(this); 42 setTransaction(tx); 43 } 44 45 67 public void commit() throws RollbackException , HeuristicMixedException , 68 HeuristicRollbackException , SecurityException , 69 IllegalStateException , SystemException  70 { 71 int status; 72 Transaction tx = getTransaction(); 73 if (tx == null) 74 throw new IllegalStateException ("thread not associated with transaction"); 75 status = tx.getStatus(); 76 if (status == Status.STATUS_MARKED_ROLLBACK) 77 throw new RollbackException (); 78 tx.commit(); 79 80 setTransaction(null); 82 } 83 84 98 public void rollback() throws IllegalStateException , SecurityException , 99 SystemException  100 { 101 Transaction tx = getTransaction(); 102 if (tx == null) 103 throw new IllegalStateException ("no transaction associated with thread"); 104 tx.rollback(); 105 106 setTransaction(null); 108 } 109 110 123 public void setRollbackOnly() throws IllegalStateException , SystemException  124 { 125 Transaction tx = getTransaction(); 126 if (tx == null) 127 throw new IllegalStateException ("no transaction associated with calling thread"); 128 tx.setRollbackOnly(); 129 } 130 131 142 public int getStatus() throws SystemException  143 { 144 Transaction tx = getTransaction(); 145 return tx != null ? tx.getStatus() : Status.STATUS_NO_TRANSACTION; 146 } 147 148 158 public Transaction getTransaction() throws SystemException  159 { 160 return thread_local.get(); 161 } 162 163 174 public void setTransactionTimeout(int seconds) throws SystemException  175 { 176 throw new SystemException ("not supported"); 177 } 178 179 192 public Transaction suspend() throws SystemException  193 { 194 Transaction retval = getTransaction(); 195 setTransaction(null); 196 return retval; 197 } 198 199 213 public void resume(Transaction tx) throws InvalidTransactionException , IllegalStateException , SystemException  214 { 215 setTransaction(tx); 216 } 217 218 223 public void setTransaction(Transaction tx) 224 { 225 thread_local.set(tx); 226 } 227 228 } 229 | Popular Tags |