KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jspPhoneBook > data > PersonDataStruct


1
2 /*-----------------------------------------------------------------------------
3  * Enhydra Java Application Server
4  * Copyright 1997-2000 Lutris Technologies, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  * must display the following acknowledgement:
17  * This product includes Enhydra software developed by Lutris
18  * Technologies, Inc. and its contributors.
19  * 4. Neither the name of Lutris Technologies nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *-----------------------------------------------------------------------------
35  * phoneList.data/PersonDataStruct.java
36  *-----------------------------------------------------------------------------
37  */

38
39
40 package jspPhoneBook.data;
41
42 import com.lutris.appserver.server.sql.*;
43 import java.sql.*;
44 import java.math.*;
45 import java.io.Serializable JavaDoc;
46 import com.lutris.dods.builder.generator.dataobject.*;
47 import com.lutris.dods.builder.generator.query.*;
48 import org.enhydra.dods.cache.Condition;
49
50
51 /**
52  * Data structure for DO class.
53  * A container for data members of a DO class.
54  * A DO class contains a reference to a DataStruct class. This reference
55  * can be null (a DO whose data has not yet been retrieved from the database),
56  * allowing a DO object to be a lightweight placeholder until its data is needed.
57  *
58  * @version $Revision: 1.1 $
59  * @author EnhydraTeam
60  * @since PhoneList;
61  */

62 public class PersonDataStruct extends CoreDataStruct implements Cloneable JavaDoc, Serializable JavaDoc {
63
64     /**
65      * A DO refers to this DataStruct.
66      * readOnly is set to true when the DO is stored in its class cache.
67      */

68     public boolean readOnly = false;
69
70     /**
71      * Since originalData is being constructed for every DO, this flag
72      * "knows" if DataStruct has any useful content.
73      */

74     protected boolean isEmpty = true;
75
76     /**
77      * String identifying logical database this DataStruct belongs to.
78      */

79     private String JavaDoc databaseName = null;
80
81     private byte[] copyByteArray( byte[] source ) {
82         byte[] dest = new byte[ source.length ];
83         System.arraycopy( source, 0, dest, 0, source.length );
84         return dest;
85     }
86
87     /**
88      * @deprecated Use get_Version()
89      * @return version
90      */

91     protected int getVersion () {
92         return get_Version();
93     }
94
95     /**
96      * @return version
97      */

98     protected int get_Version () {
99         return super.get_Version();
100     }
101
102     /**
103      * @deprecated Use set_Version()
104      * @return version
105      */

106     protected void setVersion (int v) {
107         set_Version(v);
108     }
109
110     /**
111      * @param v
112      */

113     protected void set_Version (int v) {
114         super.set_Version(v);
115     }
116
117     /**
118      * @deprecated Use get_OId()
119      * @return this object's identifier.
120      */

121     public ObjectId getOId() {
122     return get_OId();
123     }
124
125     /**
126      * Returns this object's identifier.
127      * @return this object's identifier.
128      */

129     public ObjectId get_OId() {
130     return super.get_OId();
131     }
132
133     /**
134      * @deprecated Use set_OId()
135      * @param oId this object's identifier.
136      */

137     protected void setOId(ObjectId oId) {
138         set_OId(oId);
139     }
140
141     /**
142      * Sets this object's identifier.
143      * @param oId this object's identifier.
144      */

145     protected void set_OId(ObjectId oId) {
146         super.set_OId(oId);
147     }
148     
149     
150
151     /**
152      * Returns this object's handle (identifier as a string).
153      * @return This object's identifier as a string.
154      *
155      * @exception DatabaseManagerException
156      * If a connection to the database cannot be established, etc.
157      */

158     public String JavaDoc get_Handle()
159     throws DatabaseManagerException {
160         String JavaDoc ret = null;
161         if ( null == get_OId() )
162                throw new DatabaseManagerException( "ID not set " );
163         ret = get_OId().toString();
164         return ret;
165     }
166
167
168     /**
169      * Returns this object's cache handle (String in the form:
170      * "<database_name>.<indetifier_as_String>").
171      *
172      * @return cache handle.
173      * @exception DatabaseManagerException
174      * If a connection to the database cannot be established, etc.
175      */

176     public String JavaDoc get_CacheHandle()throws DatabaseManagerException {
177         String JavaDoc ret = get_Database() + "." + get_Handle();
178         return ret;
179     }
180
181
182
183     /**
184      * @param dbName - name of the logical database this DataStruct should belong to.
185      */

186     public void set_Database(String JavaDoc dbName) {
187          if (null != databaseName)
188              throw new Error JavaDoc("Whatta hack you are doing! Multiple db setting not allowed.");
189          databaseName = dbName;
190     }
191
192
193     /**
194      * @return name of the logical database this DataStruct belongs to.
195      */

196     public String JavaDoc get_Database() {
197          return databaseName;
198     }
199     
200
201     private String JavaDoc firstName = null;
202
203
204
205     /**
206
207      * Used for query caching.
208
209      */

210
211     static public final int COLUMN_FIRSTNAME = 0;
212
213     
214
215
216
217     /**
218
219      *
220
221      */

222
223     public void setFirstName(String JavaDoc _firstName) {
224
225         if (readOnly)
226
227             throw new Error JavaDoc("This should never happen! setFirstName on "
228
229                 + this +" is being called although readOnly is true");
230
231 // boolean bDiff = GenericDO.isNewDataDifferent_String(firstName, _firstName);
232

233         firstName = _firstName;
234
235 // return bDiff;
236

237     }
238
239
240
241     /**
242
243      *
244
245      */

246
247     public String JavaDoc getFirstName() {
248
249         return firstName;
250
251     }
252
253     
254
255     private String JavaDoc lastName = null;
256
257
258
259     /**
260
261      * Used for query caching.
262
263      */

264
265     static public final int COLUMN_LASTNAME = 1;
266
267     
268
269
270
271     /**
272
273      *
274
275      */

276
277     public void setLastName(String JavaDoc _lastName) {
278
279         if (readOnly)
280
281             throw new Error JavaDoc("This should never happen! setLastName on "
282
283                 + this +" is being called although readOnly is true");
284
285 // boolean bDiff = GenericDO.isNewDataDifferent_String(lastName, _lastName);
286

287         lastName = _lastName;
288
289 // return bDiff;
290

291     }
292
293
294
295     /**
296
297      *
298
299      */

300
301     public String JavaDoc getLastName() {
302
303         return lastName;
304
305     }
306
307     
308
309     private String JavaDoc phoneNumber = null;
310
311
312
313     /**
314
315      * Used for query caching.
316
317      */

318
319     static public final int COLUMN_PHONENUMBER = 2;
320
321     
322
323
324
325     /**
326
327      *
328
329      */

330
331     public void setPhoneNumber(String JavaDoc _phoneNumber) {
332
333         if (readOnly)
334
335             throw new Error JavaDoc("This should never happen! setPhoneNumber on "
336
337                 + this +" is being called although readOnly is true");
338
339 // boolean bDiff = GenericDO.isNewDataDifferent_String(phoneNumber, _phoneNumber);
340

341         phoneNumber = _phoneNumber;
342
343 // return bDiff;
344

345     }
346
347
348
349     /**
350
351      *
352
353      */

354
355     public String JavaDoc getPhoneNumber() {
356
357         return phoneNumber;
358
359     }
360
361
362     /**
363      * Used for query caching.
364      */

365     static public final int COLUMN_OID = 3;
366
367     /**
368      * Compares whether this DataStruct object satisfies condition cond.
369      *
370      * @param cond Condition of the query.
371      *
372      * @return true if this DataStruct object satisfies condition of this query,
373      * otherwise false.
374      */

375     public boolean compareCond(Condition cond) {
376         try {
377             switch (cond.getColumnIndex()) {
378               case COLUMN_FIRSTNAME:
379
380                    return QueryBuilder.compare(getFirstName(),cond.getValue(),cond.getOperator());
381
382
383
384               case COLUMN_LASTNAME:
385
386                    return QueryBuilder.compare(getLastName(),cond.getValue(),cond.getOperator());
387
388
389
390               case COLUMN_PHONENUMBER:
391
392                    return QueryBuilder.compare(getPhoneNumber(),cond.getValue(),cond.getOperator());
393
394
395
396
397                 case COLUMN_OID:
398                     return QueryBuilder.compare(get_CacheHandle(),cond.getValue(),cond.getOperator());
399             }
400         } catch (Exception JavaDoc e) {
401           System.out.println("************************** compareCond catck blok");
402         }
403         return false;
404     }
405
406     /**
407      * Create a copy of the guts of a DO.
408      *
409      * @return Copied DataStruct object.
410      *
411      * @exception DatabaseManagerException
412      * if createExisting() fails for a contained DO
413      * @exception ObjectIdException
414      * if GenericDO has trouble obtaining a valid id.
415      */

416     public PersonDataStruct duplicate()
417     throws DatabaseManagerException, ObjectIdException {
418         PersonDataStruct ret = new PersonDataStruct ();
419         if (!isEmpty) {
420             ret.firstName = GenericDO.copyString(firstName);
421
422             ret.lastName = GenericDO.copyString(lastName);
423
424             ret.phoneNumber = GenericDO.copyString(phoneNumber);
425
426
427         }
428         ret.set_OId(get_OId());
429         ret.set_Version(get_Version());
430         ret.databaseName=get_Database();
431         ret.isEmpty = isEmpty;
432         return ret;
433     }
434 }
435
Popular Tags