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: MRecordEC.java 4791 2004-05-24 12:32:46Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: // MRecordEC.java
027: package org.objectweb.jonas.jtests.beans.message;
028:
029: import java.rmi.RemoteException;
030: import javax.ejb.CreateException;
031: import javax.ejb.DuplicateKeyException;
032: import javax.ejb.EntityBean;
033: import javax.ejb.EntityContext;
034: import javax.ejb.RemoveException;
035:
036: import org.objectweb.jonas.common.Log;
037: import org.objectweb.util.monolog.api.Logger;
038: import org.objectweb.util.monolog.api.BasicLevel;
039:
040: /**
041: *
042: */
043: public class MRecordEC implements EntityBean {
044:
045: protected static Logger logger = null;
046: EntityContext ejbContext;
047:
048: // ------------------------------------------------------------------
049: // State of the bean.
050: // They must be public for Container Managed Persistance.
051: // ------------------------------------------------------------------
052: public String uuid;
053: public String dest;
054: public int value;
055: public int count;
056: public String mdb;
057:
058: // ------------------------------------------------------------------
059: // EntityBean implementation
060: // ------------------------------------------------------------------
061:
062: /**
063: * Set the associated entity context. The container invokes this method
064: * on an instance after the instance has been created.
065: * This method is called in an unspecified transaction context.
066: *
067: * @param ctx - An EntityContext interface for the instance. The instance
068: * should store the reference to the context in an instance variable.
069: * @throws EJBException Thrown by the method to indicate a failure caused by a
070: * system-level error.
071: */
072: public void setEntityContext(EntityContext ctx) {
073: if (logger == null) {
074: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
075: }
076: logger.log(BasicLevel.DEBUG, "");
077: ejbContext = ctx;
078: }
079:
080: /**
081: * Unset the associated entity context. The container calls this method
082: * before removing the instance.
083: * This is the last method that the container invokes on the instance.
084: * The Java garbage collector will eventually invoke the finalize() method
085: * on the instance.
086: * This method is called in an unspecified transaction context.
087: *
088: * @throws EJBException Thrown by the method to indicate a failure caused by a
089: * system-level error.
090: */
091: public void unsetEntityContext() {
092: ejbContext = null;
093: }
094:
095: /**
096: * A container invokes this method before it removes the EJB object
097: * that is currently associated with the instance. This method is
098: * invoked when a client invokes a remove operation on the enterprise Bean's
099: * home interface or the EJB object's remote interface. This method
100: * transitions the instance from the ready state to the pool of available
101: * instances.
102: *
103: * This method is called in the transaction context of the remove operation.
104: * @throws RemoveException The enterprise Bean does not allow destruction of the object.
105: * @throws EJBException - Thrown by the method to indicate a failure caused by a system-level
106: * error.
107: */
108: public void ejbRemove() throws RemoveException {
109: logger.log(BasicLevel.DEBUG, "");
110: }
111:
112: /**
113: * A container invokes this method to instruct the instance to synchronize
114: * its state by loading it state from the underlying database.
115: * This method always executes in the proper transaction context.
116: *
117: * @throws EJBException Thrown by the method to indicate a failure caused by
118: * a system-level error.
119: */
120: public void ejbLoad() {
121: logger.log(BasicLevel.DEBUG, "");
122: }
123:
124: /**
125: * A container invokes this method to instruct the instance to synchronize
126: * its state by storing it to the underlying database.
127: * This method always executes in the proper transaction context.
128: *
129: * @throws EJBException Thrown by the method to indicate a failure caused by
130: * a system-level error.
131: */
132: public void ejbStore() {
133: logger.log(BasicLevel.DEBUG, "");
134: }
135:
136: /**
137: * There must be an ejbPostCreate par ejbCreate method
138: *
139: * @throws CreateException Failure to create an entity EJB object.
140: */
141: public void ejbPostCreate(String uuid, String dest, int value,
142: String mdb) throws CreateException {
143: logger.log(BasicLevel.DEBUG, "");
144: }
145:
146: /**
147: * The Entity bean can define 0 or more ejbCreate methods.
148: *
149: * @throws CreateException Failure to create an entity EJB object.
150: * @throws DuplicateKeyException An object with the same key already exists.
151: */
152: public MRecordPK ejbCreate(String uuid, String dest, int value,
153: String mdb) throws CreateException, DuplicateKeyException {
154: logger.log(BasicLevel.DEBUG, "");
155: // Init here the bean fields
156: this .uuid = uuid;
157: this .dest = dest;
158: this .value = value;
159: this .mdb = mdb;
160: this .count = 1;
161:
162: // In CMP, should return null.
163: return null;
164: }
165:
166: /**
167: * A container invokes this method on an instance before the instance
168: * becomes disassociated with a specific EJB object.
169: */
170: public void ejbPassivate() {
171: logger.log(BasicLevel.DEBUG, "");
172: }
173:
174: /**
175: * A container invokes this method when the instance is taken out of
176: * the pool of available instances to become associated with a specific
177: * EJB object.
178: */
179: public void ejbActivate() {
180: logger.log(BasicLevel.DEBUG, "");
181: }
182:
183: // ------------------------------------------------------------------
184: // MRecord implementation
185: // ------------------------------------------------------------------
186:
187: /**
188: * returns UUID
189: */
190: public String getUUID() throws RemoteException {
191: return uuid;
192: }
193:
194: /**
195: * returns dest
196: */
197: public String getDest() throws RemoteException {
198: return dest;
199: }
200:
201: /**
202: * returns value
203: */
204: public int getValue() throws RemoteException {
205: return value;
206: }
207:
208: /**
209: * returns count
210: */
211: public int getCount() throws RemoteException {
212: return count;
213: }
214:
215: /**
216: * Add 1 to the count
217: */
218: public void updateCount() throws RemoteException {
219: count++;
220: }
221:
222: /**
223: * returns MDB
224: */
225: public String getMDB() throws RemoteException {
226: return mdb;
227: }
228:
229: }
|