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 5995 2004-12-17 15:08:36Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.relation.oob;
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, "param=" + c);
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: assignB(c);
065: }
066:
067: public String retrieveB() {
068: BLocal lejbB = getB();
069: if (lejbB == null) {
070: logger.log(BasicLevel.DEBUG, "return null");
071: return null;
072: } else {
073: logger.log(BasicLevel.DEBUG, "return " + lejbB.getId());
074: return lejbB.getId();
075: }
076: }
077:
078: public String retrieveBInNewTx() {
079: return retrieveB();
080: }
081:
082: // ------------------------------------------------------------------
083: // Get and Set accessor methods of the bean's abstract schema
084: // ------------------------------------------------------------------
085: public abstract String getId();
086:
087: public abstract void setId(String id);
088:
089: public abstract BLocal getB();
090:
091: public abstract void setB(BLocal bl);
092:
093: public abstract BLocal getBBis();
094:
095: public abstract void setBBis(BLocal bl);
096:
097: // ------------------------------------------------------------------
098: // EntityBean implementation
099: // ------------------------------------------------------------------
100:
101: static protected Logger logger = null;
102: EntityContext ejbContext;
103:
104: /**
105: * The Entity bean can define 0 or more ejbCreate methods.
106: *
107: * @throws CreateException Failure to create an entity EJB object.
108: * @throws DuplicateKeyException An object with the same key already exists.
109: */
110: public String ejbCreate(String id) throws CreateException,
111: DuplicateKeyException {
112: logger.log(BasicLevel.DEBUG, "");
113:
114: // Init here the bean fields
115: setId(id);
116:
117: // In CMP, should return null.
118: return null;
119: }
120:
121: /**
122: * Set the associated entity context. The container invokes this method
123: * on an instance after the instance has been created.
124: * This method is called in an unspecified transaction context.
125: *
126: * @param ctx - An EntityContext interface for the instance. The instance
127: * should store the reference to the context in an instance variable.
128: * @throws EJBException Thrown by the method to indicate a failure caused by a
129: * system-level error.
130: */
131: public void setEntityContext(EntityContext ctx) {
132: if (logger == null)
133: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
134: logger.log(BasicLevel.DEBUG, "");
135: ejbContext = ctx;
136: try {
137: Context ictx = new InitialContext();
138: bhl = (BHomeLocal) ictx.lookup("java:comp/env/ejb/b");
139: } catch (NamingException e) {
140: throw new EJBException("Impossible to fetch the ", e);
141: }
142: }
143:
144: /**
145: * Unset the associated entity context. The container calls this method
146: * before removing the instance.
147: * This is the last method that the container invokes on the instance.
148: * The Java garbage collector will eventually invoke the finalize() method
149: * on the instance.
150: * This method is called in an unspecified transaction context.
151: *
152: * @throws EJBException Thrown by the method to indicate a failure caused by a
153: * system-level error.
154: */
155: public void unsetEntityContext() {
156: logger.log(BasicLevel.DEBUG, "");
157: ejbContext = null;
158: }
159:
160: /**
161: * A container invokes this method before it removes the EJB object
162: * that is currently associated with the instance. This method is
163: * invoked when a client invokes a remove operation on the enterprise Bean's
164: * home interface or the EJB object's remote interface. This method
165: * transitions the instance from the ready state to the pool of available
166: * instances.
167: *
168: * This method is called in the transaction context of the remove operation.
169: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
170: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
171: * error.
172: */
173: public void ejbRemove() throws RemoveException {
174: logger.log(BasicLevel.DEBUG, "");
175: }
176:
177: /**
178: * A container invokes this method to instruct the instance to synchronize
179: * its state by loading it state from the underlying database.
180: * This method always executes in the proper transaction context.
181: *
182: * @throws EJBException Thrown by the method to indicate a failure caused by
183: * a system-level error.
184: */
185: public void ejbLoad() {
186: logger.log(BasicLevel.DEBUG, "");
187: }
188:
189: /**
190: * A container invokes this method to instruct the instance to synchronize
191: * its state by storing it to the underlying database.
192: * This method always executes in the proper transaction context.
193: *
194: * @throws EJBException Thrown by the method to indicate a failure caused by
195: * a system-level error.
196: */
197: public void ejbStore() {
198: logger.log(BasicLevel.DEBUG, "");
199: }
200:
201: /**
202: * There must be an ejbPostCreate par ejbCreate method
203: *
204: * @throws CreateException Failure to create an entity EJB object.
205: */
206: public void ejbPostCreate(String id) throws CreateException {
207: logger.log(BasicLevel.DEBUG, "id=" + id);
208: }
209:
210: /**
211: * A container invokes this method on an instance before the instance
212: * becomes disassociated with a specific EJB object.
213: */
214: public void ejbPassivate() {
215: logger.log(BasicLevel.DEBUG, "");
216: }
217:
218: /**
219: * A container invokes this method when the instance is taken out of
220: * the pool of available instances to become associated with a specific
221: * EJB object.
222: */
223: public void ejbActivate() {
224: logger.log(BasicLevel.DEBUG, "");
225: }
226:
227: }
|