1 29 30 package com.caucho.jca; 31 32 import com.caucho.log.Log; 33 import com.caucho.transaction.TransactionManagerImpl; 34 import com.caucho.util.L10N; 35 36 import javax.transaction.HeuristicMixedException ; 37 import javax.transaction.HeuristicRollbackException ; 38 import javax.transaction.NotSupportedException ; 39 import javax.transaction.RollbackException ; 40 import javax.transaction.SystemException ; 41 import javax.transaction.UserTransaction ; 42 import javax.transaction.xa.XAException ; 43 import javax.transaction.xa.XAResource ; 44 import java.util.logging.Logger ; 45 46 49 public class UserTransactionProxy implements UserTransaction { 50 private static final Logger log = Log.open(UserTransactionProxy.class); 51 private static final L10N L = new L10N(UserTransactionProxy.class); 52 53 57 private static final UserTransactionProxy _proxy 58 = new UserTransactionProxy(); 59 60 private static final ThreadLocal <UserTransactionImpl> _threadTransaction 61 = new ThreadLocal <UserTransactionImpl>(); 62 63 66 private UserTransactionProxy() 67 { 68 72 } 73 74 77 public static UserTransactionProxy getInstance() 78 { 79 return _proxy; 81 } 82 83 86 public UserTransactionImpl getTransaction() 87 { 88 UserTransactionImpl xa = _threadTransaction.get(); 89 90 if (xa == null) { 91 xa = new UserTransactionImpl(TransactionManagerImpl.getLocal()); 92 _threadTransaction.set(xa); 93 } 94 95 return xa; 96 } 97 98 101 public void setTransactionTimeout(int seconds) 102 throws SystemException 103 { 104 getTransaction().setTransactionTimeout(seconds); 105 } 106 107 110 public int getStatus() 111 throws SystemException 112 { 113 return getTransaction().getStatus(); 114 } 115 116 119 public void begin() 120 throws NotSupportedException , SystemException 121 { 122 getTransaction().begin(); 123 } 124 125 128 public void setRollbackOnly() 129 throws IllegalStateException , SystemException 130 { 131 getTransaction().setRollbackOnly(); 132 } 133 134 137 public void commit() 138 throws IllegalStateException , RollbackException , HeuristicMixedException , 139 HeuristicRollbackException , SecurityException , SystemException 140 { 141 getTransaction().commit(); 142 } 143 144 147 public void rollback() 148 throws IllegalStateException , SecurityException , SystemException 149 { 150 getTransaction().rollback(); 151 } 152 153 156 public void enlistBeginResource(BeginResource resource) 157 throws IllegalStateException 158 { 159 getTransaction().enlistBeginResource(resource); 160 } 161 162 165 public void enlistCloseResource(CloseResource resource) 166 throws IllegalStateException 167 { 168 getTransaction().enlistCloseResource(resource); 169 } 170 171 174 public void abortTransaction() 175 throws IllegalStateException 176 { 177 UserTransactionImpl xa = _threadTransaction.get(); 178 179 if (xa == null) 180 return; 181 182 xa.abortTransaction(); 183 } 184 185 188 void recover(XAResource xaRes) 189 throws XAException 190 { 191 TransactionManagerImpl.getLocal().recover(xaRes); 192 } 193 194 public String toString() 195 { 196 return "UserTransactionProxy[]"; 197 } 198 } 199 200 | Popular Tags |