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.test.cmp2.jbas979;
023:
024: import javax.ejb.EntityBean;
025: import javax.ejb.EntityContext;
026: import javax.ejb.RemoveException;
027: import javax.ejb.CreateException;
028: import javax.ejb.EJBException;
029: import javax.transaction.TransactionManager;
030: import javax.transaction.SystemException;
031: import org.jboss.tm.TransactionManagerLocator;
032:
033: /**
034: * @author <a href="mailto:alex@jboss.org">Alexey Loubyansky</a>
035: * @version <tt>$Revision: 57211 $</tt>
036: */
037: public abstract class ABean implements EntityBean {
038: private Object longTx;
039:
040: // CMP accessors --------------------------------------------
041: /**
042: * @ejb.pk-field
043: * @ejb.persistent-field
044: * @ejb.interface-method
045: */
046: public abstract Integer getId();
047:
048: public abstract void setId(Integer id);
049:
050: /**
051: * @ejb.persistent-field
052: * @ejb.interface-method
053: */
054: public abstract String getName();
055:
056: /**
057: * @ejb.interface-method
058: */
059: public abstract void setName(String name);
060:
061: public void longTx() throws Exception {
062: TransactionManager tm = TransactionManagerLocator.getInstance()
063: .locate();
064: longTx = tm.getTransaction();
065: if (longTx == null) {
066: throw new EJBException("longTx invoked w/o a transaction!");
067: }
068: }
069:
070: /**
071: * @throws javax.ejb.CreateException
072: * @ejb.create-method
073: */
074: public Integer ejbCreate(Integer id, String name)
075: throws CreateException {
076: setId(id);
077: setName(name);
078: return null;
079: }
080:
081: public void ejbPostCreate(Integer id, String name) {
082: }
083:
084: /**
085: * @param ctx The new entityContext value
086: */
087: public void setEntityContext(EntityContext ctx) {
088: }
089:
090: /**
091: * Unset the associated entity context.
092: */
093: public void unsetEntityContext() {
094: }
095:
096: public void ejbActivate() {
097: }
098:
099: public void ejbLoad() {
100: }
101:
102: public void ejbPassivate() {
103: TransactionManager tm = TransactionManagerLocator.getInstance()
104: .locate();
105: try {
106: // is it safe to check like this? could there be a race condition?
107: if (longTx != null && longTx.equals(tm.getTransaction())) {
108: JBAS979UnitTestCase.PASSIVATED_IN_AFTER_COMPLETION = true;
109: } else {
110: JBAS979UnitTestCase.PASSIVATED_IN_AFTER_COMPLETION = false;
111: }
112: JBAS979UnitTestCase.ERROR_IN_EJB_PASSIVATE = null;
113: } catch (SystemException e) {
114: JBAS979UnitTestCase.ERROR_IN_EJB_PASSIVATE = e;
115: }
116: }
117:
118: public void ejbRemove() throws RemoveException {
119: }
120:
121: public void ejbStore() {
122: }
123: }
|