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