001: // BankAccountECL.java
002:
003: package org.objectweb.clusterDemo;
004:
005: import javax.ejb.CreateException;
006: import javax.ejb.DuplicateKeyException;
007: import javax.ejb.EntityBean;
008: import javax.ejb.EntityContext;
009: import javax.ejb.RemoveException;
010:
011: import org.objectweb.jonas.common.Log;
012: import org.objectweb.util.monolog.api.Logger;
013: import org.objectweb.util.monolog.api.BasicLevel;
014:
015: /**
016: *
017: */
018: public abstract class BankAccountECL implements EntityBean {
019:
020: static private Logger logger = null;
021:
022: EntityContext ejbContext;
023:
024: // ------------------------------------------------------------------
025: // EntityBean implementation
026: // ------------------------------------------------------------------
027:
028: /**
029: * Set the associated entity context. The container invokes this method on
030: * an instance after the instance has been created. This method is called in
031: * an unspecified transaction context.
032: * @param ctx - An EntityContext interface for the instance. The instance
033: * should store the reference to the context in an instance variable.
034: * @throws EJBException Thrown by the method to indicate a failure caused by
035: * a system-level error.
036: */
037: public void setEntityContext(EntityContext ctx) {
038: if (logger == null) {
039: logger = Log.getLogger("org.objectweb.jonas_tests");
040: }
041: logger.log(BasicLevel.DEBUG, "");
042: ejbContext = ctx;
043: }
044:
045: /**
046: * Unset the associated entity context. The container calls this method
047: * before removing the instance. This is the last method that the container
048: * invokes on the instance. The Java garbage collector will eventually
049: * invoke the finalize() method on the instance. This method is called in an
050: * unspecified transaction context.
051: * @throws EJBException Thrown by the method to indicate a failure caused by
052: * a system-level error.
053: */
054: public void unsetEntityContext() {
055: logger.log(BasicLevel.DEBUG, "");
056: ejbContext = null;
057: }
058:
059: /**
060: * A container invokes this method before it removes the EJB object that is
061: * currently associated with the instance. This method is invoked when a
062: * client invokes a remove operation on the enterprise Bean's home interface
063: * or the EJB object's remote interface. This method transitions the
064: * instance from the ready state to the pool of available instances. This
065: * method is called in the transaction context of the remove operation.
066: * @throws RemoveException The enterprise Bean does not allow destruction of
067: * the object.
068: * @throws EJBException - Thrown by the method to indicate a failure caused
069: * by a system-level error.
070: */
071: public void ejbRemove() throws RemoveException {
072: logger.log(BasicLevel.DEBUG, "");
073: }
074:
075: /**
076: * A container invokes this method to instruct the instance to synchronize
077: * its state by loading it state from the underlying database. This method
078: * always executes in the proper transaction context.
079: * @throws EJBException Thrown by the method to indicate a failure caused by
080: * a system-level error.
081: */
082: public void ejbLoad() {
083: logger.log(BasicLevel.DEBUG, "");
084: }
085:
086: /**
087: * A container invokes this method to instruct the instance to synchronize
088: * its state by storing it to the underlying database. This method always
089: * executes in the proper transaction context.
090: * @throws EJBException Thrown by the method to indicate a failure caused by
091: * a system-level error.
092: */
093: public void ejbStore() {
094: logger.log(BasicLevel.DEBUG, "");
095: }
096:
097: /**
098: * There must be an ejbPostCreate par ejbCreate method
099: * @throws CreateException Failure to create an entity EJB object.
100: */
101: public void ejbPostCreate(int b, String n) throws CreateException {
102: logger.log(BasicLevel.DEBUG, "");
103: }
104:
105: /**
106: * The Entity bean can define 0 or more ejbCreate methods.
107: * @throws CreateException Failure to create an entity EJB object.
108: * @throws DuplicateKeyException An object with the same key already exists.
109: */
110: public java.lang.String ejbCreate(int b, String n)
111: throws CreateException, DuplicateKeyException {
112: logger.log(BasicLevel.DEBUG, "");
113:
114: // Init here the bean fields
115: setBalance(b);
116: setName(n);
117:
118: // In CMP, should return null.
119: return null;
120: }
121:
122: /**
123: * A container invokes this method on an instance before the instance
124: * becomes disassociated with a specific EJB object.
125: */
126: public void ejbPassivate() {
127: logger.log(BasicLevel.DEBUG, "");
128: }
129:
130: /**
131: * A container invokes this method when the instance is taken out of the
132: * pool of available instances to become associated with a specific EJB
133: * object.
134: */
135: public void ejbActivate() {
136: logger.log(BasicLevel.DEBUG, "");
137: }
138:
139: // ------------------------------------------------------------------
140: // BankAccount implementation
141: // ------------------------------------------------------------------
142:
143: /**
144: * credit method
145: */
146: public void putMoney(int value) {
147: logger.log(BasicLevel.DEBUG, "");
148: setBalance(getBalance() + value);
149: }
150:
151: /**
152: * credit method
153: */
154: public void getMoney(int value) {
155: logger.log(BasicLevel.DEBUG, "");
156: setBalance(getBalance() - value);
157: }
158:
159: public abstract String getName();
160:
161: public abstract void setName(String name);
162:
163: public abstract double getBalance();
164:
165: public abstract void setBalance(double balance);
166:
167: }
|