1 22 package org.jboss.test.recover.bean; 23 24 import javax.ejb.EJBException ; 25 import javax.naming.Context ; 26 import javax.naming.InitialContext ; 27 import javax.naming.NamingException ; 28 import javax.transaction.RollbackException ; 29 import javax.transaction.SystemException ; 30 import javax.transaction.Transaction ; 31 import javax.transaction.TransactionManager ; 32 import javax.transaction.xa.XAResource ; 33 34 import org.jboss.logging.Logger; 35 import org.jboss.test.util.ejb.SessionSupport; 36 import org.jboss.tm.recovery.Recoverable; 37 38 44 public class XAResourceEnlisterBean 45 extends SessionSupport 46 { 47 private static final Logger log = 48 Logger.getLogger(XAResourceEnlisterBean.class); 49 50 private TransactionManager tm; 51 private Recoverable recoverable1; 52 private Recoverable recoverable2; 53 private Recoverable recoverable3; 54 55 public void ejbCreate() 56 { 57 try 58 { 59 Context ctx = new InitialContext (); 60 tm = (TransactionManager ) ctx.lookup("java:/TransactionManager"); 61 recoverable1 = (Recoverable) ctx.lookup("DummyRecoverableProxy1"); 62 recoverable2 = (Recoverable) ctx.lookup("DummyRecoverableProxy2"); 63 recoverable3 = (Recoverable) ctx.lookup("DummyRecoverableProxy3"); 64 } 65 catch (NamingException e) 66 { 67 throw new EJBException (e); 68 } 69 } 70 71 public void method() 72 { 73 log.info("method called"); 74 try 75 { 76 Transaction tx = tm.getTransaction(); 77 log.info("tx=" + tx); 78 79 XAResource xaRes1 = recoverable1.getResource(); 80 tx.enlistResource(xaRes1); 81 log.info("enlisted xaRes1=" + xaRes1); 82 XAResource xaRes2 = recoverable2.getResource(); 83 tx.enlistResource(xaRes2); 84 log.info("enlisted xaRes2=" + xaRes2); 85 XAResource xaRes3 = recoverable3.getResource(); 86 tx.enlistResource(xaRes3); 87 log.info("enlisted xaRes3=" + xaRes3); 88 } 89 catch (SystemException e) 90 { 91 log.info(e); 92 throw new EJBException (e); 93 } 94 catch (RollbackException e) 95 { 96 log.info(e); 97 throw new EJBException (e); 98 } 99 } 100 101 public void enlistXAResource(int i) 102 { 103 log.info("enlistXAResrouce(" + i + ") called"); 104 try 105 { 106 XAResource xaRes; 107 Transaction tx = tm.getTransaction(); 108 log.info("tx=" + tx); 109 110 switch (i) 111 { 112 case 1: 113 xaRes = recoverable1.getResource(); 114 tx.enlistResource(xaRes); 115 log.info("enlisted xaRes1=" + xaRes); 116 break; 117 case 2: 118 xaRes = recoverable2.getResource(); 119 tx.enlistResource(xaRes); 120 log.info("enlisted xaRes2=" + xaRes); 121 break; 122 case 3: 123 xaRes = recoverable3.getResource(); 124 tx.enlistResource(xaRes); 125 log.info("enlisted xaRes3=" + xaRes); 126 break; 127 default: 128 throw new EJBException ("There is no XAResource " + i); 129 } 130 } 131 catch (SystemException e) 132 { 133 log.info(e); 134 throw new EJBException (e); 135 } 136 catch (RollbackException e) 137 { 138 log.info(e); 139 throw new EJBException (e); 140 } 141 142 } 143 } 144 | Popular Tags |