KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > stockonline > ejb > entity > cmp > stockitem > StockItemBean


1 /*
2  * StockOnline: EJB 1.1 Benchmark.
3  *
4  * Copyright Commonwealth Scientific and Industrial Research Organisation (CSIRO - www.csiro.au), Australia 2001, 2002, 2003.
5  *
6  * Contact: Paul.Brebner@csiro.au
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or any
11  * later version.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16  * for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21  *
22  * Originally developed for the CSIRO Middleware Technology Evaluation (MTE) Project, by
23  * the Software Architectures and Component Technologies Group, CSIRO Mathematical and Information Sciences
24  * Canberra and Sydney, Australia
25  *
26  * www.cmis.csiro.au/sact/
27  * www.cmis.csiro.au/adsat/mte.htm
28  *
29  * Initial developer(s): Shiping Chen, Paul Brebner, Lei Hu, Shuping Ran, Ian Gorton, Anna Liu.
30  * Contributor(s): ______________________.
31  */

32
33
34 //
35
//
36
// History:
37
// 10/08/2001 Shiping Initial coding based on the existing code
38
//
39
//
40
//
41

42 package stockonline.ejb.entity.cmp.stockitem;
43
44 import javax.ejb.*;
45 import javax.naming.*;
46 import javax.rmi.*;
47 import javax.sql.*;
48
49 import java.rmi.*;
50 import java.sql.*;
51 import java.util.*;
52
53 import stockonline.util.*;
54 import stockonline.ejb.entity.interf.*;
55
56 /**
57  * Bean-Managed Persistent Entity Bean.
58  * This Entity Bean represents a stock item.
59  */

60 public class StockItemBean implements EntityBean
61 {
62     final static boolean verbose = false;
63     final static String JavaDoc BEAN_NAME = "cmpStockItem";
64
65     // Container-managed state fields
66
public int stock_id;
67     public String JavaDoc name;
68     public String JavaDoc code;
69     public float current_val;
70     public float high_val;
71     public float low_val;
72
73     protected EntityContext ctx;
74     private transient boolean isDirty; // "dirty" flag
75

76     public StockItemBean()
77     {
78         if (verbose) System.out.println(BEAN_NAME + " instantiated");
79     }
80
81     //----------------------------------------------------------------
82
// Begin business methods
83
//----------------------------------------------------------------
84

85     /**
86      * Get current value of the stock item
87      */

88     public float getCurrentValue()
89     {
90         if (verbose)
91             System.out.println(BEAN_NAME + ".getCurrentValue() called.");
92
93         return current_val;
94     }
95
96     /**
97      * Get values of the stock item, including current, high, low.
98      */

99     public QueryResult getValues()
100     {
101         if (verbose)
102             System.out.println(BEAN_NAME + ".getValues() called.");
103
104         QueryResult result = new QueryResult();
105
106         result.current_val = current_val;
107         result.high_val = high_val;
108         result.low_val = low_val;
109
110         return result;
111     }
112
113     //----------------------------------------------------------------
114
// End public business methods
115
//----------------------------------------------------------------
116

117     //----------------------------------------------------------------
118
// Begin EJB-Required methods. The methods below are called
119
// by the Container, and never called by client code.
120
//----------------------------------------------------------------
121

122     /**
123      * Associates this Bean instance with a particular context.
124      * We can query the Bean properties which customize the Bean here.
125      */

126     public void setEntityContext(EntityContext ctx)
127     {
128         if (verbose)
129             System.out.println(BEAN_NAME + ".setEntityContext() called");
130
131         this.ctx = ctx;
132     }
133
134     /**
135      * Disassociates this Bean instance with a
136      * particular context environment.
137      */

138     public void unsetEntityContext()
139     {
140         if (verbose)
141             System.out.println(BEAN_NAME + ".unsetEntityContext() called");
142
143         this.ctx = null;
144     }
145
146     public StockItemPK ejbCreate() throws CreateException
147     {
148         if (verbose)
149             System.out.println(BEAN_NAME + ".ejbCreate() called.");
150
151         return null;
152     }
153
154     public void ejbPostCreate()
155     {
156         if (verbose)
157             System.out.println(BEAN_NAME + ".ejbPostCreate() called.");
158     }
159
160     /**
161      * Implementation can acquire needed resources.
162      */

163     public void ejbActivate()
164     {
165         if (verbose)
166             System.out.println(BEAN_NAME + ".ejbActivate() called.");
167
168         setModified(true);
169     }
170
171     /**
172      * Releases held resources for passivation.
173      */

174     public void ejbPassivate()
175     {
176         if (verbose)
177             System.out.println(BEAN_NAME + ".ejbPassivate() called.");
178     }
179
180     /**
181      * Removes the Entity Bean from the database.
182      * Corresponds to when client calls home.remove().
183      */

184     public void ejbRemove()
185     {
186         if (verbose)
187             System.out.println(BEAN_NAME + ".ejbRemove() called.");
188     }
189
190     /**
191      * Updates the in-memory Entity Bean object
192      * to reflect the current value stored in the database.
193      */

194     public void ejbLoad() throws RemoteException
195     {
196         if (verbose)
197             System.out.println(BEAN_NAME + ".ejbLoad() called.");
198
199         setModified(false);
200     }
201
202     /**
203      * Updates the database to reflect the
204      * current values of this in-memory Entity Bean object representation.
205      */

206     public void ejbStore() throws RemoteException
207     {
208         if (verbose)
209             System.out.println(BEAN_NAME + ".ejbStore() called.");
210
211         setModified(false);
212     }
213
214 /*
215     public StockItemPK ejbFindByCode(String stockCode)
216         throws FinderException, RemoteException
217     {
218         if (verbose)
219             System.out.println(BEAN_NAME + "FindByCode.ejb() called.");
220         
221         this.code = stockCode;
222         setModified(false);
223
224         return null;
225     }
226 */

227     /**
228      * Returns whether the EJBean has been modified or not.
229      *
230      * @return boolean isDirty
231      */

232     public boolean isModified()
233     {
234         if (verbose)
235             System.out.println (BEAN_NAME + ".isModified(): isDirty = " + (isDirty ? "true" : "false"));
236
237         return isDirty;
238     }
239
240     /**
241      * Sets the EJBean as modified.
242      *
243      * @param flag boolean Flag
244      */

245     public void setModified(boolean flag)
246     {
247         isDirty = flag;
248     }
249
250     //----------------------------------------------------------------
251
// End EJB-Required methods.
252
//----------------------------------------------------------------
253

254 }
255
Popular Tags