KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > relation > s2pkcomp > BEC2


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: BEC2.java,v 1.2 2003/02/14 07:17:35 joaninh Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.jtests.beans.relation.s2pkcomp;
27
28 import org.objectweb.util.monolog.api.Logger;
29 import org.objectweb.util.monolog.api.BasicLevel;
30 import org.objectweb.jonas.common.Log;
31
32 import javax.ejb.EntityContext JavaDoc;
33 import javax.ejb.CreateException JavaDoc;
34 import javax.ejb.DuplicateKeyException JavaDoc;
35 import javax.ejb.RemoveException JavaDoc;
36
37 /**
38  * @author Helene Joanin
39  */

40 public abstract class BEC2 implements javax.ejb.EntityBean JavaDoc {
41
42     // ------------------------------------------------------------------
43
// Get and Set accessor methods of the bean's abstract schema
44
// ------------------------------------------------------------------
45
public abstract String JavaDoc getId1();
46     public abstract void setId1(String JavaDoc id1);
47     public abstract int getId2();
48     public abstract void setId2(int id2);
49     public abstract ALocal getA();
50     public abstract void setA(ALocal al);
51
52     // ------------------------------------------------------------------
53
// EntityBean implementation
54
// ------------------------------------------------------------------
55

56     static protected Logger logger = null;
57     EntityContext JavaDoc ejbContext;
58
59     public void m1(){
60     }
61
62     public Pk getId(){
63     return (Pk) ejbContext.getPrimaryKey();
64     }
65
66     /**
67      * The Entity bean can define 0 or more ejbCreate methods.
68      *
69      * @throws CreateException Failure to create an entity EJB object.
70      * @throws DuplicateKeyException An object with the same key already exists.
71      */

72     public Pk ejbCreate(String JavaDoc id1, int id2) throws CreateException JavaDoc, DuplicateKeyException JavaDoc {
73         logger.log(BasicLevel.DEBUG, "");
74
75         // Init here the bean fields
76
setId1(id1);
77         setId2(id2);
78
79         // In CMP, should return null.
80
return null;
81     }
82
83     /**
84      * Set the associated entity context. The container invokes this method
85      * on an instance after the instance has been created.
86      * This method is called in an unspecified transaction context.
87      *
88      * @param ctx - An EntityContext interface for the instance. The instance
89      * should store the reference to the context in an instance variable.
90      * @throws EJBException Thrown by the method to indicate a failure caused by a
91      * system-level error.
92      */

93     public void setEntityContext(EntityContext JavaDoc ctx) {
94         if (logger == null)
95             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
96         logger.log(BasicLevel.DEBUG, "");
97         ejbContext = ctx;
98     }
99
100     /**
101      * Unset the associated entity context. The container calls this method
102      * before removing the instance.
103      * This is the last method that the container invokes on the instance.
104      * The Java garbage collector will eventually invoke the finalize() method
105      * on the instance.
106      * This method is called in an unspecified transaction context.
107      *
108      * @throws EJBException Thrown by the method to indicate a failure caused by a
109      * system-level error.
110      */

111     public void unsetEntityContext() {
112         logger.log(BasicLevel.DEBUG, "");
113         ejbContext = null;
114     }
115
116     public Pk retrieveA() {
117       ALocal lejbA = getA();
118       if (lejbA==null)
119       return null;
120       else
121           return lejbA.getId();
122     }
123
124     public Pk retrieveAInNewTx() {
125         return retrieveA();
126     }
127
128     /**
129      * A container invokes this method before it removes the EJB object
130      * that is currently associated with the instance. This method is
131      * invoked when a client invokes a remove operation on the enterprise Bean's
132      * home interface or the EJB object's remote interface. This method
133      * transitions the instance from the ready state to the pool of available
134      * instances.
135      *
136      * This method is called in the transaction context of the remove operation.
137      * @throws RemoveException The enterprise Bean does not allow destruction of the object.
138      * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
139      * error.
140      */

141     public void ejbRemove() throws RemoveException JavaDoc {
142         logger.log(BasicLevel.DEBUG, "");
143     }
144
145     /**
146      * A container invokes this method to instruct the instance to synchronize
147      * its state by loading it state from the underlying database.
148      * This method always executes in the proper transaction context.
149      *
150      * @throws EJBException Thrown by the method to indicate a failure caused by
151      * a system-level error.
152      */

153     public void ejbLoad() {
154         logger.log(BasicLevel.DEBUG, "");
155     }
156
157     /**
158      * A container invokes this method to instruct the instance to synchronize
159      * its state by storing it to the underlying database.
160      * This method always executes in the proper transaction context.
161      *
162      * @throws EJBException Thrown by the method to indicate a failure caused by
163      * a system-level error.
164      */

165     public void ejbStore() {
166         logger.log(BasicLevel.DEBUG, "");
167     }
168
169     /**
170      * There must be an ejbPostCreate par ejbCreate method
171      *
172      * @throws CreateException Failure to create an entity EJB object.
173      */

174     public void ejbPostCreate(String JavaDoc id1, int id2) throws CreateException JavaDoc {
175         logger.log(BasicLevel.DEBUG, "id1="+id1+", id2="+id2);
176     }
177
178     /**
179      * A container invokes this method on an instance before the instance
180      * becomes disassociated with a specific EJB object.
181      */

182     public void ejbPassivate() {
183         logger.log(BasicLevel.DEBUG, "");
184     }
185
186     /**
187      * A container invokes this method when the instance is taken out of
188      * the pool of available instances to become associated with a specific
189      * EJB object.
190      */

191     public void ejbActivate() {
192         logger.log(BasicLevel.DEBUG, "");
193     }
194
195 }
196
197
Popular Tags