1 23 24 package com.sun.enterprise.distributedtx; 25 26 import javax.transaction.TransactionSynchronizationRegistry ; 27 import com.sun.enterprise.Switch; 28 import com.sun.enterprise.util.i18n.StringManager; 29 import javax.transaction.Synchronization ; 30 import javax.transaction.Status ; 31 import javax.transaction.SystemException ; 32 33 public class TransactionSynchronizationRegistryImpl 34 implements TransactionSynchronizationRegistry { 35 36 61 public Object getTransactionKey() { 62 try { 63 return Switch.getSwitch().getTransactionManager().getTransaction(); 64 } catch (SystemException ex) { 65 return null; 66 } 67 } 68 69 84 public void putResource(Object key, Object value) { 85 try { 86 J2EETransaction tran = (J2EETransaction)Switch.getSwitch(). 87 getTransactionManager().getTransaction(); 88 if (tran == null) 89 throw new IllegalStateException ( 90 sm.getString("enterprise_distributedtx.no_transaction")); 91 tran.putUserResource(key, value); 92 } catch (SystemException ex) { 93 throw new IllegalStateException ( 94 sm.getString("enterprise_distributedtx.no_transaction")); 95 } 96 } 97 98 111 public Object getResource(Object key){ 112 try { 113 J2EETransaction tran = (J2EETransaction)Switch.getSwitch(). 114 getTransactionManager().getTransaction(); 115 if (tran == null) 116 throw new IllegalStateException ( 117 sm.getString("enterprise_distributedtx.no_transaction")); 118 return tran.getUserResource(key); 119 } catch (SystemException ex) { 120 throw new IllegalStateException ( 121 sm.getString("enterprise_distributedtx.no_transaction")); 122 } 123 } 124 125 160 public void registerInterposedSynchronization(Synchronization sync) { 161 try { 162 J2EETransaction tran = (J2EETransaction)Switch.getSwitch(). 163 getTransactionManager().getTransaction(); 164 if (tran == null) 165 throw new IllegalStateException ( 166 sm.getString("enterprise_distributedtx.no_transaction")); 167 tran.registerInterposedSynchronization(sync); 168 } catch (SystemException ex) { 169 throw new IllegalStateException ( 170 sm.getString("enterprise_distributedtx.no_transaction")); 171 } 172 } 173 174 181 public int getTransactionStatus() { 182 try { 183 return Switch.getSwitch().getTransactionManager().getStatus(); 184 } catch (SystemException ex) { 185 return Status.STATUS_NO_TRANSACTION; 186 } 187 } 188 189 196 public void setRollbackOnly() { 197 try { 198 Switch.getSwitch().getTransactionManager().setRollbackOnly(); 199 } catch (SystemException ex) { 200 throw new IllegalStateException ( 201 sm.getString("enterprise_distributedtx.no_transaction")); 202 } 203 } 204 205 214 public boolean getRollbackOnly() { 215 { 216 int status = getTransactionStatus(); 217 if ( status == Status.STATUS_NO_TRANSACTION ) { 218 throw new IllegalStateException ( 219 sm.getString("enterprise_distributedtx.no_transaction")); 220 } 221 if ( status == Status.STATUS_MARKED_ROLLBACK 222 || status == Status.STATUS_ROLLING_BACK ) 223 return true; 224 else 225 return false; 226 } 227 } 228 229 public static TransactionSynchronizationRegistry getInstance() { 230 return _instance; 231 } 232 233 private static TransactionSynchronizationRegistryImpl _instance = 234 new TransactionSynchronizationRegistryImpl(); 235 private static StringManager sm = 236 StringManager.getManager(TransactionSynchronizationRegistryImpl.class); 237 } 238 | Popular Tags |