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: BEC2.java 1478 2003-02-14 07:17:35Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.relation.s2pkcomp;
027:
028: import org.objectweb.util.monolog.api.Logger;
029: import org.objectweb.util.monolog.api.BasicLevel;
030: import org.objectweb.jonas.common.Log;
031:
032: import javax.ejb.EntityContext;
033: import javax.ejb.CreateException;
034: import javax.ejb.DuplicateKeyException;
035: import javax.ejb.RemoveException;
036:
037: /**
038: * @author Helene Joanin
039: */
040: public abstract class BEC2 implements javax.ejb.EntityBean {
041:
042: // ------------------------------------------------------------------
043: // Get and Set accessor methods of the bean's abstract schema
044: // ------------------------------------------------------------------
045: public abstract String getId1();
046:
047: public abstract void setId1(String id1);
048:
049: public abstract int getId2();
050:
051: public abstract void setId2(int id2);
052:
053: public abstract ALocal getA();
054:
055: public abstract void setA(ALocal al);
056:
057: // ------------------------------------------------------------------
058: // EntityBean implementation
059: // ------------------------------------------------------------------
060:
061: static protected Logger logger = null;
062: EntityContext ejbContext;
063:
064: public void m1() {
065: }
066:
067: public Pk getId() {
068: return (Pk) ejbContext.getPrimaryKey();
069: }
070:
071: /**
072: * The Entity bean can define 0 or more ejbCreate methods.
073: *
074: * @throws CreateException Failure to create an entity EJB object.
075: * @throws DuplicateKeyException An object with the same key already exists.
076: */
077: public Pk ejbCreate(String id1, int id2) throws CreateException,
078: DuplicateKeyException {
079: logger.log(BasicLevel.DEBUG, "");
080:
081: // Init here the bean fields
082: setId1(id1);
083: setId2(id2);
084:
085: // In CMP, should return null.
086: return null;
087: }
088:
089: /**
090: * Set the associated entity context. The container invokes this method
091: * on an instance after the instance has been created.
092: * This method is called in an unspecified transaction context.
093: *
094: * @param ctx - An EntityContext interface for the instance. The instance
095: * should store the reference to the context in an instance variable.
096: * @throws EJBException Thrown by the method to indicate a failure caused by a
097: * system-level error.
098: */
099: public void setEntityContext(EntityContext ctx) {
100: if (logger == null)
101: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
102: logger.log(BasicLevel.DEBUG, "");
103: ejbContext = ctx;
104: }
105:
106: /**
107: * Unset the associated entity context. The container calls this method
108: * before removing the instance.
109: * This is the last method that the container invokes on the instance.
110: * The Java garbage collector will eventually invoke the finalize() method
111: * on the instance.
112: * This method is called in an unspecified transaction context.
113: *
114: * @throws EJBException Thrown by the method to indicate a failure caused by a
115: * system-level error.
116: */
117: public void unsetEntityContext() {
118: logger.log(BasicLevel.DEBUG, "");
119: ejbContext = null;
120: }
121:
122: public Pk retrieveA() {
123: ALocal lejbA = getA();
124: if (lejbA == null)
125: return null;
126: else
127: return lejbA.getId();
128: }
129:
130: public Pk retrieveAInNewTx() {
131: return retrieveA();
132: }
133:
134: /**
135: * A container invokes this method before it removes the EJB object
136: * that is currently associated with the instance. This method is
137: * invoked when a client invokes a remove operation on the enterprise Bean's
138: * home interface or the EJB object's remote interface. This method
139: * transitions the instance from the ready state to the pool of available
140: * instances.
141: *
142: * This method is called in the transaction context of the remove operation.
143: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
144: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
145: * error.
146: */
147: public void ejbRemove() throws RemoveException {
148: logger.log(BasicLevel.DEBUG, "");
149: }
150:
151: /**
152: * A container invokes this method to instruct the instance to synchronize
153: * its state by loading it state from the underlying database.
154: * This method always executes in the proper transaction context.
155: *
156: * @throws EJBException Thrown by the method to indicate a failure caused by
157: * a system-level error.
158: */
159: public void ejbLoad() {
160: logger.log(BasicLevel.DEBUG, "");
161: }
162:
163: /**
164: * A container invokes this method to instruct the instance to synchronize
165: * its state by storing it to the underlying database.
166: * This method always executes in the proper transaction context.
167: *
168: * @throws EJBException Thrown by the method to indicate a failure caused by
169: * a system-level error.
170: */
171: public void ejbStore() {
172: logger.log(BasicLevel.DEBUG, "");
173: }
174:
175: /**
176: * There must be an ejbPostCreate par ejbCreate method
177: *
178: * @throws CreateException Failure to create an entity EJB object.
179: */
180: public void ejbPostCreate(String id1, int id2)
181: throws CreateException {
182: logger.log(BasicLevel.DEBUG, "id1=" + id1 + ", id2=" + id2);
183: }
184:
185: /**
186: * A container invokes this method on an instance before the instance
187: * becomes disassociated with a specific EJB object.
188: */
189: public void ejbPassivate() {
190: logger.log(BasicLevel.DEBUG, "");
191: }
192:
193: /**
194: * A container invokes this method when the instance is taken out of
195: * the pool of available instances to become associated with a specific
196: * EJB object.
197: */
198: public void ejbActivate() {
199: logger.log(BasicLevel.DEBUG, "");
200: }
201:
202: }
|