1 22 package org.jboss.test.cmp2.commerce; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import javax.ejb.EJBException ; 27 import javax.ejb.CreateException ; 28 import javax.ejb.SessionBean ; 29 import javax.ejb.SessionContext ; 30 import javax.naming.InitialContext ; 31 import org.apache.log4j.Category; 32 33 public class TxTesterBean implements SessionBean 34 { 35 private SessionContext ctx; 36 private OrderHome orderHome; 37 private LineItemHome lineItemHome; 38 39 public void ejbCreate() throws CreateException { 40 try { 41 InitialContext jndiContext = new InitialContext (); 42 43 orderHome = (OrderHome) jndiContext.lookup("commerce/Order"); 44 lineItemHome = (LineItemHome) jndiContext.lookup("commerce/LineItem"); 45 } catch(Exception e) { 46 throw new CreateException ("Error getting OrderHome and " + 47 "LineItemHome: " + e.getMessage()); 48 } 49 } 50 51 public boolean accessCMRCollectionWithoutTx() 52 { 53 Order o; 54 LineItem l1; 55 LineItem l2; 56 57 try { 59 o = orderHome.create(); 60 l1 = lineItemHome.create(); 61 l2 = lineItemHome.create(); 62 } catch (CreateException ex) { 63 throw new EJBException (ex); 64 } 65 66 l1.setOrder(o); 68 69 70 Collection c = o.getLineItems(); 72 try { 73 c.add(l2); 74 } catch (IllegalStateException ex) { 75 return true; 76 } 77 return false; 78 } 79 80 public void setSessionContext(SessionContext ctx) 81 { 82 this.ctx = ctx; 83 } 84 85 public void ejbActivate() { } 86 87 public void ejbPassivate() { } 88 89 public void ejbRemove() { } 90 } 91 | Popular Tags |