1 22 package org.jboss.test.dtm.ejb; 23 24 import java.rmi.RemoteException ; 25 26 import javax.ejb.EJBException ; 27 import javax.ejb.FinderException ; 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.rmi.PortableRemoteObject ; 31 32 import org.jboss.logging.Logger; 33 import org.jboss.test.dtm.interfaces.Account; 34 import org.jboss.test.dtm.interfaces.AccountHome; 35 import org.jboss.test.dtm.interfaces.AccountEntityHome; 36 import org.jboss.test.util.ejb.SessionSupport; 37 38 44 public class FrontEndBean 45 extends SessionSupport 46 { 47 private static transient Logger log = 48 Logger.getLogger(FrontEndBean.class); 49 50 private String testName; 51 private Account account1, account2, account3; 52 53 public void ejbCreate(String name) 54 { 55 ejbCreate(name, false); 56 } 57 58 public void ejbCreate(String name, boolean reuseAccounts) 59 { 60 this.testName = name; 61 log = Logger.getLogger(FrontEndBean.class.getName() + "#" + testName); 62 log.debug("ejbCreate(" + name + "), ctx=" + sessionCtx); 63 if (reuseAccounts) 64 findAccounts(); 65 else 66 initAccounts(); 67 68 } 69 70 public void setBalances(int value1, int value2, int value3) 71 { 72 try 73 { 74 account1.setBalance(value1); 75 account2.setBalance(value2); 76 account3.setBalance(value3); 77 } 78 catch (RemoteException e) 79 { 80 throw new EJBException (e); 81 } 82 } 83 84 public int[] getBalances() 85 { 86 try 87 { 88 int[] balances = new int[3]; 89 balances[0] = account1.getBalance(); 90 balances[1] = account2.getBalance(); 91 balances[2] = account3.getBalance(); 92 return balances; 93 } 94 catch (RemoteException e) 95 { 96 throw new EJBException (e); 97 } 98 } 99 100 public void addToBalances(int value) 101 { 102 try 103 { 104 account1.addToBalance(value); 105 account2.addToBalance(value); 106 account3.addToBalance(value); 107 } 108 catch (RemoteException e) 109 { 110 throw new EJBException (e); 111 } 112 } 113 114 public void setRollbackOnly() 115 { 116 sessionCtx.setRollbackOnly(); 117 } 118 119 public void tellFirstAccountToSetRollbackOnly() 120 { 121 try 122 { 123 account1.setRollbackOnly(); 124 } 125 catch (RemoteException e) 126 { 127 throw new EJBException (e); 128 } 129 } 130 131 public void tellSecondAccountToSetRollbackOnly() 132 { 133 try 134 { 135 account2.setRollbackOnly(); 136 } 137 catch (RemoteException e) 138 { 139 throw new EJBException (e); 140 } 141 } 142 143 public void tellThirdAccountToSetRollbackOnly() 144 { 145 try 146 { 147 account3.setRollbackOnly(); 148 } 149 catch (RemoteException e) 150 { 151 throw new EJBException (e); 152 } 153 } 154 155 private void initAccounts() 156 { 157 try 158 { 159 Object objref; 160 AccountHome home; 161 Context iniCtx = new InitialContext (); 162 163 objref = iniCtx.lookup("java:comp/env/ejb/Account1"); 164 home = (AccountHome) 165 PortableRemoteObject.narrow(objref, AccountHome.class); 166 account1 = home.create(testName + "#account1", 0); 167 168 objref = iniCtx.lookup("java:comp/env/ejb/Account2"); 169 home = (AccountHome) 170 PortableRemoteObject.narrow(objref, AccountHome.class); 171 account2 = home.create(testName + "#account2", 0); 172 173 objref = iniCtx.lookup("java:comp/env/ejb/Account3"); 174 home = (AccountHome) 175 PortableRemoteObject.narrow(objref, AccountHome.class); 176 account3 = home.create(testName + "#account3", 0); 177 178 } 179 catch (Exception e) 180 { 181 throw new EJBException (e); 182 } 183 } 184 185 private void findAccounts() 186 { 187 try 188 { 189 Object objref; 190 AccountEntityHome home; 191 Context iniCtx = new InitialContext (); 192 193 objref = iniCtx.lookup("java:comp/env/ejb/Account1"); 194 home = (AccountEntityHome) 195 PortableRemoteObject.narrow(objref, AccountEntityHome.class); 196 try 197 { 198 account1 = home.findByPrimaryKey(testName + "#account1"); 199 } 200 catch (FinderException e) 201 { 202 account1 = home.create(testName + "#account1", 0); 203 } 204 205 objref = iniCtx.lookup("java:comp/env/ejb/Account2"); 206 home = (AccountEntityHome) 207 PortableRemoteObject.narrow(objref, AccountEntityHome.class); 208 try 209 { 210 account2 = home.findByPrimaryKey(testName + "#account2"); 211 } 212 catch (FinderException e) 213 { 214 account2 = home.create(testName + "#account2", 0); 215 } 216 217 218 objref = iniCtx.lookup("java:comp/env/ejb/Account3"); 219 home = (AccountEntityHome) 220 PortableRemoteObject.narrow(objref, AccountEntityHome.class); 221 try 222 { 223 account3 = home.findByPrimaryKey(testName + "#account3"); 224 } 225 catch (FinderException e) 226 { 227 account3 = home.create(testName + "#account3", 0); 228 } 229 } 230 catch (Exception e) 231 { 232 throw new EJBException (e); 233 } 234 } 235 236 } 237 | Popular Tags |