01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
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: private SessionContext ctx;
35: private OrderHome orderHome;
36: private LineItemHome lineItemHome;
37:
38: public void ejbCreate() throws CreateException {
39: try {
40: InitialContext jndiContext = new InitialContext();
41:
42: orderHome = (OrderHome) jndiContext
43: .lookup("commerce/Order");
44: lineItemHome = (LineItemHome) jndiContext
45: .lookup("commerce/LineItem");
46: } catch (Exception e) {
47: throw new CreateException("Error getting OrderHome and "
48: + "LineItemHome: " + e.getMessage());
49: }
50: }
51:
52: public boolean accessCMRCollectionWithoutTx() {
53: Order o;
54: LineItem l1;
55: LineItem l2;
56:
57: // create something to work with
58: 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: // this should work
67: l1.setOrder(o);
68:
69: // this should throw an IllegalStateException
70: Collection c = o.getLineItems();
71: try {
72: c.add(l2);
73: } catch (IllegalStateException ex) {
74: return true;
75: }
76: return false;
77: }
78:
79: public void setSessionContext(SessionContext ctx) {
80: this .ctx = ctx;
81: }
82:
83: public void ejbActivate() {
84: }
85:
86: public void ejbPassivate() {
87: }
88:
89: public void ejbRemove() {
90: }
91: }
|