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