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