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: P3EC2.java 5995 2004-12-17 15:08:36Z joaninh $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.relation.dass;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.DuplicateKeyException;
030: import javax.ejb.EJBException;
031: import javax.ejb.EntityContext;
032: import javax.ejb.FinderException;
033: import javax.ejb.RemoveException;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import javax.naming.NamingException;
037: import javax.rmi.PortableRemoteObject;
038:
039: import org.objectweb.jonas.common.Log;
040: import org.objectweb.util.monolog.api.BasicLevel;
041: import org.objectweb.util.monolog.api.Logger;
042:
043: /**
044: * @author Ph Durieux
045: */
046: public abstract class P3EC2 implements javax.ejb.EntityBean {
047:
048: private P1HomeLocal p1home = null;
049: private P4HomeLocal p4home = null;
050:
051: // ------------------------------------------------------------------
052: // Get and Set accessor methods of the bean's abstract schema
053: // ------------------------------------------------------------------
054: public abstract String getId3();
055:
056: public abstract void setId3(String id3);
057:
058: public abstract String getId();
059:
060: public abstract void setId(String id);
061:
062: public abstract P1Local getP1();
063:
064: public abstract void setP1(P1Local p1);
065:
066: public abstract P4Local getP4();
067:
068: public abstract void setP4(P4Local p4);
069:
070: // ------------------------------------------------------------------
071: // EntityBean implementation
072: // ------------------------------------------------------------------
073:
074: static protected Logger logger = null;
075: EntityContext ejbContext;
076:
077: /**
078: * The Entity bean can define 0 or more ejbCreate methods.
079: *
080: * @throws CreateException Failure to create an entity EJB object.
081: * @throws DuplicateKeyException An object with the same key already exists.
082: */
083: public String ejbCreate(String id3, String id)
084: throws CreateException, DuplicateKeyException {
085: logger.log(BasicLevel.DEBUG, "");
086:
087: // Init here the bean fields
088: setId3(id3);
089: setId(id);
090:
091: // In CMP, should return null.
092: return null;
093: }
094:
095: /**
096: * There must be an ejbPostCreate par ejbCreate method
097: * @throws CreateException Failure to create an entity EJB object.
098: */
099: public void ejbPostCreate(String id3, String id)
100: throws CreateException {
101: logger.log(BasicLevel.DEBUG, "id3=" + id3 + " id=" + id);
102: try {
103: P1Local p1l = p1home.findByPrimaryKey(id);
104: setP1(p1l);
105: } catch (FinderException e) {
106: throw new CreateException(
107: "P3 cannot exist without matching P1");
108: }
109: try {
110: P4PK pk4 = new P4PK(id);
111: P4Local p4l = p4home.findByPrimaryKey(pk4);
112: setP4(p4l);
113: } catch (FinderException e) {
114: throw new CreateException(
115: "P3 cannot exist without matching P4");
116: }
117: }
118:
119: /**
120: * Set the associated entity context. The container invokes this method
121: * on an instance after the instance has been created.
122: * This method is called in an unspecified transaction context.
123: *
124: * @param ctx - An EntityContext interface for the instance. The instance
125: * should store the reference to the context in an instance variable.
126: * @throws EJBException Thrown by the method to indicate a failure caused by a
127: * system-level error.
128: */
129: public void setEntityContext(EntityContext ctx) {
130: if (logger == null)
131: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
132: logger.log(BasicLevel.DEBUG, "");
133: ejbContext = ctx;
134: try {
135: Context ictx = new InitialContext();
136: p1home = (P1HomeLocal) ictx.lookup("java:comp/env/ejb/p1");
137: p4home = (P4HomeLocal) ictx.lookup("java:comp/env/ejb/p4");
138: } catch (NamingException e) {
139: throw new EJBException("Impossible to get HomeLocal:", e);
140: }
141: }
142:
143: /**
144: * Unset the associated entity context. The container calls this method
145: * before removing the instance.
146: * This is the last method that the container invokes on the instance.
147: * The Java garbage collector will eventually invoke the finalize() method
148: * on the instance.
149: * This method is called in an unspecified transaction context.
150: *
151: * @throws EJBException Thrown by the method to indicate a failure caused by a
152: * system-level error.
153: */
154: public void unsetEntityContext() {
155: logger.log(BasicLevel.DEBUG, "");
156: ejbContext = null;
157: }
158:
159: /**
160: * A container invokes this method before it removes the EJB object
161: * that is currently associated with the instance. This method is
162: * invoked when a client invokes a remove operation on the enterprise Bean's
163: * home interface or the EJB object's remote interface. This method
164: * transitions the instance from the ready state to the pool of available
165: * instances.
166: *
167: * This method is called in the transaction context of the remove operation.
168: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
169: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
170: * error.
171: */
172: public void ejbRemove() throws RemoveException {
173: logger.log(BasicLevel.DEBUG, "");
174: }
175:
176: /**
177: * A container invokes this method to instruct the instance to synchronize
178: * its state by loading it state from the underlying database.
179: * This method always executes in the proper transaction context.
180: *
181: * @throws EJBException Thrown by the method to indicate a failure caused by
182: * a system-level error.
183: */
184: public void ejbLoad() {
185: logger.log(BasicLevel.DEBUG, "");
186: }
187:
188: /**
189: * A container invokes this method to instruct the instance to synchronize
190: * its state by storing it to the underlying database.
191: * This method always executes in the proper transaction context.
192: *
193: * @throws EJBException Thrown by the method to indicate a failure caused by
194: * a system-level error.
195: */
196: public void ejbStore() {
197: logger.log(BasicLevel.DEBUG, "");
198: }
199:
200: /**
201: * A container invokes this method on an instance before the instance
202: * becomes disassociated with a specific EJB object.
203: */
204: public void ejbPassivate() {
205: logger.log(BasicLevel.DEBUG, "");
206: }
207:
208: /**
209: * A container invokes this method when the instance is taken out of
210: * the pool of available instances to become associated with a specific
211: * EJB object.
212: */
213: public void ejbActivate() {
214: logger.log(BasicLevel.DEBUG, "");
215: }
216:
217: // ---------------------------------------------------------------------
218: // P3Remote Implementation
219: // ---------------------------------------------------------------------
220:
221: /**
222: *
223: */
224: public String getP1Value() {
225: P1Local p1l = getP1();
226: return p1l.getPf1();
227: }
228:
229: public String getP4Value() {
230: P4Local p4l = getP4();
231: return p4l.getPf4();
232: }
233: }
|