1 22 package org.jboss.test.recover.bean; 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.recover.interfaces.Account; 34 import org.jboss.test.recover.interfaces.AccountHome; 35 import org.jboss.test.util.ejb.SessionSupport; 36 37 43 public class FrontEndBean 44 extends SessionSupport 45 { 46 private static transient Logger log = 47 Logger.getLogger(FrontEndBean.class); 48 49 private String testName; 50 private Account account1JBRem, account2JBRem, account1IIOP, account2IIOP; 51 52 public void ejbCreate(String name) 53 { 54 ejbCreate(name, false); 55 } 56 57 public void ejbCreate(String name, boolean keepAccountBalances) 58 { 59 this.testName = name; 60 log = Logger.getLogger(FrontEndBean.class.getName() + "#" + testName); 61 log.debug("ejbCreate(" + name + "), ctx=" + sessionCtx); 62 findAccounts(keepAccountBalances); 63 } 64 65 public void setBalancesOverJBRem(int value1, int value2) 66 { 67 try 68 { 69 account1JBRem.setBalance(value1); 70 account2JBRem.setBalance(value2); 71 } 72 catch (RemoteException e) 73 { 74 throw new EJBException (e); 75 } 76 } 77 78 public void setBalancesOverIIOP(int value1, int value2) 79 { 80 try 81 { 82 account1IIOP.setBalance(value1); 83 account2IIOP.setBalance(value2); 84 } 85 catch (RemoteException e) 86 { 87 throw new EJBException (e); 88 } 89 } 90 91 public void setBalancesOverJBRemAndIIOP(int value1, int value2) 92 { 93 try 94 { 95 account1JBRem.setBalance(value1); 96 account2IIOP.setBalance(value2); 97 } 98 catch (RemoteException e) 99 { 100 throw new EJBException (e); 101 } 102 } 103 104 public void setBalancesOverIIOPAndJBRem(int value1, int value2) 105 { 106 try 107 { 108 account1IIOP.setBalance(value1); 109 account2JBRem.setBalance(value2); 110 } 111 catch (RemoteException e) 112 { 113 throw new EJBException (e); 114 } 115 } 116 117 public int[] getBalancesOverJBRem() 118 { 119 try 120 { 121 int[] balances = new int[2]; 122 balances[0] = account1JBRem.getBalance(); 123 balances[1] = account2JBRem.getBalance(); 124 return balances; 125 } 126 catch (RemoteException e) 127 { 128 throw new EJBException (e); 129 } 130 } 131 132 public int[] getBalancesOverIIOP() 133 { 134 try 135 { 136 int[] balances = new int[2]; 137 balances[0] = account1IIOP.getBalance(); 138 balances[1] = account2IIOP.getBalance(); 139 return balances; 140 } 141 catch (RemoteException e) 142 { 143 throw new EJBException (e); 144 } 145 } 146 147 public int[] getBalancesOverJBRemAndIIOP() 148 { 149 try 150 { 151 int[] balances = new int[2]; 152 balances[0] = account1JBRem.getBalance(); 153 balances[1] = account2IIOP.getBalance(); 154 return balances; 155 } 156 catch (RemoteException e) 157 { 158 throw new EJBException (e); 159 } 160 } 161 162 public int[] getBalancesOverIIOPAndJBRem() 163 { 164 try 165 { 166 int[] balances = new int[2]; 167 balances[0] = account1IIOP.getBalance(); 168 balances[1] = account2JBRem.getBalance(); 169 return balances; 170 } 171 catch (RemoteException e) 172 { 173 throw new EJBException (e); 174 } 175 } 176 177 public void addToBalancesOverJBRem(int value) 178 { 179 try 180 { 181 account1JBRem.addToBalance(value); 182 account2JBRem.addToBalance(value); 183 } 184 catch (RemoteException e) 185 { 186 throw new EJBException (e); 187 } 188 } 189 190 public void addToBalancesOverIIOP(int value) 191 { 192 try 193 { 194 account1IIOP.addToBalance(value); 195 account2IIOP.addToBalance(value); 196 } 197 catch (RemoteException e) 198 { 199 throw new EJBException (e); 200 } 201 } 202 203 public void addToBalancesOverJBRemAndIIOP(int value) 204 { 205 try 206 { 207 account1JBRem.addToBalance(value); 208 account2IIOP.addToBalance(value); 209 } 210 catch (RemoteException e) 211 { 212 throw new EJBException (e); 213 } 214 } 215 216 public void addToBalancesOverIIOPAndJBRem(int value) 217 { 218 try 219 { 220 account1IIOP.addToBalance(value); 221 account2JBRem.addToBalance(value); 222 } 223 catch (RemoteException e) 224 { 225 throw new EJBException (e); 226 } 227 } 228 229 public void setRollbackOnly() 230 { 231 sessionCtx.setRollbackOnly(); 232 } 233 234 public void tellFirstAccountToSetRollbackOnlyOverJBRem() 235 { 236 try 237 { 238 account1JBRem.setRollbackOnly(); 239 } 240 catch (RemoteException e) 241 { 242 throw new EJBException (e); 243 } 244 } 245 246 public void tellFirstAccountToSetRollbackOnlyOverIIOP() 247 { 248 try 249 { 250 account1IIOP.setRollbackOnly(); 251 } 252 catch (RemoteException e) 253 { 254 throw new EJBException (e); 255 } 256 } 257 258 public void tellSecondAccountToSetRollbackOnlyOverJBRem() 259 { 260 try 261 { 262 account2JBRem.setRollbackOnly(); 263 } 264 catch (RemoteException e) 265 { 266 throw new EJBException (e); 267 } 268 } 269 270 public void tellSecondAccountToSetRollbackOnlyOverIIOP() 271 { 272 try 273 { 274 account2IIOP.setRollbackOnly(); 275 } 276 catch (RemoteException e) 277 { 278 throw new EJBException (e); 279 } 280 } 281 282 private void findAccounts(boolean keepAccountBalances) 283 { 284 try 285 { 286 Object objref; 287 AccountHome home; 288 Context iniCtx = new InitialContext (); 289 290 objref = iniCtx.lookup("java:comp/env/ejb/Account1JBRem"); 291 home = (AccountHome) 292 PortableRemoteObject.narrow(objref, AccountHome.class); 293 try 294 { 295 account1JBRem = home.findByPrimaryKey(testName + "#account1"); 296 if (!keepAccountBalances) 297 account1JBRem.setBalance(0); 298 } 299 catch (FinderException e) 300 { 301 account1JBRem = home.create(testName + "#account1", 0); 302 } 303 304 objref = iniCtx.lookup("java:comp/env/ejb/Account2JBRem"); 305 home = (AccountHome) 306 PortableRemoteObject.narrow(objref, AccountHome.class); 307 try 308 { 309 account2JBRem = home.findByPrimaryKey(testName + "#account2"); 310 if (!keepAccountBalances) 311 account2JBRem.setBalance(0); 312 } 313 catch (FinderException e) 314 { 315 account2JBRem = home.create(testName + "#account2", 0); 316 } 317 318 objref = iniCtx.lookup("java:comp/env/ejb/Account1IIOP"); 319 home = (AccountHome) 320 PortableRemoteObject.narrow(objref, AccountHome.class); 321 try 322 { 323 account1IIOP = home.findByPrimaryKey(testName + "#account1"); 324 } 328 catch (FinderException e) 329 { 330 account1IIOP = home.create(testName + "#account1", 0); 332 } 333 334 objref = iniCtx.lookup("java:comp/env/ejb/Account2IIOP"); 335 home = (AccountHome) 336 PortableRemoteObject.narrow(objref, AccountHome.class); 337 try 338 { 339 account2IIOP = home.findByPrimaryKey(testName + "#account2"); 340 } 344 catch (FinderException e) 345 { 346 account2IIOP = home.create(testName + "#account2", 0); 348 } 349 } 350 catch (Exception e) 351 { 352 System.out.println("----------------------------------------"); 353 e.printStackTrace(); 354 System.out.println("----------------------------------------"); 355 throw new EJBException (e); 356 } 357 } 358 359 } 360 | Popular Tags |