001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.factory;
023:
024: import javax.ejb.Remote;
025: import javax.ejb.Remove;
026: import javax.ejb.Stateful;
027: import javax.ejb.TransactionAttribute;
028: import javax.ejb.TransactionAttributeType;
029: import javax.persistence.EntityManager;
030: import javax.persistence.PersistenceContext;
031: import javax.persistence.PersistenceContextType;
032:
033: /**
034: * Comment
035: *
036: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
037: * @version $Revision: 57207 $
038: */
039: @Stateful
040: @Remote(Stateful1.class)
041: public class Stateful1Bean implements Stateful1, java.io.Serializable {
042: @PersistenceContext(unitName="manager1",type=PersistenceContextType.EXTENDED)
043: EntityManager manager1;
044: @PersistenceContext(unitName="../session2.jar#manager2",type=PersistenceContextType.EXTENDED)
045: EntityManager manager2;
046:
047: Entity1 one;
048: Entity2 two;
049:
050: public int create1() {
051: one = new Entity1();
052: one.setString("oneManager");
053: manager1.persist(one);
054: return one.getId();
055: }
056:
057: public int create2() {
058: two = new Entity2();
059: two.setString("twoManager");
060: manager2.persist(two);
061: return two.getId();
062: }
063:
064: public void update1() {
065: one.setString("changed");
066: }
067:
068: public void update2() {
069: two.setString("changed");
070: }
071:
072: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
073: public void never() {
074: one.setString("never");
075: two.setString("never");
076: }
077:
078: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
079: public void never2(Entity1 uno, Entity2 dos) {
080: if (manager1.merge(uno) != one)
081: throw new RuntimeException("NOT EQUAL!!");
082: if (!uno.getString().equals("never2"))
083: throw new RuntimeException("NOT_EQUAL");
084: if (manager2.merge(dos) != two)
085: throw new RuntimeException("NOT EQUAL!");
086: if (!dos.getString().equals("never2"))
087: throw new RuntimeException("NOT_EQUAL");
088: }
089:
090: @Remove
091: public void checkout() {
092: /*
093: Entity1 uno = manager1.find(Entity1.class, one.getId());
094: if (uno != one) throw new RuntimeException("NOT EQUAL");
095: if (!uno.equals("never2")) throw new RuntimeException("NOT EQUAL");
096: manager1.flush();
097: manager2.flush();
098: */
099: }
100:
101: }
|