1 22 package org.jboss.test.cmp2.optimisticlock.bug1006723.testsession; 23 24 25 import org.jboss.test.cmp2.optimisticlock.bug1006723.testentity.EntityALocal; 26 import org.jboss.test.cmp2.optimisticlock.bug1006723.testentity.EntityBLocal; 27 import org.jboss.test.cmp2.optimisticlock.bug1006723.testentity.EntityBLocalHome; 28 import org.jboss.test.cmp2.optimisticlock.bug1006723.testentity.EntityALocalHome; 29 30 import javax.ejb.SessionBean ; 31 import javax.ejb.SessionContext ; 32 import javax.ejb.CreateException ; 33 import javax.ejb.EJBException ; 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.NamingException ; 37 import java.util.Iterator ; 38 import java.util.Date ; 39 40 public class TestSessionBean implements SessionBean { 41 42 public Long setup() throws Exception { 43 try{ 44 45 EntityALocal entityA = getEntityALocalHome().create(new Long (1)); 46 entityA.addEntityB(getEntityBLocalHome().create(new Long (2))); 47 return entityA.getOID(); 48 } 49 catch (Exception e){ 50 sessionContext.setRollbackOnly(); 51 throw e; 52 } 53 } 54 55 public void test(Long entityAOID) throws Exception { 56 try{ 57 EntityALocal entityA = getEntityALocalHome().findByPrimaryKey 58 (entityAOID); 59 Iterator entityBs = entityA.listEntityBs().iterator(); 60 while (entityBs.hasNext()){ 61 ((EntityBLocal)entityBs.next()).setLastModified(new Date ()); 62 } 63 } 64 catch (Exception e){ 65 sessionContext.setRollbackOnly(); 66 throw e; 67 } 68 } 69 70 public void ejbCreate() throws CreateException {} 71 72 public void ejbRemove(){} 73 74 public void ejbActivate(){} 75 76 public void ejbPassivate(){} 77 78 public void setSessionContext(SessionContext context){ 79 this.sessionContext = context; 80 } 81 82 private Context getContext(){ 83 if (context == null){ 84 try{ 85 context = new InitialContext (); 86 } 87 catch (NamingException e){ 88 throw new EJBException (e.getMessage()); 89 } 90 } 91 return context; 92 } 93 94 private EntityALocalHome getEntityALocalHome(){ 95 if (entityALocalHome == null){ 96 try{ 97 entityALocalHome = (EntityALocalHome)getContext().lookup 98 ("java:comp/env/ejb/EntityA"); 99 } 100 catch (NamingException e){ 101 throw new EJBException (e.getMessage()); 102 } 103 } 104 return entityALocalHome; 105 } 106 107 private EntityBLocalHome getEntityBLocalHome(){ 108 if (entityBLocalHome == null){ 109 try{ 110 entityBLocalHome = (EntityBLocalHome)getContext().lookup 111 ("java:comp/env/ejb/EntityB"); 112 } 113 catch (NamingException e){ 114 throw new EJBException (e.getMessage()); 115 } 116 } 117 return entityBLocalHome; 118 } 119 120 private SessionContext sessionContext; 121 private Context context; 122 private EntityALocalHome entityALocalHome; 123 private EntityBLocalHome entityBLocalHome; 124 125 } 126 127 | Popular Tags |