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:
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.fbasic;
031:
032: import java.rmi.RemoteException;
033: import java.sql.Connection;
034: import java.sql.PreparedStatement;
035: import java.sql.ResultSet;
036: import java.sql.SQLException;
037: import java.sql.Statement;
038: import java.util.Collection;
039: import java.util.Vector;
040: import javax.ejb.CreateException;
041: import javax.ejb.DuplicateKeyException;
042: import javax.ejb.EJBObject;
043: import javax.ejb.EJBException;
044: import javax.ejb.EntityBean;
045: import javax.ejb.EntityContext;
046: import javax.ejb.FinderException;
047: import javax.ejb.ObjectNotFoundException;
048: import javax.ejb.RemoveException;
049: import javax.naming.Context;
050: import javax.naming.InitialContext;
051: import javax.naming.NamingException;
052: import javax.sql.DataSource;
053: import javax.transaction.NotSupportedException;
054: import javax.transaction.Status;
055: import javax.transaction.SystemException;
056: import javax.transaction.UserTransaction;
057:
058: /**
059: *
060: */
061: public abstract class PersonEC2 implements EntityBean {
062:
063: EntityContext ejbContext;
064:
065: // ------------------------------------------------------------------
066: // Get and Set accessor methods of the bean's abstract schema
067: // ------------------------------------------------------------------
068: public abstract Integer getNumber();
069:
070: public abstract void setNumber(Integer num);
071:
072: public abstract String getName();
073:
074: public abstract void setName(String name);
075:
076: // ------------------------------------------------------------------
077: // EntityBean implementation
078: // ------------------------------------------------------------------
079:
080: /**
081: * Set the associated entity context. The container invokes this method
082: * on an instance after the instance has been created.
083: * This method is called in an unspecified transaction context.
084: *
085: * @param ctx - An EntityContext interface for the instance. The instance
086: * should store the reference to the context in an instance variable.
087: * @throws EJBException Thrown by the method to indicate a failure caused by a
088: * system-level error.
089: */
090: public void setEntityContext(EntityContext ctx) {
091:
092: ejbContext = ctx;
093: }
094:
095: /**
096: * Unset the associated entity context. The container calls this method
097: * before removing the instance.
098: * This is the last method that the container invokes on the instance.
099: * The Java garbage collector will eventually invoke the finalize() method
100: * on the instance.
101: * This method is called in an unspecified transaction context.
102: *
103: * @throws EJBException Thrown by the method to indicate a failure caused by a
104: * system-level error.
105: */
106: public void unsetEntityContext() {
107:
108: ejbContext = null;
109: }
110:
111: /**
112: * A container invokes this method before it removes the EJB object
113: * that is currently associated with the instance. This method is
114: * invoked when a client invokes a remove operation on the enterprise Bean's
115: * home interface or the EJB object's remote interface. This method
116: * transitions the instance from the ready state to the pool of available
117: * instances.
118: *
119: * This method is called in the transaction context of the remove operation.
120: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
121: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
122: * error.
123: */
124: public void ejbRemove() throws RemoveException {
125:
126: }
127:
128: /**
129: * A container invokes this method to instruct the instance to synchronize
130: * its state by loading it state from 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 ejbLoad() {
137:
138: }
139:
140: /**
141: * A container invokes this method to instruct the instance to synchronize
142: * its state by storing it to the underlying database.
143: * This method always executes in the proper transaction context.
144: *
145: * @throws EJBException Thrown by the method to indicate a failure caused by
146: * a system-level error.
147: */
148: public void ejbStore() {
149:
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.Object ejbCreate(int i, String s)
159: throws CreateException, DuplicateKeyException {
160:
161: // Init here the bean fields
162: setNumber(new Integer(i));
163: setName(new String(s));
164:
165: // In CMP, should return null.
166: return null;
167: }
168:
169: /**
170: * There must be an ejbPostCreate par ejbCreate method
171: *
172: * @throws CreateException Failure to create an entity EJB object.
173: */
174: public void ejbPostCreate(int i, String s) throws CreateException {
175:
176: }
177:
178: /**
179: * A container invokes this method on an instance before the instance
180: * becomes disassociated with a specific EJB object.
181: */
182: public void ejbPassivate() {
183:
184: }
185:
186: /**
187: * A container invokes this method when the instance is taken out of
188: * the pool of available instances to become associated with a specific
189: * EJB object.
190: */
191: public void ejbActivate() {
192:
193: }
194:
195: // ------------------------------------------------------------------
196: // Person implementation
197: // ------------------------------------------------------------------
198:
199: /**
200: * getNumberPrimitive
201: */
202: public int getNumberPrimitive() {
203:
204: return getNumber().intValue();
205: }
206:
207: }
|