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