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.standalone.flushmodenever;
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: import javax.transaction.TransactionManager;
033: import javax.transaction.Transaction;
034: import javax.transaction.SystemException;
035: import org.jboss.annotation.JndiInject;
036: import org.jboss.ejb3.entity.ExtendedEntityManager;
037:
038: /**
039: * Comment
040: *
041: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
042: * @version $Revision: 60233 $
043: */
044: @Stateful
045: @Remote(Stateful1.class)
046: public class Stateful1Bean implements Stateful1, java.io.Serializable {
047: @PersistenceContext(unitName="manager1",type=PersistenceContextType.EXTENDED)
048: EntityManager manager1;
049: @PersistenceContext(unitName="../flushmodenever-session2.jar#manager2",type=PersistenceContextType.EXTENDED)
050: EntityManager manager2;
051:
052: Entity1 one;
053: Entity2 two;
054:
055: @JndiInject(jndiName="java:/TransactionManager")
056: TransactionManager tm;
057:
058: public int create1() {
059: one = new Entity1();
060: one.setString("oneManager");
061: if (!(manager1 instanceof ExtendedEntityManager))
062: throw new RuntimeException("assert failed");
063: manager1.persist(one);
064: return one.getId();
065: }
066:
067: public int create2() {
068: two = new Entity2();
069: two.setString("twoManager");
070: manager2.persist(two);
071: return two.getId();
072: }
073:
074: public void update1() {
075: if (!manager1.contains(one))
076: throw new RuntimeException("assert failed");
077: one.setString("changed");
078: }
079:
080: public void update2() {
081: if (!manager2.contains(two))
082: throw new RuntimeException("assert failed");
083: two.setString("changed");
084: }
085:
086: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
087: public void never() {
088: one.setString("never");
089: two.setString("never");
090: }
091:
092: @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
093: public void never2(Entity1 uno, Entity2 dos) {
094: Transaction tx = null;
095: try {
096: tx = tm.getTransaction();
097: } catch (SystemException e) {
098: throw new RuntimeException(e);
099: }
100: if (tx != null)
101: throw new RuntimeException("TRANSACTION IS NOT NULL!");
102: if (manager1.merge(uno) != one)
103: throw new RuntimeException("NOT EQUAL!!");
104: if (!uno.getString().equals("never2"))
105: throw new RuntimeException("NOT_EQUAL");
106: if (manager2.merge(dos) != two)
107: throw new RuntimeException("NOT EQUAL!");
108: if (!dos.getString().equals("never2"))
109: throw new RuntimeException("NOT_EQUAL");
110: }
111:
112: @Remove
113: public void checkout() {
114: /*
115: Entity1 uno = manager1.find(Entity1.class, one.getId());
116: if (uno != one) throw new RuntimeException("NOT EQUAL");
117: if (!uno.equals("never2")) throw new RuntimeException("NOT EQUAL");
118: manager1.flush();
119: manager2.flush();
120: */
121: }
122:
123: }
|