001: // CustomerEC2R.java
002: package org.objectweb.jonas.stests.appli;
003:
004: import org.objectweb.jonas.common.Log;
005: import org.objectweb.util.monolog.api.Logger;
006: import org.objectweb.util.monolog.api.BasicLevel;
007:
008: /**
009: *
010: */
011: public abstract class CustomerEC2R implements javax.ejb.EntityBean {
012:
013: static private Logger logger = null;
014: javax.ejb.EntityContext ejbContext;
015:
016: /**
017: * Create a new Customer with minimal information.
018: * <p>
019: * @param id Customer ID for the customer being created, must be unique
020: * @param fN First name of the customer
021: * @param lN Last name of the customer
022: * @param phone Phone number of the customer
023: * @return Customer
024: * @exception javax.ejb.CreateException Creation Exception
025: * @exception java.rmi.RemoteException Remote Exception
026: */
027:
028: public String ejbCreate(Integer custID, String fN, String lN,
029: String phone) throws javax.ejb.CreateException {
030: setCustomerID(custID);
031: setFirstName(fN);
032: setLastName(lN);
033: setPhone(phone);
034: setAddressLine1("unknown");
035: setAddressLine2("unknown");
036: setCity("unknown");
037: setState("unknown");
038: setZip("unknown");
039: setCreditLimit(0);
040: setBalance(0);
041: setYearToDateBalance(0);
042: return null;
043: }
044:
045: /**
046: * Create a new Customer with all parameters, except balances which will automatically
047: * be initialized to zero
048: * <p>
049: * @param id Customer ID for the customer being created, must be unique
050: * @param fN First name of the customer
051: * @param lN Last name of the customer
052: * @param inits Middle initials of the customer
053: * @param phone Phone number of the customer
054: * @param addr1 First address line of the customer
055: * @param addr2 Second address line of the customer
056: * @param city City of the customer's mailing address
057: * @param state State of the customer's mailing address
058: * @param zip Zip code of the customer's mailing address
059: * @param creditLimit Credit limit allowed for this cusomter
060: * @return Customer
061: * @exception javax.ejb.CreateException Creation Exception
062: * @exception java.rmi.RemoteException Remote Exception
063: */
064: public String ejbCreate(Integer Id, String fN, String lN,
065: String inits, String addr1, String addr2, String city,
066: String state, String zip, String phone, float creditLimit)
067: throws javax.ejb.CreateException {
068: logger.log(BasicLevel.DEBUG, "");
069:
070: // Init here the bean fields
071: setCustomerID(Id);
072: setFirstName(fN);
073: setLastName(lN);
074: setPhone(phone);
075: setAddressLine1(addr1);
076: setAddressLine2(addr2);
077: setCity(city);
078: setState(state);
079: setZip(zip);
080: setCreditLimit(creditLimit);
081: setBalance(0);
082: setYearToDateBalance(0);
083: return null;
084: }
085:
086: public void ejbPostCreate(Integer custID, String fN, String lN,
087: String phone) {
088: logger.log(BasicLevel.DEBUG, "");
089: }
090:
091: public void ejbPostCreate(Integer Id, String fN, String lN,
092: String inits, String addr1, String addr2, String city,
093: String state, String zip, String phone, float creditLimit) {
094: logger.log(BasicLevel.DEBUG, "");
095: }
096:
097: // ------------------------------------------------------------------
098: // Persistent fields
099: //
100: // ------------------------------------------------------------------
101: public abstract Integer getCustomerID();
102:
103: public abstract void setCustomerID(Integer id);
104:
105: public abstract String getFirstName();
106:
107: public abstract void setFirstName(String fn);
108:
109: public abstract String getLastName();
110:
111: public abstract void setLastName(String ln);
112:
113: public abstract String getMiddleInitials();
114:
115: public abstract void setMiddleInitials(String mi);
116:
117: public abstract String getPhone();
118:
119: public abstract void setPhone(String phone);
120:
121: public abstract String getAddressLine1();
122:
123: public abstract void setAddressLine1(String line);
124:
125: public abstract String getAddressLine2();
126:
127: public abstract void setAddressLine2(String line);
128:
129: public abstract String getCity();
130:
131: public abstract void setCity(String city);
132:
133: public abstract String getState();
134:
135: public abstract void setState(String state);
136:
137: public abstract String getZip();
138:
139: public abstract void setZip(String zip);
140:
141: public abstract float getBalance();
142:
143: public abstract void setBalance(float balance);
144:
145: public abstract float getYearToDateBalance();
146:
147: public abstract void setYearToDateBalance(float ytdBalance);
148:
149: public abstract float getCreditLimit();
150:
151: public abstract void setCreditLimit(float limit);
152:
153: // ------------------------------------------------------------------
154: // Standard call back methods
155: // ------------------------------------------------------------------
156:
157: public void setEntityContext(javax.ejb.EntityContext ctx) {
158: if (logger == null) {
159: logger = Log.getLogger("org.objectweb.jonas_tests");
160: }
161: logger.log(BasicLevel.DEBUG, "");
162: ejbContext = ctx;
163: }
164:
165: public void unsetEntityContext() {
166: logger.log(BasicLevel.DEBUG, "");
167: ejbContext = null;
168: }
169:
170: public void ejbRemove() throws javax.ejb.RemoveException {
171: logger.log(BasicLevel.DEBUG, "");
172: }
173:
174: public void ejbLoad() {
175: logger.log(BasicLevel.DEBUG, "");
176: }
177:
178: public void ejbStore() {
179: logger.log(BasicLevel.DEBUG, "");
180: }
181:
182: public void ejbPassivate() {
183: logger.log(BasicLevel.DEBUG, "");
184: }
185:
186: public void ejbActivate() {
187: logger.log(BasicLevel.DEBUG, "");
188: }
189:
190: /**
191: * Update the balance and year to date balance with the total amount from an order.
192: * <p>
193: * @param orderAmount Order amount to update the balances with <i>(Mandatory)</i>
194: * @return void
195: * @exception java.rmi.RemoteException Remote exception
196: */
197: /*------------------------------------------------------------------*/
198: public void updateBalance(float orderAmount) {
199: float ytd = getYearToDateBalance();
200: setYearToDateBalance(ytd + orderAmount);
201: float balance = getBalance();
202: setBalance(balance + orderAmount);
203: }
204: }
|