1 22 package org.jboss.tm.usertx.client; 23 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.EventListener ; 28 import java.util.Iterator ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 import javax.transaction.HeuristicMixedException ; 32 import javax.transaction.HeuristicRollbackException ; 33 import javax.transaction.NotSupportedException ; 34 import javax.transaction.RollbackException ; 35 import javax.transaction.SystemException ; 36 import javax.transaction.TransactionManager ; 37 import javax.transaction.UserTransaction ; 38 39 40 49 public class ServerVMClientUserTransaction 50 implements UserTransaction 51 { 52 54 57 private final static ServerVMClientUserTransaction singleton = new ServerVMClientUserTransaction(); 58 59 60 63 private final TransactionManager tm; 64 65 66 private final Collection listeners = new ArrayList (); 67 68 71 public static ServerVMClientUserTransaction getSingleton() 72 { 73 return singleton; 74 } 75 76 77 79 82 private ServerVMClientUserTransaction() 83 { 84 TransactionManager local = null; 86 try { 87 local = (TransactionManager )new InitialContext ().lookup("java:/TransactionManager"); 88 89 } catch (NamingException ex) 90 { 91 } 93 tm = local; 94 } 95 public ServerVMClientUserTransaction(final TransactionManager tm) 97 { 98 this.tm = tm; 99 } 100 101 103 105 public void registerTxStartedListener(UserTransactionStartedListener txStartedListener) 106 { 107 listeners.add(txStartedListener); 108 } 109 110 public void unregisterTxStartedListener(UserTransactionStartedListener txStartedListener) 111 { 112 listeners.remove(txStartedListener); 113 } 114 115 119 public void begin() 120 throws NotSupportedException , SystemException 121 { 122 tm.begin(); 123 for (Iterator i = listeners.iterator(); i.hasNext(); ) 124 { 125 ((UserTransactionStartedListener)i.next()).userTransactionStarted(); 126 } 128 } 129 130 public void commit() 131 throws RollbackException , 132 HeuristicMixedException , 133 HeuristicRollbackException , 134 SecurityException , 135 IllegalStateException , 136 SystemException 137 { 138 tm.commit(); 139 } 140 141 public void rollback() 142 throws SecurityException , 143 IllegalStateException , 144 SystemException 145 { 146 tm.rollback(); 147 } 148 149 public void setRollbackOnly() 150 throws IllegalStateException , 151 SystemException 152 { 153 tm.setRollbackOnly(); 154 } 155 156 public int getStatus() 157 throws SystemException 158 { 159 return tm.getStatus(); 160 } 161 162 public void setTransactionTimeout(int seconds) 163 throws SystemException 164 { 165 tm.setTransactionTimeout(seconds); 166 } 167 168 public interface UserTransactionStartedListener extends EventListener 169 { 170 void userTransactionStarted() throws SystemException ; 171 } 172 173 174 } 175 | Popular Tags |