1 17 package org.alfresco.repo.search.transaction; 18 19 import javax.transaction.HeuristicMixedException ; 20 import javax.transaction.HeuristicRollbackException ; 21 import javax.transaction.InvalidTransactionException ; 22 import javax.transaction.NotSupportedException ; 23 import javax.transaction.RollbackException ; 24 import javax.transaction.SystemException ; 25 import javax.transaction.Transaction ; 26 import javax.transaction.TransactionManager ; 27 28 public class SimpleTransactionManager implements TransactionManager 29 { 30 private static SimpleTransactionManager manager = new SimpleTransactionManager(); 31 32 private int timeout; 33 34 private SimpleTransactionManager() 35 { 36 super(); 37 } 38 39 public static SimpleTransactionManager getInstance() 40 { 41 return manager; 42 } 43 44 public void begin() throws NotSupportedException , SystemException 45 { 46 SimpleTransaction.begin(); 47 48 } 49 50 public void commit() throws RollbackException , HeuristicMixedException , HeuristicRollbackException , 51 SecurityException , IllegalStateException , SystemException 52 { 53 SimpleTransaction transaction = getTransactionChecked(); 54 transaction.commit(); 55 } 56 57 public int getStatus() throws SystemException 58 { 59 SimpleTransaction transaction = getTransactionChecked(); 60 return transaction.getStatus(); 61 } 62 63 public SimpleTransaction getTransaction() throws SystemException 64 { 65 return SimpleTransaction.getTransaction(); 66 } 67 68 private SimpleTransaction getTransactionChecked() throws SystemException , IllegalStateException 69 { 70 SimpleTransaction tx = SimpleTransaction.getTransaction(); 71 if (tx == null) 72 { 73 throw new IllegalStateException ("The thread is not bound to a transaction."); 74 } 75 return tx; 76 } 77 78 public void resume(Transaction tx) throws InvalidTransactionException , IllegalStateException , SystemException 79 { 80 if (!(tx instanceof SimpleTransaction)) 81 { 82 throw new IllegalStateException ("Transaction must be a SimpleTransaction to resume"); 83 } 84 SimpleTransaction.resume((SimpleTransaction) tx); 85 } 86 87 public void rollback() throws IllegalStateException , SecurityException , SystemException 88 { 89 SimpleTransaction transaction = getTransactionChecked(); 90 transaction.rollback(); 91 } 92 93 public void setRollbackOnly() throws IllegalStateException , SystemException 94 { 95 SimpleTransaction transaction = getTransactionChecked(); 96 transaction.setRollbackOnly(); 97 } 98 99 public void setTransactionTimeout(int timeout) throws SystemException 100 { 101 this.timeout = timeout; 102 } 103 104 public SimpleTransaction suspend() throws SystemException 105 { 106 return SimpleTransaction.suspend(); 107 } 108 109 } 110 | Popular Tags |