1 22 package org.jboss.test.perf.ejb; 23 24 import java.rmi.RemoteException ; 25 import javax.ejb.CreateException ; 26 import javax.ejb.EJBException ; 27 import javax.ejb.SessionBean ; 28 import javax.ejb.SessionContext ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 import javax.transaction.Transaction ; 33 import javax.transaction.TransactionManager ; 34 35 import org.jboss.test.perf.interfaces.TxSession; 36 37 public class TxSessionBean implements SessionBean 38 { 39 private SessionContext sessionContext; 40 private InitialContext iniCtx; 41 42 public void ejbCreate() throws CreateException 43 { 44 } 45 46 public void ejbActivate() 47 { 48 } 49 50 public void ejbPassivate() 51 { 52 } 53 54 public void ejbRemove() 55 { 56 } 57 58 public void setSessionContext(SessionContext context) 59 { 60 sessionContext = context; 61 try 62 { 63 iniCtx = new InitialContext (); 64 } 65 catch(NamingException e) 66 { 67 throw new EJBException (e); 68 } 69 } 70 71 74 public String txRequired() 75 { 76 Transaction tx = getDaTransaction(); 77 if (tx == null) 78 throw new EJBException ("Required sees no transaction"); 79 else 80 return ("required sees a transaction "+tx.hashCode()); 81 } 82 83 84 87 public String txRequiresNew() 88 { 89 Object tx =getDaTransaction(); 90 if (tx == null) 91 throw new EJBException ("RequiresNew sees no transaction"); 92 else 93 return ("requiresNew sees a transaction "+tx.hashCode()); 94 } 95 96 99 public String txSupports() 100 { 101 Object tx =getDaTransaction(); 102 if (tx == null) 103 return "supports sees no transaction"; 104 else 105 return "supports sees a transaction "+tx.hashCode(); 106 } 107 108 111 public String txMandatory() 112 { 113 Object tx =getDaTransaction(); 114 if (tx == null) 115 throw new EJBException ("Mandatory sees no transaction"); 116 else 117 return ("mandatory sees a transaction "+tx.hashCode()); 118 } 119 120 123 public String txNever() 124 { 125 Object tx =getDaTransaction(); 126 if (tx == null) 127 return "never sees no transaction"; 128 else 129 throw new EJBException ("txNever sees a transaction"); 130 } 131 132 135 public String txNotSupported() 136 { 137 Object tx =getDaTransaction(); 138 if (tx == null) 139 return "notSupported sees no transaction"; 140 else 141 throw new EJBException ("txNotSupported sees a transaction"); 142 } 143 144 147 public String requiredToSupports() throws RemoteException 148 { 149 String message; 150 Object tx =getDaTransaction(); 151 if (tx == null) 152 throw new EJBException ("Required doesn't see a transaction"); 153 else 154 message = "Required sees a transaction "+tx.hashCode()+ " Supports should see the same "; 155 156 message = message + ((TxSession) sessionContext.getEJBObject()).txSupports(); 157 158 tx =getDaTransaction(); 160 if (tx == null) 161 throw new EJBException ("Required doesn't see a transaction COMING BACK"); 162 else 163 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 164 165 } 166 167 170 public String requiredToMandatory() throws RemoteException 171 { 172 String message; 173 Object tx =getDaTransaction(); 174 if (tx == null) 175 throw new EJBException ("Required doesn't see a transaction"); 176 else 177 message = "Required sees a transaction "+tx.hashCode()+ " NotSupported should see the same "; 178 179 180 message = message + ((TxSession) sessionContext.getEJBObject()).txMandatory(); 181 182 tx =getDaTransaction(); 184 if (tx == null) 185 throw new EJBException ("Required doesn't see a transaction COMING BACK"); 186 else 187 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 188 } 189 190 public String requiredToRequiresNew() throws RemoteException 191 { 192 String message; 193 Object tx =getDaTransaction(); 194 if (tx == null) 195 throw new EJBException ("Required doesn't see a transaction"); 196 else 197 message = "Required sees a transaction "+tx.hashCode()+ " Requires new should see a new transaction "; 198 199 message = message + ((TxSession) sessionContext.getEJBObject()).txRequiresNew(); 200 201 tx = getDaTransaction(); 203 if (tx == null) 204 throw new EJBException ("Required doesn't see a transaction COMING BACK"); 205 else 206 return message + " on coming back Required sees a transaction "+tx.hashCode() ; 207 } 208 209 private Transaction getDaTransaction() 210 { 211 Transaction t = null; 212 try 213 { 214 TransactionManager tm = (TransactionManager ) iniCtx.lookup("java:/TransactionManager"); 215 t = tm.getTransaction(); 216 } 217 catch(Exception e) 218 { 219 } 220 return t; 221 } 222 223 } 224 | Popular Tags |