001: /*-----------------------------------------------------------------------------
002: * Enhydra Java Application Server
003: * Copyright 1997-2000 Lutris Technologies, Inc.
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the distribution.
014: * 3. All advertising materials mentioning features or use of this software
015: * must display the following acknowledgement:
016: * This product includes Enhydra software developed by Lutris
017: * Technologies, Inc. and its contributors.
018: * 4. Neither the name of Lutris Technologies nor the names of its contributors
019: * may be used to endorse or promote products derived from this software
020: * without specific prior written permission.
021: *
022: * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
023: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
024: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
025: * ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
026: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
027: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
028: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
029: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
030: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
031: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
032: * POSSIBILITY OF SUCH DAMAGE.
033: *-----------------------------------------------------------------------------
034: * phoneList.data/PersonDataStruct.java
035: *-----------------------------------------------------------------------------
036: */
037:
038: package jspPhoneBook.data;
039:
040: import com.lutris.appserver.server.sql.*;
041: import java.sql.*;
042: import java.math.*;
043: import java.io.Serializable;
044: import com.lutris.dods.builder.generator.dataobject.*;
045: import com.lutris.dods.builder.generator.query.*;
046: import org.enhydra.dods.cache.Condition;
047:
048: /**
049: * Data structure for DO class.
050: * A container for data members of a DO class.
051: * A DO class contains a reference to a DataStruct class. This reference
052: * can be null (a DO whose data has not yet been retrieved from the database),
053: * allowing a DO object to be a lightweight placeholder until its data is needed.
054: *
055: * @version $Revision: 1.1 $
056: * @author EnhydraTeam
057: * @since PhoneList;
058: */
059: public class PersonDataStruct extends CoreDataStruct implements
060: Cloneable, Serializable {
061:
062: /**
063: * A DO refers to this DataStruct.
064: * readOnly is set to true when the DO is stored in its class cache.
065: */
066: public boolean readOnly = false;
067:
068: /**
069: * Since originalData is being constructed for every DO, this flag
070: * "knows" if DataStruct has any useful content.
071: */
072: protected boolean isEmpty = true;
073:
074: /**
075: * String identifying logical database this DataStruct belongs to.
076: */
077: private String databaseName = null;
078:
079: private byte[] copyByteArray(byte[] source) {
080: byte[] dest = new byte[source.length];
081: System.arraycopy(source, 0, dest, 0, source.length);
082: return dest;
083: }
084:
085: /**
086: * @deprecated Use get_Version()
087: * @return version
088: */
089: protected int getVersion() {
090: return get_Version();
091: }
092:
093: /**
094: * @return version
095: */
096: protected int get_Version() {
097: return super .get_Version();
098: }
099:
100: /**
101: * @deprecated Use set_Version()
102: * @return version
103: */
104: protected void setVersion(int v) {
105: set_Version(v);
106: }
107:
108: /**
109: * @param v
110: */
111: protected void set_Version(int v) {
112: super .set_Version(v);
113: }
114:
115: /**
116: * @deprecated Use get_OId()
117: * @return this object's identifier.
118: */
119: public ObjectId getOId() {
120: return get_OId();
121: }
122:
123: /**
124: * Returns this object's identifier.
125: * @return this object's identifier.
126: */
127: public ObjectId get_OId() {
128: return super .get_OId();
129: }
130:
131: /**
132: * @deprecated Use set_OId()
133: * @param oId this object's identifier.
134: */
135: protected void setOId(ObjectId oId) {
136: set_OId(oId);
137: }
138:
139: /**
140: * Sets this object's identifier.
141: * @param oId this object's identifier.
142: */
143: protected void set_OId(ObjectId oId) {
144: super .set_OId(oId);
145: }
146:
147: /**
148: * Returns this object's handle (identifier as a string).
149: * @return This object's identifier as a string.
150: *
151: * @exception DatabaseManagerException
152: * If a connection to the database cannot be established, etc.
153: */
154: public String get_Handle() throws DatabaseManagerException {
155: String ret = null;
156: if (null == get_OId())
157: throw new DatabaseManagerException("ID not set ");
158: ret = get_OId().toString();
159: return ret;
160: }
161:
162: /**
163: * Returns this object's cache handle (String in the form:
164: * "<database_name>.<indetifier_as_String>").
165: *
166: * @return cache handle.
167: * @exception DatabaseManagerException
168: * If a connection to the database cannot be established, etc.
169: */
170: public String get_CacheHandle() throws DatabaseManagerException {
171: String ret = get_Database() + "." + get_Handle();
172: return ret;
173: }
174:
175: /**
176: * @param dbName - name of the logical database this DataStruct should belong to.
177: */
178: public void set_Database(String dbName) {
179: if (null != databaseName)
180: throw new Error(
181: "Whatta hack you are doing! Multiple db setting not allowed.");
182: databaseName = dbName;
183: }
184:
185: /**
186: * @return name of the logical database this DataStruct belongs to.
187: */
188: public String get_Database() {
189: return databaseName;
190: }
191:
192: private String firstName = null;
193:
194: /**
195:
196: * Used for query caching.
197:
198: */
199:
200: static public final int COLUMN_FIRSTNAME = 0;
201:
202: /**
203:
204: *
205:
206: */
207:
208: public void setFirstName(String _firstName) {
209:
210: if (readOnly)
211:
212: throw new Error(
213: "This should never happen! setFirstName on "
214:
215: + this
216: + " is being called although readOnly is true");
217:
218: // boolean bDiff = GenericDO.isNewDataDifferent_String(firstName, _firstName);
219:
220: firstName = _firstName;
221:
222: // return bDiff;
223:
224: }
225:
226: /**
227:
228: *
229:
230: */
231:
232: public String getFirstName() {
233:
234: return firstName;
235:
236: }
237:
238: private String lastName = null;
239:
240: /**
241:
242: * Used for query caching.
243:
244: */
245:
246: static public final int COLUMN_LASTNAME = 1;
247:
248: /**
249:
250: *
251:
252: */
253:
254: public void setLastName(String _lastName) {
255:
256: if (readOnly)
257:
258: throw new Error("This should never happen! setLastName on "
259:
260: + this + " is being called although readOnly is true");
261:
262: // boolean bDiff = GenericDO.isNewDataDifferent_String(lastName, _lastName);
263:
264: lastName = _lastName;
265:
266: // return bDiff;
267:
268: }
269:
270: /**
271:
272: *
273:
274: */
275:
276: public String getLastName() {
277:
278: return lastName;
279:
280: }
281:
282: private String phoneNumber = null;
283:
284: /**
285:
286: * Used for query caching.
287:
288: */
289:
290: static public final int COLUMN_PHONENUMBER = 2;
291:
292: /**
293:
294: *
295:
296: */
297:
298: public void setPhoneNumber(String _phoneNumber) {
299:
300: if (readOnly)
301:
302: throw new Error(
303: "This should never happen! setPhoneNumber on "
304:
305: + this
306: + " is being called although readOnly is true");
307:
308: // boolean bDiff = GenericDO.isNewDataDifferent_String(phoneNumber, _phoneNumber);
309:
310: phoneNumber = _phoneNumber;
311:
312: // return bDiff;
313:
314: }
315:
316: /**
317:
318: *
319:
320: */
321:
322: public String getPhoneNumber() {
323:
324: return phoneNumber;
325:
326: }
327:
328: /**
329: * Used for query caching.
330: */
331: static public final int COLUMN_OID = 3;
332:
333: /**
334: * Compares whether this DataStruct object satisfies condition cond.
335: *
336: * @param cond Condition of the query.
337: *
338: * @return true if this DataStruct object satisfies condition of this query,
339: * otherwise false.
340: */
341: public boolean compareCond(Condition cond) {
342: try {
343: switch (cond.getColumnIndex()) {
344: case COLUMN_FIRSTNAME:
345:
346: return QueryBuilder.compare(getFirstName(), cond
347: .getValue(), cond.getOperator());
348:
349: case COLUMN_LASTNAME:
350:
351: return QueryBuilder.compare(getLastName(), cond
352: .getValue(), cond.getOperator());
353:
354: case COLUMN_PHONENUMBER:
355:
356: return QueryBuilder.compare(getPhoneNumber(), cond
357: .getValue(), cond.getOperator());
358:
359: case COLUMN_OID:
360: return QueryBuilder.compare(get_CacheHandle(), cond
361: .getValue(), cond.getOperator());
362: }
363: } catch (Exception e) {
364: System.out
365: .println("************************** compareCond catck blok");
366: }
367: return false;
368: }
369:
370: /**
371: * Create a copy of the guts of a DO.
372: *
373: * @return Copied DataStruct object.
374: *
375: * @exception DatabaseManagerException
376: * if createExisting() fails for a contained DO
377: * @exception ObjectIdException
378: * if GenericDO has trouble obtaining a valid id.
379: */
380: public PersonDataStruct duplicate()
381: throws DatabaseManagerException, ObjectIdException {
382: PersonDataStruct ret = new PersonDataStruct();
383: if (!isEmpty) {
384: ret.firstName = GenericDO.copyString(firstName);
385:
386: ret.lastName = GenericDO.copyString(lastName);
387:
388: ret.phoneNumber = GenericDO.copyString(phoneNumber);
389:
390: }
391: ret.set_OId(get_OId());
392: ret.set_Version(get_Version());
393: ret.databaseName = get_Database();
394: ret.isEmpty = isEmpty;
395: return ret;
396: }
397: }
|