1 9 package org.jboss.portal.core.impl.tree.tm; 10 11 import javax.transaction.Transaction ; 12 import javax.transaction.RollbackException ; 13 import javax.transaction.HeuristicMixedException ; 14 import javax.transaction.HeuristicRollbackException ; 15 import javax.transaction.SystemException ; 16 import javax.transaction.Synchronization ; 17 import javax.transaction.xa.XAResource ; 18 import java.util.List ; 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 22 30 public class TransactionObservation implements Transaction 31 { 32 33 34 private final List listeners; 35 36 37 private final TransactionManagerObserver observer; 38 39 40 final Transaction tx; 41 42 public TransactionObservation(TransactionManagerObserver observer, Transaction tx) 43 { 44 this.listeners = new ArrayList (); 45 this.tx = tx; 46 this.observer = observer; 47 } 48 49 54 public void addListener(TransactionListener listener) 55 { 56 listeners.add(listener); 57 } 58 59 void afterCommit() 60 { 61 for (Iterator i = listeners.iterator(); i.hasNext();) 62 { 63 TransactionListener listener = (TransactionListener)i.next(); 64 listener.afterCommit(); 65 } 66 } 67 68 void afterRollback() 69 { 70 for (Iterator i = listeners.iterator(); i.hasNext();) 71 { 72 TransactionListener listener = (TransactionListener)i.next(); 73 listener.afterRollack(); 74 } 75 } 76 77 public void commit() throws RollbackException , HeuristicMixedException , HeuristicRollbackException , SecurityException , SystemException 78 { 79 observer.commit(); 80 } 81 82 public void rollback() throws IllegalStateException , SystemException 83 { 84 observer.rollback(); 85 } 86 87 public void setRollbackOnly() throws IllegalStateException , SystemException 88 { 89 tx.setRollbackOnly(); 90 } 91 92 public int getStatus() throws SystemException 93 { 94 return tx.getStatus(); 95 } 96 97 public boolean enlistResource(XAResource xares) throws RollbackException , IllegalStateException , SystemException 98 { 99 return tx.enlistResource(xares); 100 } 101 102 public boolean delistResource(XAResource xares, int value) throws IllegalStateException , SystemException 103 { 104 return tx.delistResource(xares, value); 105 } 106 107 public void registerSynchronization(Synchronization synch) throws RollbackException , IllegalStateException , SystemException 108 { 109 tx.registerSynchronization(synch); 110 } 111 112 public int hashCode() 113 { 114 return tx.hashCode(); 115 } 116 117 public boolean equals(Object obj) 118 { 119 return ((TransactionObservation)obj).tx.equals(tx); 120 } 121 } 122 | Popular Tags |