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