001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: AEC2.java 7420 2005-09-26 14:16:26Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.relation.mou;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.DuplicateKeyException;
030: import javax.ejb.EJBException;
031: import javax.ejb.EntityContext;
032: import javax.ejb.FinderException;
033: import javax.ejb.RemoveException;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037: import javax.rmi.PortableRemoteObject;
038:
039: import org.objectweb.jonas.common.Log;
040: import org.objectweb.util.monolog.api.BasicLevel;
041: import org.objectweb.util.monolog.api.Logger;
042:
043: /**
044: * @author S.Chassande-Barrioz
045: */
046: public abstract class AEC2 implements javax.ejb.EntityBean {
047:
048: private BHomeLocal bhl = null;
049:
050: public void m1() {
051: }
052:
053: public void assignB(String c) throws FinderException {
054: logger.log(BasicLevel.DEBUG, "");
055: if (c != null) {
056: BLocal bl = null;
057: bl = bhl.findByPrimaryKey(c);
058: setB(bl);
059: } else
060: setB(null);
061: }
062:
063: public void assignBInNewTx(String c) throws FinderException {
064: logger.log(BasicLevel.DEBUG, "");
065: assignB(c);
066: }
067:
068: public String retrieveB() {
069: BLocal lejbB = getB();
070: if (lejbB == null) {
071: logger.log(BasicLevel.DEBUG, "return null");
072: return null;
073: } else {
074: logger.log(BasicLevel.DEBUG, "return " + lejbB.getId());
075: return lejbB.getId();
076: }
077: }
078:
079: public String retrieveBInNewTx() {
080: logger.log(BasicLevel.DEBUG, "");
081: return retrieveB();
082: }
083:
084: // ------------------------------------------------------------------
085: // Get and Set accessor methods of the bean's abstract schema
086: // ------------------------------------------------------------------
087: public abstract String getId();
088:
089: public abstract void setId(String id);
090:
091: public abstract BLocal getB();
092:
093: public abstract void setB(BLocal bl);
094:
095: // ------------------------------------------------------------------
096: // EntityBean implementation
097: // ------------------------------------------------------------------
098:
099: static protected Logger logger = null;
100: EntityContext ejbContext;
101:
102: /**
103: * The Entity bean can define 0 or more ejbCreate methods.
104: *
105: * @throws CreateException Failure to create an entity EJB object.
106: * @throws DuplicateKeyException An object with the same key already exists.
107: */
108: public String ejbCreate(String id, String idb)
109: throws CreateException, DuplicateKeyException {
110: logger.log(BasicLevel.DEBUG, "");
111:
112: // Init here the bean fields
113: setId(id);
114:
115: // In CMP, should return null.
116: return null;
117: }
118:
119: /**
120: * There must be an ejbPostCreate par ejbCreate method
121: *
122: * @throws CreateException Failure to create an entity EJB object.
123: */
124: public void ejbPostCreate(String id, String idb)
125: throws CreateException {
126: logger.log(BasicLevel.DEBUG, "id=" + id);
127: try {
128: assignB(idb);
129: } catch (FinderException e) {
130: throw new CreateException("Bad arg: " + idb);
131: }
132: }
133:
134: /**
135: * The Entity bean can define 0 or more ejbCreate methods.
136: *
137: * @throws CreateException Failure to create an entity EJB object.
138: * @throws DuplicateKeyException An object with the same key already exists.
139: */
140: public String ejbCreate(String id) throws CreateException,
141: DuplicateKeyException {
142: logger.log(BasicLevel.DEBUG, "");
143:
144: // Init here the bean fields
145: setId(id);
146:
147: // In CMP, should return null.
148: return null;
149: }
150:
151: /**
152: * There must be an ejbPostCreate par ejbCreate method
153: *
154: * @throws CreateException Failure to create an entity EJB object.
155: */
156: public void ejbPostCreate(String id) throws CreateException {
157: logger.log(BasicLevel.DEBUG, "id=" + id);
158: }
159:
160: /**
161: * The Entity bean can define 0 or more ejbCreate methods.
162: *
163: * @throws CreateException Failure to create an entity EJB object.
164: * @throws DuplicateKeyException An object with the same key already exists.
165: */
166: public String ejbCreate(String id, BLocal b)
167: throws CreateException, DuplicateKeyException {
168: logger.log(BasicLevel.DEBUG, "");
169:
170: // Init here the bean fields
171: setId(id);
172:
173: // In CMP, should return null.
174: return null;
175: }
176:
177: /**
178: * There must be an ejbPostCreate par ejbCreate method
179: *
180: * @throws CreateException Failure to create an entity EJB object.
181: */
182: public void ejbPostCreate(String id, BLocal b)
183: throws CreateException {
184: logger.log(BasicLevel.DEBUG, "id=" + id);
185: setB(b);
186: }
187:
188: /**
189: * Set the associated entity context. The container invokes this method
190: * on an instance after the instance has been created.
191: * This method is called in an unspecified transaction context.
192: *
193: * @param ctx - An EntityContext interface for the instance. The instance
194: * should store the reference to the context in an instance variable.
195: * @throws EJBException Thrown by the method to indicate a failure caused by a
196: * system-level error.
197: */
198: public void setEntityContext(EntityContext ctx) {
199: if (logger == null)
200: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
201: logger.log(BasicLevel.DEBUG, "");
202: ejbContext = ctx;
203: try {
204: Context ictx = new InitialContext();
205: bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b");
206: } catch (NamingException e) {
207: throw new EJBException("Impossible to fetch the ", e);
208: }
209: }
210:
211: /**
212: * Unset the associated entity context. The container calls this method
213: * before removing the instance.
214: * This is the last method that the container invokes on the instance.
215: * The Java garbage collector will eventually invoke the finalize() method
216: * on the instance.
217: * This method is called in an unspecified transaction context.
218: *
219: * @throws EJBException Thrown by the method to indicate a failure caused by a
220: * system-level error.
221: */
222: public void unsetEntityContext() {
223: logger.log(BasicLevel.DEBUG, "");
224: ejbContext = null;
225: }
226:
227: /**
228: * A container invokes this method before it removes the EJB object
229: * that is currently associated with the instance. This method is
230: * invoked when a client invokes a remove operation on the enterprise Bean's
231: * home interface or the EJB object's remote interface. This method
232: * transitions the instance from the ready state to the pool of available
233: * instances.
234: *
235: * This method is called in the transaction context of the remove operation.
236: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
237: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
238: * error.
239: */
240: public void ejbRemove() throws RemoveException {
241: logger.log(BasicLevel.DEBUG, "");
242: }
243:
244: /**
245: * A container invokes this method to instruct the instance to synchronize
246: * its state by loading it state from the underlying database.
247: * This method always executes in the proper transaction context.
248: *
249: * @throws EJBException Thrown by the method to indicate a failure caused by
250: * a system-level error.
251: */
252: public void ejbLoad() {
253: logger.log(BasicLevel.DEBUG, "");
254: }
255:
256: /**
257: * A container invokes this method to instruct the instance to synchronize
258: * its state by storing it to the underlying database.
259: * This method always executes in the proper transaction context.
260: *
261: * @throws EJBException Thrown by the method to indicate a failure caused by
262: * a system-level error.
263: */
264: public void ejbStore() {
265: logger.log(BasicLevel.DEBUG, "");
266: }
267:
268: /**
269: * A container invokes this method on an instance before the instance
270: * becomes disassociated with a specific EJB object.
271: */
272: public void ejbPassivate() {
273: logger.log(BasicLevel.DEBUG, "");
274: }
275:
276: /**
277: * A container invokes this method when the instance is taken out of
278: * the pool of available instances to become associated with a specific
279: * EJB object.
280: */
281: public void ejbActivate() {
282: logger.log(BasicLevel.DEBUG, "");
283: }
284:
285: }
|