KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cmp2 > jbas979 > ABean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * 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.jbas979;
23
24
25 import javax.ejb.EntityBean JavaDoc;
26 import javax.ejb.EntityContext JavaDoc;
27 import javax.ejb.RemoveException JavaDoc;
28 import javax.ejb.CreateException JavaDoc;
29 import javax.ejb.EJBException JavaDoc;
30 import javax.transaction.TransactionManager JavaDoc;
31 import javax.transaction.SystemException JavaDoc;
32 import org.jboss.tm.TransactionManagerLocator;
33
34
35 /**
36  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
37  * @version <tt>$Revision: 44013 $</tt>
38  */

39 public abstract class ABean implements EntityBean JavaDoc
40 {
41    private Object JavaDoc longTx;
42
43    // CMP accessors --------------------------------------------
44
/**
45     * @ejb.pk-field
46     * @ejb.persistent-field
47     * @ejb.interface-method
48     */

49    public abstract Integer JavaDoc getId();
50
51    public abstract void setId(Integer JavaDoc id);
52
53    /**
54     * @ejb.persistent-field
55     * @ejb.interface-method
56     */

57    public abstract String JavaDoc getName();
58
59   /**
60    * @ejb.interface-method
61    */

62    public abstract void setName(String JavaDoc name);
63
64    public void longTx() throws Exception JavaDoc
65    {
66       TransactionManager JavaDoc tm = TransactionManagerLocator.getInstance().locate();
67       longTx = tm.getTransaction();
68       if(longTx == null)
69       {
70          throw new EJBException JavaDoc("longTx invoked w/o a transaction!");
71       }
72    }
73
74    /**
75     * @throws javax.ejb.CreateException
76     * @ejb.create-method
77     */

78    public Integer JavaDoc ejbCreate(Integer JavaDoc id, String JavaDoc name)
79       throws CreateException JavaDoc
80    {
81       setId(id);
82       setName(name);
83       return null;
84    }
85
86    public void ejbPostCreate(Integer JavaDoc id, String JavaDoc name)
87    {
88    }
89
90    /**
91     * @param ctx The new entityContext value
92     */

93    public void setEntityContext(EntityContext JavaDoc ctx)
94    {
95    }
96
97    /**
98     * Unset the associated entity context.
99     */

100    public void unsetEntityContext()
101    {
102    }
103
104    public void ejbActivate()
105    {
106    }
107
108    public void ejbLoad()
109    {
110    }
111
112    public void ejbPassivate()
113    {
114       TransactionManager JavaDoc tm = TransactionManagerLocator.getInstance().locate();
115       try
116       {
117          // is it safe to check like this? could there be a race condition?
118
if(longTx != null && longTx.equals(tm.getTransaction()))
119          {
120             JBAS979UnitTestCase.PASSIVATED_IN_AFTER_COMPLETION = true;
121          }
122          else
123          {
124             JBAS979UnitTestCase.PASSIVATED_IN_AFTER_COMPLETION = false;
125          }
126          JBAS979UnitTestCase.ERROR_IN_EJB_PASSIVATE = null;
127       }
128       catch(SystemException JavaDoc e)
129       {
130          JBAS979UnitTestCase.ERROR_IN_EJB_PASSIVATE = e;
131       }
132    }
133
134    public void ejbRemove() throws RemoveException JavaDoc
135    {
136    }
137
138    public void ejbStore()
139    {
140    }
141 }
142
Popular Tags