KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jspPhoneBook > data > PersonDO


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  * contains WebDocWf extensions
36  *
37  *-----------------------------------------------------------------------------
38  * phoneList.data/PersonDO.java
39  *-----------------------------------------------------------------------------
40  */

41
42
43 package jspPhoneBook.data;
44
45 import java.io.*;
46 import java.sql.*;
47 import java.math.*;
48 import java.util.Hashtable JavaDoc;
49 import java.util.Collection JavaDoc;
50 import java.util.Properties JavaDoc;
51 import java.io.FileInputStream JavaDoc;
52 import java.util.Vector JavaDoc;
53 import java.util.Map JavaDoc;
54 import java.util.HashSet JavaDoc;
55 import java.util.HashMap JavaDoc;
56 import java.util.Iterator JavaDoc;
57 import java.lang.reflect.Method JavaDoc;
58  
59 import com.lutris.logging.LogChannel;
60 import com.lutris.logging.Logger;
61 import org.enhydra.dods.DODS;
62 import com.lutris.util.Config;
63 import com.lutris.util.ConfigException;
64 import com.lutris.appserver.server.sql.*;
65 import com.lutris.appserver.server.sql.standard.*;
66 import com.lutris.dods.builder.generator.dataobject.*;
67 import com.lutris.dods.builder.generator.query.*;
68 import org.enhydra.dods.cache.Condition;
69 import org.enhydra.dods.cache.DataStructCache;
70 import org.enhydra.dods.cache.QueryCache;
71 import org.enhydra.dods.cache.QueryCacheImpl;
72 import org.enhydra.dods.cache.QueryResult;
73 import org.enhydra.dods.cache.ConfigurationAdministration;
74 import org.enhydra.dods.statistics.Statistics;
75 import com.lutris.classloader.MultiClassLoader;
76 import org.enhydra.xml.XMLConfig;
77 import org.enhydra.dods.Common;
78 import org.enhydra.dods.cache.CacheConstants;
79 import org.enhydra.dods.exceptions.AssertionDataObjectException;
80 import org.enhydra.dods.exceptions.CacheObjectException;
81
82
83
84 /**
85  * Data core class, used to set and retrieve the PersonDO information.
86  *
87  * @version $Revision: 1.1 $
88  * @author EnhydraTeam
89  * @since PhoneList
90  */

91  public class PersonDO extends com.lutris.dods.builder.generator.dataobject.GenericDO implements PersonDOI, java.io.Serializable JavaDoc {
92     /**
93      * Static final data members name the table and columns for this DO.
94      * By using these members with an instance of the QueryBuilder class,
95      * an application can perform straight SQL queries while retaining
96      * compile-time checking of table and column usage.
97      *
98      * Example: List the Cities containing Persons named Bob:
99      *
100      * Using straight SQL with QueryBuilder:
101      * Pro: code runs faster because you create fewer objects
102      * Con: code is less clear
103      *
104      * Vector fields = new Vector();
105      * fields.addElement( AddressDO.City );
106      * QueryBuilder qb = new QueryBuilder( fields );
107      * qb.addWhere( PersonDO.FirstName, "Bob" );
108      * qb.addWhere( PersonDO.PrimaryKey, AddressDO.Person );
109      * RDBRow row;
110      * while ( null != ( row = qb.getNextRow() ) ) {
111      * String city = row.get( AddressDO.City ).getString();
112      * }
113      *
114      * Using Query/DO classes:
115      * Pro: code is (often) clearer
116      * Con: code runs slower because you create more objects
117      *
118      * PersonQuery pq = new PersonQuery();
119      * pq.setQueryFirstName( "Bob" );
120      * PersonDO[] bobs = pq.getDOArray();
121      * for ( int i = 0; i < bobs.length; i++ ) {
122      * AddressQuery aq = new AddressQuery();
123      * aq.setQueryPerson( bobs[i] );
124      * AddressDO addr = aq.getNextDO();
125      * String city = addr.getCity();
126      * }
127      */

128     static public final RDBTable table = new RDBTable( "person" );
129
130     /**
131      * List of reference objects
132      */

133     private HashMap JavaDoc refs = null;
134
135
136     /**
137      * Name of the logical database for which DO object was created
138      */

139     protected String JavaDoc originDatabase = null;
140
141
142     /**
143      * Return the name of the logical database for which DO object was created.
144      *
145      * @deprecated Use get_OriginDatabase()
146      * @return origin logical database name.
147      *
148      */

149     public String JavaDoc getOriginDatabase() {
150         return get_OriginDatabase();
151     }
152
153     /**
154      * Return the name of the logical database for which DO object was created.
155      *
156      * @return origin logical database name.
157      *
158      */

159     public String JavaDoc get_OriginDatabase() {
160         return get_DataStruct().get_Database();
161     }
162
163     /**
164      * Return person as the name of the table in the database
165      * which contains PersonDO objects.
166      * This method overrides CoreDO.getTableName()
167      * and is used by CoreDO.executeUpdate() during error handling.
168      *
169      * @return The database table name.
170      *
171      * @see CoreDO
172      * @author Jay Gunter
173      */

174     public String JavaDoc getTableName() {
175         return "person";
176     }
177
178     /**
179      * static final RDBColumn PrimaryKey for use with QueryBuilder.
180      * See example above.
181      */

182     static public final RDBColumn PrimaryKey = new RDBColumn( table, get_primaryKeyName() );
183
184     /* RDBColumns for PersonDO attributes are defined below. */
185
186
187     /* Using a DO (and its Query class) to access a VIEW instead of a TABLE:
188      *
189      * A DO (and its Query class) can be used to access a VIEW
190      * instead of a TABLE. The Data Object is created as usual in DODS,
191      * but the "create table" SQL command for that DO is not used.
192      * Instead, you substitute a "create view" command to create a
193      * virtual table in the database; this is often done to provide
194      * convenient access to a collection of tables joined together.
195      *
196      * A VIEW usually does not return "oid" and "version" columns;
197      * often (but now always) a VIEW is defined to return the "oid" column
198      * for one of the tables joined together in the definition of the VIEW.
199      *
200      * If notUsingOId is true, PersonDO.createExisting(ResultSet)
201      * will NOT invoke the GenericDO(ResultSet) constructor
202      * so to avoid attempting to extract the "oid" and "version" columns
203      * from the ResultSet.
204      */

205     static protected final boolean notUsingOId = false;
206
207
208     /**
209      * A DO class contains a reference to a DataStruct class.
210      * This reference can be null (when the data for the DO
211      * has not yet been retrieved from the database),
212      * allowing a DO object to be a lightweight placeholder
213      * until its data is needed.
214      */

215     private PersonDataStruct data = null;
216
217     /**
218      * A DO class contains a reference to a DBTransaction class.
219      * This reference can be null (when the DO is created without
220      * transaction).
221      */

222     private DBTransaction transaction = null;
223
224     /**
225      * Return transaction which DO belongs.
226      *
227      * @return DBTransaction or null if not specified.
228      *
229      */

230     public DBTransaction get_transaction() {
231         return transaction;
232     }
233
234     /**
235      * Set Transaction to current DO.
236      *
237      * @param DBTransaction.
238      *
239      */

240     protected boolean setTransaction(DBTransaction trans) {
241         boolean isOK=false;
242         if (get_transaction() == null) {
243             transaction = trans;
244             isOK=true;
245         } else {
246         if(get_transaction().equals(trans))
247             isOK=true;
248         }
249         return isOK;
250     }
251
252
253     /**
254      * Return information whether the data for this object has been marked read-only.
255      *
256      * @return True if the data for this object has been marked read-only.
257      *
258      */

259     public boolean isReadOnly() {
260       return getConfigurationAdministration().getTableConfiguration().isReadOnly();
261      }
262
263     /**
264      * Sets DO's data.
265      * @deprecated Use set_Data()
266      */

267      public void setData (Object JavaDoc data) {
268         set_Data(data);
269      }
270
271     /**
272      * Sets DO's data.
273      */

274      public void set_Data (Object JavaDoc data) {
275         this.data = (PersonDataStruct)data;
276      }
277
278     /**
279      * Sets original DO's data.
280      */

281      public void originalData_set (Object JavaDoc data) {
282         originalData = (PersonDataStruct)data;
283      }
284
285     /**
286      * Returns DO's data.
287      * @deprecated Use get_Data()
288      */

289      public Object JavaDoc getData () {
290         return get_Data();
291      }
292
293     /**
294      * Returns DO's data.
295      */

296      public Object JavaDoc get_Data () {
297         return (null != data)? data : originalData;
298      }
299
300     /**
301      * Returns dataStruct.
302      * @deprecated Use get_DataStruct()
303      */

304     public PersonDataStruct getDataStruct () {
305         return get_DataStruct();
306     }
307
308     /**
309      * Returns dataStruct.
310      */

311     public PersonDataStruct get_DataStruct () {
312         return (PersonDataStruct) get_Data();
313     }
314
315     /**
316      * Returns original DO's data.
317      */

318      public Object JavaDoc originalData_get () {
319         return originalData;
320      }
321
322      public void checkDup () throws DatabaseManagerException, com.lutris.appserver.server.sql.ObjectIdException {
323          if (isDeletedFromDatabase)
324              throw new DatabaseManagerException("Object "+get_OId()+" is deleted");
325          if (null == data) {
326              data = ((PersonDataStruct)originalData).duplicate();
327          data.readOnly = false;
328          }
329      }
330
331     /**
332      * Protected constructor. Only derived classes should call it.
333      *
334      * @param is_view
335      *
336      * @exception DatabaseManagerException
337      * If a connection to the database cannot be established, etc.
338      * @exception com.lutris.appserver.server.sql.ObjectIdException
339      * If an object's id can't be allocated for this object.
340      */

341     protected PersonDO ( boolean is_view )
342     throws ObjectIdException, DatabaseManagerException {
343         super( is_view );
344         if(isTransactionCheck()) {
345             String JavaDoc trace="";
346             StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
347             for(int i=0; i < traceElements.length; i++)
348                trace+=traceElements[i].toString()+"\n";
349             DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created :"+(is_view?"":" Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version())+" \n"+trace);
350         }
351     }
352     /**
353      * Protected constructor. Only derived classes should call it.
354      *
355      * @param is_view
356      * @dbTrans Database transaction.
357      *
358      * @exception DatabaseManagerException
359      * If a connection to the database cannot be established, etc.
360      * @exception com.lutris.appserver.server.sql.ObjectIdException
361      * If an object's id can't be allocated for this object.
362      */

363     protected PersonDO ( boolean is_view, DBTransaction dbTrans )
364     throws ObjectIdException, DatabaseManagerException {
365         super( is_view );
366         setTransaction(dbTrans);
367         if(dbTrans!=null) {
368            originDatabase = dbTrans.getDatabaseName();
369         }
370         if(originDatabase==null)
371            originDatabase = get_logicalDBName();
372         get_DataStruct().set_Database(originDatabase);
373         addToTransactionCache();
374
375     }
376
377
378     /**
379      * Protected constructor. Only derived classes should call it.
380      *
381      * @exception DatabaseManagerException
382      * If a connection to the database cannot be established, etc.
383      * @exception com.lutris.appserver.server.sql.ObjectIdException
384      * If an object's id can't be allocated for this object.
385      */

386     protected PersonDO ()
387     throws ObjectIdException, DatabaseManagerException {
388         super( notUsingOId );
389         originDatabase = get_logicalDBName();
390         get_DataStruct().set_Database(originDatabase);
391         if(isTransactionCheck()) {
392             String JavaDoc trace="";
393             StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
394             for(int i=0; i < traceElements.length; i++)
395                trace+=traceElements[i].toString()+"\n";
396             DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created : Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
397         }
398         if (autoSaveAllowed&&isAutoSaveCreateVirgin()&&null != transaction) {
399             try {
400                 save(transaction,false);
401             } catch (Exception JavaDoc ex) {
402                 DODS.getLogChannel().write(Logger.DEBUG,"Faild to AutoSave virgin DO: "+get_OriginDatabase()+" PersonDO class\n");
403             }
404         }
405     }
406
407     /**
408      * Protected constructor. Only derived classes should call it.
409      * @param dbTrans The current database transaction.
410      * @exception DatabaseManagerException
411      * If a connection to the database cannot be established, etc.
412      * @exception com.lutris.appserver.server.sql.ObjectIdException
413      * If an object's id can't be allocated for this object.
414      */

415     protected PersonDO (DBTransaction dbTrans)
416     throws ObjectIdException, DatabaseManagerException {
417         super( notUsingOId );
418         setTransaction(dbTrans);
419         if(dbTrans!=null) {
420            originDatabase = dbTrans.getDatabaseName();
421         }
422         if(originDatabase==null)
423            originDatabase = get_logicalDBName();
424         get_DataStruct().set_Database(originDatabase);
425
426         addToTransactionCache();
427         if (autoSaveAllowed&&isAutoSaveCreateVirgin()&&null != transaction) {
428             try {
429                 save(transaction,false);
430             } catch (Exception JavaDoc ex) {
431                 DODS.getLogChannel().write(Logger.DEBUG,"Faild to AutoSave virgin DO: "+get_OriginDatabase()+" PersonDO class\n");
432             }
433         }
434     }
435
436
437
438     /**
439      * isLoaded()
440      * Returns information whether object's data is loaded from database.
441      * @return true if the data for this object has been retrieved
442      * from the database.
443      */

444     public boolean isLoaded() {
445         return (null != originalData)&&(!get_DataStruct().isEmpty);
446     }
447
448
449     /**
450      * Load the fields for the DO from the database.
451      *
452      * @exception com.lutris.appserver.server.sql.ObjectIdException
453      * If an object's id can't be allocated for this object.
454      * @exception DataObjectException
455      * If the object is not found in the database.
456      * @exception SQLException
457      * If the database rejects the SQL generated to retrieve data
458      * for this object, or if the table contains a bad foreign key, etc.
459      */

460     public void loadData()
461     throws SQLException, ObjectIdException, DataObjectException {
462         if (null == originalData&&!get_DataStruct().isEmpty) {
463             originalData = new PersonDataStruct ();
464         }
465
466         ObjectId id = get_OId();
467         if ( null == id )
468             return;
469         if ( ! isPersistent() ) // DO from createVirgin
470
return;
471         // DO from createExisting. Complain if no record in database.
472
PersonQuery query;
473
474                query = new PersonQuery (get_transaction());
475
476 // if(get_refs()!=null)
477
// {
478
query.setRefs(get_refs());
479 // }
480
query.setQueryOId( id );
481         query.requireUniqueInstance();
482         query.setLoadData(true);
483         PersonDO obj;
484         try {
485             obj = query.getNextDO();
486             if ( null == obj )
487                 throw new DataObjectException("PersonDO DO not found for id=" + id );
488             makeIdentical(obj);
489             set_Version( obj.get_Version() );
490             get_DataStruct().isEmpty = false;
491         } catch ( NonUniqueQueryException e ) {
492             throw new ObjectIdException( "Duplicate ObjectId" );
493         }
494
495     }
496
497     /**
498      * Load the actual DO data if necessary.
499      * Called by get/set methods.
500      *
501      * @exception DataObjectException If a data access error occurs.
502      */

503     protected void checkLoad()
504     throws DataObjectException {
505     if (null == originalData||get_DataStruct().isEmpty) {
506             try {
507                 loadData();
508             } catch ( Exception JavaDoc e ) {
509                 throw new DataObjectException("Unable to load data for PersonDO id=" + get_OId() +
510                                               ", error = ", e);
511             }
512     }
513     }
514
515
516     /**
517      * Protected constructor used by createExisting(ObjectId) above.
518      *
519      * @param id The ObjectId for the object.
520      *
521      * @exception DataObjectException
522      * If the object is not found in the database.
523      * @exception com.lutris.appserver.server.sql.ObjectIdException
524      * If an object's id can't be allocated for this object.
525      * @exception DatabaseManagerException
526      * If a connection to the database cannot be established, etc.
527      * @exception SQLException
528      * Should never see this exception since GenericDO.ctor(ObjectId)
529      * never accesses the database.
530      */

531     protected PersonDO( ObjectId id )
532     throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
533         super( id );
534         originDatabase = get_logicalDBName();
535         get_DataStruct().set_Database(originDatabase);
536         if(isTransactionCheck()) {
537             String JavaDoc trace="";
538             StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
539             for(int i=0; i < traceElements.length; i++)
540                trace+=traceElements[i].toString()+"\n";
541             DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created : Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
542         }
543
544     }
545
546     /**
547      * Protected constructor used by createExisting(ObjectId, DBTransaction) above.
548      *
549      * @param id The ObjectId for the object.
550      * @param dbTrans The current database transaction
551      * @exception DataObjectException
552      * If the object is not found in the database.
553      * @exception com.lutris.appserver.server.sql.ObjectIdException
554      * If an object's id can't be allocated for this object.
555      * @exception DatabaseManagerException
556      * If a connection to the database cannot be established, etc.
557      * @exception SQLException
558      * Should never see this exception since GenericDO.ctor(ObjectId)
559      * never accesses the database.
560      */

561     protected PersonDO( ObjectId id , DBTransaction dbTrans)
562     throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
563         super( id );
564         setTransaction(dbTrans);
565         if(dbTrans!=null) {
566            originDatabase = dbTrans.getDatabaseName();
567         }
568         if(originDatabase==null)
569            originDatabase = get_logicalDBName();
570         get_DataStruct().set_Database(originDatabase);
571         addToTransactionCache();
572     }
573
574
575
576
577     /**
578      * Represents table and cache (if there is caching) statistics.
579      */

580     protected static Statistics statistics;
581
582     /**
583      * Get table statistics.
584      *
585      * @return Table statistics.
586      */

587     public static Statistics get_statistics() {
588         statistics = cache.getStatistics();
589         return statistics;
590     }
591
592     /**
593      * Refresh table statistics.
594      */

595     public static void refreshStatistics() {
596        cache.refreshStatistics();
597     }
598
599
600     /**
601      * Get all used logical databases.
602      *
603      * @deprecated Use get_UsedLogicalDatabases()
604      * @return Array that contains names of all used logical databases.
605      *
606      */

607     public static String JavaDoc[] getUsedLogicalDatabases() {
608         return get_UsedLogicalDatabases();
609     }
610
611     /**
612      * Get all used logical databases.
613      *
614      * @return Array that contains names of all used logical databases.
615      *
616      */

617     public static String JavaDoc[] get_UsedLogicalDatabases() {
618         String JavaDoc[] str = { get_logicalDBName() };
619         return str;
620     }
621
622
623     protected static DataStructCache cache; // cache for PersonDO
624

625     /**
626      * Read cache configuration from application configuration file:
627      * cache size for phoneList.data.person table or default cache size.
628      */

629     public static void readCacheConfiguration(String JavaDoc database) throws CacheObjectException {
630         if (getConfigurationAdministration().isDisabled()) {
631             throw new CacheObjectException("Caching is disabled");
632         }
633         Config tableConfig = null;
634         Config cacheConfig = null;
635         try {
636             tableConfig = (Config)DODS.getDatabaseManager().getConfig().getSection("DB."+database+".person");
637         } catch (Exception JavaDoc ex) {
638         }
639         try {
640             cacheConfig = (Config)DODS.getDatabaseManager().getConfig().getSection("DB."+database+".person.cache");
641         } catch ( Exception JavaDoc e ) {
642         }
643         
644         cache.readConfiguration(tableConfig,cacheConfig, database);
645     }
646
647
648     /**
649      * Get name of the table that is cached.
650      *
651      * @return Name of the table that is cached.
652      */

653     public static String JavaDoc getCacheDodsTableName() {
654         return "person";
655     }
656
657
658     /**
659      * Returns person table cache.
660      *
661      * @return person table cache.
662      */

663     public static ConfigurationAdministration getConfigurationAdministration() {
664         return cache;
665     }
666
667     /**
668      * Queries all rows in table, and for each row
669      * creates a DO instance in the cache.
670      * For these DOs, data.readOnly = true,
671      * which causes set methods to throw an exception.
672      *
673      * @exception DataObjectException
674      * If the object is not found in the database.
675      * @exception com.lutris.appserver.server.sql.ObjectIdException
676      * If an object's id can't be allocated for this object.
677      * @exception DatabaseManagerException
678      * If a connection to the database cannot be established, etc.
679      * @exception SQLException
680      * If the database rejects the SQL generated to retrieve data
681      * for this object, or if the table contains a bad foreign key, etc.
682      */

683     public static void refreshCache()
684     throws java.sql.SQLException JavaDoc, DatabaseManagerException, ObjectIdException, DataObjectException {
685        getConfigurationAdministration().getCacheAdministration(CacheConstants.DATA_CACHE).refresh();
686         String JavaDoc querySnt = cache.getInitialQueryCache();
687         int maxSize = 0;
688         cache.checkFull();
689         if (querySnt != null) {
690             PersonQuery query;
691
692                 query = new PersonQuery ((DBTransaction)null);
693                 query.hitDatabase();
694                 maxSize = cache.getCacheAdministration(CacheConstants.DATA_CACHE).getMaxCacheSize();
695                 if (maxSize > 0)
696                     try {
697                         query.setMaxRows(maxSize);
698                     }
699                     catch (NonUniqueQueryException nuEx){
700                         System.out.println ("NonUniqueQueryException in refreshCache() method : too many rows were found.");
701                     }
702                 if (!querySnt.equals("*") ) {
703                     QueryBuilder builder = query.getQueryBuilder();
704                     builder.addWhere(querySnt);
705                 }
706                 PersonDO obj;
707                 try {
708                     query.setLoadData(true);
709                     query.getNextDO();
710                 } catch ( NonUniqueQueryException ex ) {
711                     // Since we do not call query.requireUniqueInstance()
712
// this should never happen.
713
throw new ObjectIdException( "Duplicate ObjectId" );
714                 }
715
716         }
717         cache.refreshStatistics();
718     }
719
720     private static boolean isDisabledCaching = false;
721
722     /**
723      * Disable caching
724      */

725     public static void disableCaching()
726     throws java.sql.SQLException JavaDoc, DatabaseManagerException, ObjectIdException, DataObjectException {
727         isDisabledCaching = true;
728         getConfigurationAdministration().getCacheAdministration(CacheConstants.DATA_CACHE).disable();
729     }
730
731     /**
732      * Enable caching
733      */

734     public static void enableCaching()
735     throws java.sql.SQLException JavaDoc, DatabaseManagerException, ObjectIdException, DataObjectException {
736         if (isDisabledCaching){
737             getConfigurationAdministration().getCacheAdministration(CacheConstants.DATA_CACHE).enable();
738             String JavaDoc querySnt = cache.getInitialQueryCache();
739             if (querySnt != null) {
740                 PersonQuery query;
741     
742                     query = new PersonQuery ((DBTransaction)null);
743                     query.hitDatabase();
744                     if (!querySnt.equals("*") ) {
745                         QueryBuilder builder = query.getQueryBuilder();
746                         builder.addWhere(querySnt);
747                     }
748                     PersonDO obj;
749                     try {
750                         query.getNextDO();
751                     } catch ( NonUniqueQueryException ex ) {
752                         // Since we do not call query.requireUniqueInstance()
753
// this should never happen.
754
throw new ObjectIdException( "Duplicate ObjectId" );
755                     }
756     
757             }
758         }
759     }
760     private static StandardDBTransaction _tr_(DBTransaction dbt) {
761     return (StandardDBTransaction)dbt;
762     }
763
764     /**
765      * Add DO to cache.
766      * If DO already exists in cache, just the data member is replaced,
767      * so that application references to the DO remain valid.
768      * If there is no caching newDO object is returned.
769      *
770      * param newDO Data object that will be added to cache.
771      *
772      * return Data object added to cache.
773      */

774     private PersonDO addToTransactionCache( PersonDO newDO ) {
775         PersonDO ret = null;
776         if(get_transaction()!=null && _tr_(get_transaction()).getTransactionCache()!=null) {
777             ret = (PersonDO)_tr_(get_transaction()).getTransactionCache().addDO(newDO);
778         }
779         if (ret == null)
780             return newDO;
781         return ret;
782     }
783
784     /**
785      * Add DataStruct object to cache.
786      * If there is no caching newDO object is returned.
787      *
788      * param newDS DataStruct object that will be added to cache.
789      *
790      * return DataStruct object added to cache.
791      */

792     public static synchronized PersonDataStruct addToCache( PersonDataStruct newDS ) {
793         PersonDataStruct ret = (PersonDataStruct)cache.addDataStruct(newDS);
794         if (ret == null)
795             return newDS;
796         return ret;
797     }
798
799     /**
800      * Add DO's original data object to cache.
801      */

802     public void addToCache() {
803         addToCache((PersonDataStruct)this.originalData_get());
804     }
805
806     /**
807      * Add DO to cache.
808      * If DO already exists in cache, just the data member is replaced,
809      * so that application references to the DO remain valid.
810      * This method overides method addToCache of the class CoreDO.
811      */

812     private void addToTransactionCache() {
813         addToTransactionCache(this);
814     }
815
816
817      /**
818      * UpdateCache for given DataStruct object
819      *
820      * @param data DataStruct object
821      */

822     public static synchronized PersonDataStruct updateCache( PersonDataStruct updDS) {
823         PersonDataStruct ret = (PersonDataStruct)cache.updateDataStruct(updDS);
824         if (ret == null)
825             return updDS;
826         return ret;
827     }
828
829     /**
830      * Update Cache
831      */

832     public void updateCache() {
833         updateCache((PersonDataStruct)this.originalData_get());
834     }
835
836     /**
837      * Delete DataStruct object from cache
838      *
839      * @param data DataStruct object for deleting
840      *
841      * @return Deleted DataStruct object
842      */

843     public static synchronized PersonDataStruct deleteFromCache( PersonDataStruct data ) {
844         cache.deleteDataStruct(data);
845         return data;
846     }
847
848
849     /**
850      * Remove DataStruct object from cache.
851      *
852      * @param dbName Logical name of the database from which
853      * PersonDataStruct object will be removed.
854      * @param handle Handle of DataStruct object which will be re moved.
855      */

856     public static synchronized void removeFromCache(String JavaDoc dbName, String JavaDoc handle) {
857         String JavaDoc cacheHandle = dbName+"."+handle;
858         cache.removeDataStruct( cacheHandle );
859     }
860
861     /**
862      * Delete object from cache
863      */

864     public void deleteFromCache() {
865         deleteFromCache((PersonDataStruct)this.originalData_get());
866     }
867
868
869     /**
870      * Remove DataStruct from cache.
871      *
872      * @param data DataStruct object which will be removed.
873      *
874      * @return Removed DataStruct object or null if DataStruct object doesn't
875      * exist in the cache.
876      */

877     public static synchronized PersonDataStruct removeFromCache( PersonDataStruct data ) {
878         return (PersonDataStruct)cache.removeDataStruct(data);
879     }
880
881     /**
882      * Remove DataStruct from cache.
883      */

884     public void evict() {
885         if (!isPersistent())
886             removeFromCache((PersonDataStruct)this.originalData_get());
887     }
888
889     /**
890      * Remove DataStruct objects from cache.
891      *
892      * @param DSs Array of DataStruct objects which will be removed from cache.
893      */

894     public static void evict(PersonDataStruct[] DSs) {
895         for (int i=0; i<DSs.length; i++)
896             removeFromCache((PersonDataStruct) DSs[i]);
897     }
898
899     /**
900      * Remove DataStruct objects from cache.
901      *
902      * @param dbName Logical name of the database from which
903      * PersonDataStruct object will be removed.
904      * @param handles array of DataStruct object handles that will be removed
905      * from cache.
906      */

907     public static void evict(String JavaDoc dbName, String JavaDoc[] handles) {
908         if (handles!=null) {
909             for (int i=0; i<handles.length; i++)
910                 removeFromCache(dbName, handles[i]);
911         }
912     }
913
914     /**
915      * The cache is used automatically by the class.
916      * Callers of the create() methods do not know whether
917      * the returned DO instance is shared or not.
918      * This prevents the existence of multiple instances in memory
919      * of the same database object.
920      * The cache is instantiated when the first DO instance is created.
921      */

922
923     /**
924      * Class that contains unchanging (static) data from the database
925      * will have a cache of DOs representing the entire contents of the table.
926      */

927     static {
928         try {
929             XMLConfig dodsConf = Common.getDodsConf();
930             String JavaDoc cacheClassPath = null;
931             String JavaDoc cacheClassName = null;
932             try {
933                 cacheClassPath = dodsConf.getText("CacheJar");
934                 cacheClassName = dodsConf.getText("CacheClassName");
935                 if (cacheClassPath != null && cacheClassName != null) {
936                     MultiClassLoader loader = new MultiClassLoader(null);
937                     loader.setClassPath(cacheClassPath);
938                     Class JavaDoc cacheClass = loader.loadClass(cacheClassName);
939                     cache = (DataStructCache)cacheClass.newInstance();
940                     cache = cache.newInstance();
941                 } else {
942                     cache = new QueryCacheImpl();
943                 }
944             } catch ( Exception JavaDoc e ) {
945             }
946             if (cache == null) {
947                 cache = new QueryCacheImpl();
948             }
949             readCacheConfiguration(get_logicalDBName());
950             get_statistics(); // set statistics
951
refreshCache();
952         } catch ( Exception JavaDoc e ) {
953             // cannot throw from static block
954
}
955     }
956
957     /**
958      * This method is invoked whenever object needs to be loaded from database.
959      *
960      * @exception DataObjectException If a data access error occurs.
961      */

962     public void refresh() throws DataObjectException {
963         try {
964             loadData();
965         } catch ( Exception JavaDoc e ) {
966             throw new DataObjectException("Unable to load data for PersonDO id=" + get_OId() +
967                                           ", error = ", e);
968         }
969     }
970
971     /**
972      * This method is invoked whenever objects needs to be loaded from database.
973      *
974      * @param DOs Array of DOs which will be red from database.
975      *
976      * @exception DataObjectException If a data access error occurs.
977      */

978     public static void refresh(PersonDO[] DOs) throws DataObjectException {
979         for (int i=0; i<DOs.length; i++)
980             DOs[i].refresh();
981     }
982
983
984     /**
985      * Refresh
986      *
987      * @exception QueryException If a data access error occurs.
988      */

989      public static void refresh(String JavaDoc querySnt) throws QueryException {
990          try {
991            QueryBuilder qb = new QueryBuilder();
992            qb.select( PersonDO.PrimaryKey);
993            qb.addWhere(querySnt);
994          BigDecimal objId;
995          String JavaDoc handle;
996          String JavaDoc database = get_logicalDBName();
997            RDBRow row;
998            try {
999                while ( null != ( row = qb.getNextRow() ) ) {
1000                    objId = row.get( PersonDO.PrimaryKey ).getBigDecimal();
1001                       handle = objId.toString();
1002                       removeFromCache(database, handle);
1003               }
1004           }catch ( Exception JavaDoc e ) {
1005               throw new QueryException(" Query Exception occured," );
1006           }
1007     }catch (Exception JavaDoc ex){
1008             System.out.println("Error in refresh(String) of DO object.");
1009        }
1010     }
1011
1012
1013    /**
1014     * createVirgin()
1015     * Creates a DO that has no ObjectId or data.
1016     * Such a DO is used to insert a new database entry
1017     * after its data has been set.
1018     *
1019     * @return Created data object.
1020     *
1021     * @exception com.lutris.appserver.server.sql.ObjectIdException
1022     * If an object's id can't be allocated for this object.
1023     * @exception DatabaseManagerException
1024     * If a connection to the database cannot be established, etc.
1025     *
1026
1027     */

1028    public static PersonDO createVirgin()
1029    throws DatabaseManagerException, ObjectIdException {
1030        return new PersonDO ();
1031    }
1032
1033    /**
1034     * createVirgin(DBTransaction)
1035     * @param dbTrans The current database transaction
1036     * @return Created data object.
1037     *
1038     * @exception com.lutris.appserver.server.sql.ObjectIdException
1039     * If an object's id can't be allocated for this object.
1040     * @exception DatabaseManagerException
1041     * If a connection to the database cannot be established, etc.
1042     */

1043    public static PersonDO createVirgin(DBTransaction dbTrans)
1044    throws DatabaseManagerException, ObjectIdException {
1045        return new PersonDO (dbTrans);
1046    }
1047
1048    /**
1049     * createExisting( BigDecimal )
1050     *
1051     * Factory method creates a PersonDO object by searching for it
1052     * in the database using the passed BigDecimal value as the primary key.
1053     *
1054     * Creates a DO that represents an existing entry in the database.
1055     * Such a DO is used to examine and possibly update such an entry.
1056     * createExisting() is called only from the code that retrieves
1057     * an ObjectId from a ResultSet (database query result).
1058     * createExisting() is protected because no other DO or BO should ever
1059     * need to call it.
1060     * FIX unfortunately the createExisting(BigDecimal) form *does* need
1061     * to be public because it is called by the public ctors of other DOs.
1062     * For example:
1063     * AaaDO contains a ref to a BbbDO,
1064     * so there is a method AaaDO.setBbb(BbbDO).
1065     * In the ctor AaaDO(ResultSet), we have the call
1066     * setBbb( BbbDO.createExisting( rs.getBigDecimal( "bbb")));
1067     * Since AaaDO is not in the same package as BbbDO,
1068     * BbbDO.createExisting(BigDecimal) must be public, not protected.
1069     * Java needs the C++ 'friend' idea.
1070     *
1071     * @param bd The BigDecimal representation of the ObjectId for the object.
1072     *
1073     * @return Created PersonDO object.
1074     *
1075     * @exception DataObjectException
1076     * If the object is not found in the database.
1077     * @exception com.lutris.appserver.server.sql.ObjectIdException
1078     * If an object's id can't be allocated for this object.
1079     * @exception DatabaseManagerException
1080     * If a connection to the database cannot be established, etc.
1081     * @exception SQLException
1082     * If the database rejects the SQL generated to retrieve data
1083     * for this object, or if the table contains a bad foreign key, etc.
1084
1085     */

1086    public static PersonDO createExisting( BigDecimal bd )
1087    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1088        if ( null == bd )
1089            return null;
1090        return createExisting( new ObjectId( bd ) );
1091    }
1092
1093
1094    /**
1095     * createExisting( BigDecimal, DBTransaction )
1096     *
1097     * @param bd The BigDecimal representation of the ObjectId for the object.
1098     *
1099     * @param dbTrans The current database transaction.
1100     *
1101     * @return Created PersonDO object.
1102     *
1103     * @exception DataObjectException
1104     * If the object is not found in the database.
1105     * @exception com.lutris.appserver.server.sql.ObjectIdException
1106     * If an object's id can't be allocated for this object.
1107     * @exception DatabaseManagerException
1108     * If a connection to the database cannot be established, etc.
1109     * @exception SQLException
1110     * If the database rejects the SQL generated to retrieve data
1111     * for this object, or if the table contains a bad foreign key, etc.
1112     */

1113    public static PersonDO createExisting( BigDecimal bd, DBTransaction dbTrans)
1114    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1115        if ( null == bd )
1116            return null;
1117        return createExisting( new ObjectId( bd ), dbTrans );
1118    }
1119
1120    /**
1121     * createExisting( BigDecimal, HashMap, DBTransaction )
1122     *
1123     * @param bd The BigDecimal representation of the ObjectId for the object.
1124     *
1125     * @param queryRefs HashMap Created referenced DO's (key datamaseName.Oid)
1126     *
1127     * @param dbTrans The current database transaction.
1128     *
1129     * @return Created PersonDO object.
1130     *
1131     * @exception DataObjectException
1132     * If the object is not found in the database.
1133     * @exception com.lutris.appserver.server.sql.ObjectIdException
1134     * If an object's id can't be allocated for this object.
1135     * @exception DatabaseManagerException
1136     * If a connection to the database cannot be established, etc.
1137     * @exception SQLException
1138     * If the database rejects the SQL generated to retrieve data
1139     * for this object, or if the table contains a bad foreign key, etc.
1140     */

1141    public static PersonDO createExisting( BigDecimal bd, HashMap JavaDoc queryRefs, DBTransaction dbTrans)
1142    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1143        if ( null == bd )
1144            return null;
1145        return createExisting( new ObjectId( bd ), queryRefs, dbTrans );
1146    }
1147
1148
1149    /**
1150     * createExisting( String )
1151     *
1152     * The createExisting method is used to create a <CODE>PersonDO</CODE>
1153     * from a string handle.
1154     *
1155     * @param handle String representation of the ObjectId for the object.
1156     *
1157     * @return Created PersonDO object.
1158
1159     */

1160    public static PersonDO createExisting( String JavaDoc handle ) {
1161        PersonDO ret = null;
1162        try {
1163            BigDecimal bd = new BigDecimal( handle );
1164            ret = createExisting( bd );
1165        } catch ( Exception JavaDoc e ) {
1166        }
1167        return ret;
1168    }
1169
1170
1171    /**
1172     * createExisting( String, DBTransaction )
1173     *
1174     * The createExisting method is used to create a <CODE>PersonDO</CODE>
1175     * from a string handle.
1176     *
1177     * @param handle String representation of the ObjectId for the object.
1178     * @param dbTrans The current database transaction
1179     * @return Created PersonDO object.
1180     */

1181    public static PersonDO createExisting( String JavaDoc handle, DBTransaction dbTrans ) {
1182        PersonDO ret = null;
1183        try {
1184            BigDecimal bd = new BigDecimal( handle );
1185            ret = createExisting( bd, dbTrans );
1186        } catch ( Exception JavaDoc e ) {
1187        }
1188        return ret;
1189    }
1190
1191
1192
1193    /**
1194     * createExisting( ObjectId , DBTransaction)
1195     *
1196     * Factory method creates a PersonDO object by searching for it
1197     * in the database using the passed ObjectID value as the primary key.
1198     *
1199     * @param id The ObjectId for the object.
1200     * @param dbTrans The current database transaction.
1201     * @return Created PersonDO object.
1202     *
1203     * @exception DataObjectException
1204     * If the object is not found in the database.
1205     * @exception com.lutris.appserver.server.sql.ObjectIdException
1206     * If an object's id can't be allocated for this object.
1207     * @exception DatabaseManagerException
1208     * If a connection to the database cannot be established, etc.
1209     * @exception SQLException
1210     * If the database rejects the SQL generated to retrieve data
1211     * for this object, or if the table contains a bad foreign key, etc.
1212     */

1213    protected static PersonDO createExisting( ObjectId id, DBTransaction dbTrans )
1214    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1215        if ( null == id )
1216            return null;
1217        return createExisting(id, null, dbTrans);
1218    }
1219
1220    /**
1221     * createExisting( ObjectId , HashMap queryRefs, DBTransaction)
1222     *
1223     * Factory method creates a PersonDO object by searching for it
1224     * in the database using the passed ObjectID value as the primary key.
1225     *
1226     * @param id The ObjectId for the object.
1227     * @param queryRefs HashMap of available references.
1228     * @param dbTrans The current database transaction.
1229     * @return Created PersonDO object.
1230     *
1231     * @exception DataObjectException
1232     * If the object is not found in the database.
1233     * @exception com.lutris.appserver.server.sql.ObjectIdException
1234     * If an object's id can't be allocated for this object.
1235     * @exception DatabaseManagerException
1236     * If a connection to the database cannot be established, etc.
1237     * @exception SQLException
1238     * If the database rejects the SQL generated to retrieve data
1239     * for this object, or if the table contains a bad foreign key, etc.
1240     */

1241    protected static PersonDO createExisting( ObjectId id, HashMap JavaDoc queryRefs, DBTransaction dbTrans )
1242    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1243        if ( null == id )
1244            return null;
1245        String JavaDoc cacheHandle = get_logicalDBName()+"."+id.toString();
1246        PersonDO ret = null;
1247        PersonDataStruct data = null;
1248        if(queryRefs==null)
1249            queryRefs = new HashMap JavaDoc();
1250        if(queryRefs.containsKey(cacheHandle)) {
1251            ret = (PersonDO)queryRefs.get(cacheHandle);
1252            return ret;
1253        }
1254        if(dbTrans!=null && _tr_(dbTrans).getTransactionCache()!= null) {
1255            ret = (PersonDO)_tr_(dbTrans).getTransactionCache().getDOByHandle( cacheHandle );
1256            if(ret != null)
1257                return ret;
1258        }
1259        if (null != ret)
1260            return ret;
1261        data = (PersonDataStruct)findCachedObjectByHandle( cacheHandle );
1262        if ( data != null ){
1263            ret = (PersonDO)createDO (data.get_OId(), dbTrans);
1264            if(ret!=null) {
1265                ret.originalData_set(data);
1266                ret.setPersistent(true);
1267            }
1268            return ret;
1269        }
1270// 14.XI if(dbTrans!=null)
1271
ret = new PersonDO( id , dbTrans);
1272// 14.XI else
1273
// 14.XI ret = new PersonDO( id );
1274
ret.setPersistent( true ); // mark DO as persistent (preexisting)
1275
/*14.XI
1276        if(queryRefs==null)
1277            queryRefs = new HashMap();
1278        if(queryRefs.containsKey(cacheHandle)) {
1279            ret = (PersonDO)queryRefs.get(cacheHandle);
1280            return ret;
1281        }
128214.XI */

1283        if(queryRefs!=null) {
1284            ret.set_refs(queryRefs);
1285            ret.addRefs(cacheHandle, ret);
1286        }
1287        if (!cache.getTableConfiguration().isLazyLoading()) { // If not lazy-loading, fetch DO data now.
1288
ret.loadData();
1289        } else {
1290            statistics.incrementLazyLoadingNum();
1291        }
1292        // unset the GenericDO.dirty flag.
1293
ret.markClean();
1294
1295        return ret;
1296    }
1297
1298
1299    /**
1300     * createExisting( ObjectId )
1301     *
1302     * Factory method creates a PersonDO object by searching for it
1303     * in the database using the passed ObjectID value as the primary key.
1304     *
1305     * @param id The ObjectId for the object.
1306     *
1307     * @return Created PersonDO object.
1308     *
1309     * @exception DataObjectException
1310     * If the object is not found in the database.
1311     * @exception com.lutris.appserver.server.sql.ObjectIdException
1312     * If an object's id can't be allocated for this object.
1313     * @exception DatabaseManagerException
1314     * If a connection to the database cannot be established, etc.
1315     * @exception SQLException
1316     * If the database rejects the SQL generated to retrieve data
1317     * for this object, or if the table contains a bad foreign key, etc.
1318
1319     */

1320    protected static PersonDO createExisting( ObjectId id )
1321    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1322        if ( null == id )
1323            return null;
1324        return createExisting(id, null);
1325    }
1326
1327    /**
1328     * createExisting( ResultSet )
1329     *
1330     * Factory method used to create an instance of this class to
1331     * represent a Data Object already existing in the database.
1332     *
1333     * @param rs The ResultSet returned by the Query class for
1334     * an existing Data Object stored in the database.
1335     *
1336     * @return Created PersonDO object.
1337     *
1338     * @exception DataObjectException
1339     * If the object is not found in the database.
1340     * @exception com.lutris.appserver.server.sql.ObjectIdException
1341     * If an object's id can't be allocated for this object.
1342     * @exception DatabaseManagerException
1343     * If a connection to the database cannot be established, etc.
1344     * @exception SQLException
1345     * If the database rejects the SQL generated to retrieve data
1346     * for this object, or if the table contains a bad foreign key, etc.
1347
1348     */

1349    protected static PersonDO createExisting( ResultSet rs )
1350    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1351        if ( null == rs )
1352            return null;
1353        PersonDO ret = null;
1354        if ( notUsingOId ) {
1355            ret = new PersonDO ();
1356            ret.initFromResultSet( rs );
1357        } else {
1358            ret = new PersonDO ( rs );
1359        }
1360        return ret;
1361    }
1362
1363
1364    /**
1365     * createExisting( ResultSet, DBTransaction )
1366     *
1367     * @param rs The ResultSet returned by the Query class for
1368     * an existing Data Object stored in the database.
1369     * @param dbTrans The current database transaction
1370     * @return Created PersonDO object.
1371     *
1372     * @exception DataObjectException
1373     * If the object is not found in the database.
1374     * @exception com.lutris.appserver.server.sql.ObjectIdException
1375     * If an object's id can't be allocated for this object.
1376     * @exception DatabaseManagerException
1377     * If a connection to the database cannot be established, etc.
1378     * @exception SQLException
1379     * If the database rejects the SQL generated to retrieve data
1380     * for this object, or if the table contains a bad foreign key, etc.
1381     */

1382    protected static PersonDO createExisting( ResultSet rs , DBTransaction dbTrans)
1383    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1384        if ( null == rs )
1385            return null;
1386        PersonDO ret = null;
1387        if ( notUsingOId ) {
1388            ret = new PersonDO (dbTrans);
1389            ret.initFromResultSet( rs );
1390        } else {
1391            ret = new PersonDO ( rs, dbTrans );
1392        }
1393        return ret;
1394    }
1395
1396
1397    /**
1398     * createExisting( ResultSet , HashMap)
1399     *
1400     * Factory method used to create an instance of this class to
1401     * represent a Data Object already existing in the database.
1402     *
1403     * @param rs The ResultSet returned by the Query class for
1404     * an existing Data Object stored in the database.
1405     * @param queryRefs list of created refernce objects.
1406     *
1407     * @return Created PersonDO object.
1408     *
1409     * @exception DataObjectException
1410     * If the object is not found in the database.
1411     * @exception com.lutris.appserver.server.sql.ObjectIdException
1412     * If an object's id can't be allocated for this object.
1413     * @exception DatabaseManagerException
1414     * If a connection to the database cannot be established, etc.
1415     * @exception SQLException
1416     * If the database rejects the SQL generated to retrieve data
1417     * for this object, or if the table contains a bad foreign key, etc.
1418
1419     */

1420    protected static PersonDO createExisting( ResultSet rs , HashMap JavaDoc queryRefs)
1421    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1422        if ( null == rs )
1423            return null;
1424        PersonDO ret = null;
1425        if ( notUsingOId ) {
1426            ret = new PersonDO ();
1427            ret.set_refs(queryRefs);
1428            ret.initFromResultSet( rs );
1429        } else {
1430            ret = new PersonDO ( rs, queryRefs );
1431        }
1432        return ret;
1433    }
1434
1435
1436    /**
1437     * createExisting( ResultSet , HashMap, DBTransaction)
1438     *
1439     * @param rs The ResultSet returned by the Query class for
1440     * an existing Data Object stored in the database.
1441     * @param queryRefs list of created refernce objects.
1442     * @param dbTrans The current database transaction
1443     * @return Created PersonDO object.
1444     *
1445     * @exception DataObjectException
1446     * If the object is not found in the database.
1447     * @exception com.lutris.appserver.server.sql.ObjectIdException
1448     * If an object's id can't be allocated for this object.
1449     * @exception DatabaseManagerException
1450     * If a connection to the database cannot be established, etc.
1451     * @exception SQLException
1452     * If the database rejects the SQL generated to retrieve data
1453     * for this object, or if the table contains a bad foreign key, etc.
1454     */

1455    protected static PersonDO createExisting( ResultSet rs , HashMap JavaDoc queryRefs, DBTransaction dbTrans)
1456    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1457        if ( null == rs )
1458            return null;
1459        PersonDO ret = null;
1460        if ( notUsingOId ) {
1461            ret = new PersonDO (dbTrans);
1462            ret.set_refs(queryRefs);
1463            ret.initFromResultSet( rs );
1464        } else {
1465            if(queryRefs==null)
1466                queryRefs = new HashMap JavaDoc();
1467            String JavaDoc cacheHandle = get_logicalDBName()+"."+rs.getBigDecimal(get_OIdColumnName());
1468            if(queryRefs.containsKey(cacheHandle)) {
1469                ret = (PersonDO)queryRefs.get(cacheHandle);
1470        if (!ret.isLoaded()) {
1471            ret.set_refs(queryRefs);
1472            ret.initFromResultSet(rs);
1473        }
1474                return ret;
1475            }
1476            ret = new PersonDO ( rs, queryRefs, dbTrans );
1477        }
1478        return ret;
1479    }
1480
1481
1482    /**
1483     * createExisting( RDBRow )
1484     *
1485     * Factory method creates a PersonDO object by searching for it
1486     * in the database using the PersonDO.PrimaryKey value
1487     * in the passed RDBRow.
1488     *
1489     * @param RDBRow A row returned by QueryBuilder.getNextRow().
1490     *
1491     * @return Created PersonDO object.
1492     *
1493     * @exception DataObjectException
1494     * If the RDBRow does not contain a PersonDO.PrimaryKey.
1495     * If the object is not found in the database.
1496     * @exception com.lutris.appserver.server.sql.ObjectIdException
1497     * If an object's id can't be allocated for this object.
1498     * @exception DatabaseManagerException
1499     * If a connection to the database cannot be established, etc.
1500     * @exception SQLException
1501     * If the database rejects the SQL generated to retrieve data
1502     * for this object, or if the table contains a bad foreign key, etc.
1503
1504     */

1505    protected static PersonDO createExisting( RDBRow row )
1506    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1507        if ( null == row )
1508            return null;
1509        RDBColumnValue pk = null;
1510        try {
1511            pk = row.get( PersonDO.PrimaryKey );
1512            return createExisting( pk );
1513        } catch ( Exception JavaDoc e ) {
1514            throw new DataObjectException("Cannot create PersonDO, row does not " +
1515                                          "contain PersonDO primary key." );
1516        }
1517    }
1518
1519
1520    /**
1521     * createExisting( RDBRow , DBTransaction)
1522     *
1523     * Factory method creates a PersonDO object by searching for it
1524     * in the database using the PersonDO.PrimaryKey value
1525     * in the passed RDBRow.
1526     *
1527     * @param RDBRow A row returned by QueryBuilder.getNextRow().
1528     * @param DBTransaction The current database transaction
1529     * @return Created PersonDO object.
1530     *
1531     * @exception DataObjectException
1532     * If the RDBRow does not contain a PersonDO.PrimaryKey.
1533     * If the object is not found in the database.
1534     * @exception com.lutris.appserver.server.sql.ObjectIdException
1535     * If an object's id can't be allocated for this object.
1536     * @exception DatabaseManagerException
1537     * If a connection to the database cannot be established, etc.
1538     * @exception SQLException
1539     * If the database rejects the SQL generated to retrieve data
1540     * for this object, or if the table contains a bad foreign key, etc.
1541     */

1542    protected static PersonDO createExisting( RDBRow row, DBTransaction dbTrans )
1543    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1544        if ( null == row )
1545            return null;
1546        RDBColumnValue pk = null;
1547        try {
1548            pk = row.get( PersonDO.PrimaryKey );
1549            return createExisting( pk, dbTrans );
1550        } catch ( Exception JavaDoc e ) {
1551            throw new DataObjectException("Cannot create PersonDO, row does not " +
1552                                          "contain PersonDO primary key." );
1553        }
1554    }
1555
1556
1557    /**
1558     * createExisting( RDBColumnValue )
1559     *
1560     * Factory method creates a PersonDO object by searching for it
1561     * in the database using the passed PersonDO.PrimaryKey.
1562     *
1563     * @param RDBColumnValue a PrimaryKey column value from a row
1564     * that was returned by QueryBuilder.getNextRow().
1565     *
1566     * @return Created PersonDO object.
1567     *
1568     * @exception DataObjectException
1569     * If the RDBColumnValue does not contain a PersonDO.PrimaryKey.
1570     * If the object is not found in the database.
1571     * @exception com.lutris.appserver.server.sql.ObjectIdException
1572     * If an object's id can't be allocated for this object.
1573     * @exception DatabaseManagerException
1574     * If a connection to the database cannot be established, etc.
1575     * @exception SQLException
1576     * If the database rejects the SQL generated to retrieve data
1577     * for this object, or if the table contains a bad foreign key, etc.
1578
1579     */

1580    protected static PersonDO createExisting( RDBColumnValue pk )
1581    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1582        if ( null == pk )
1583            return null;
1584        if ( ! pk.equals( PersonDO.PrimaryKey ) )
1585            throw new DataObjectException("Cannot create PersonDO, " +
1586                                          "RDBColumnValue is not PersonDO.PrimaryKey." );
1587        BigDecimal bd = null;
1588        try {
1589            bd = pk.getBigDecimal();
1590        } catch ( Exception JavaDoc e ) {
1591            throw new DataObjectException("Cannot create PersonDO, bad primary key." );
1592        }
1593        if ( null == bd )
1594            return null;
1595        return createExisting( bd );
1596    }
1597
1598
1599
1600    /**
1601     * createExisting( RDBColumnValue, DBTransaction )
1602     *
1603     * Factory method creates a PersonDO object by searching for it
1604     * in the database using the passed PersonDO.PrimaryKey.
1605     *
1606     * @param RDBColumnValue a PrimaryKey column value from a row
1607     * that was returned by QueryBuilder.getNextRow().
1608     *
1609     * @return Created PersonDO object.
1610     *
1611     * @exception DataObjectException
1612     * If the RDBColumnValue does not contain a PersonDO.PrimaryKey.
1613     * If the object is not found in the database.
1614     * @exception com.lutris.appserver.server.sql.ObjectIdException
1615     * If an object's id can't be allocated for this object.
1616     * @exception DatabaseManagerException
1617     * If a connection to the database cannot be established, etc.
1618     * @exception SQLException
1619     * If the database rejects the SQL generated to retrieve data
1620     * for this object, or if the table contains a bad foreign key, etc.
1621     */

1622    protected static PersonDO createExisting( RDBColumnValue pk, DBTransaction dbTrans )
1623    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
1624        if ( null == pk )
1625            return null;
1626        if ( ! pk.equals( PersonDO.PrimaryKey ) )
1627            throw new DataObjectException("Cannot create PersonDO, " +
1628                                          "RDBColumnValue is not PersonDO.PrimaryKey." );
1629        BigDecimal bd = null;
1630        try {
1631            bd = pk.getBigDecimal();
1632        } catch ( Exception JavaDoc e ) {
1633            throw new DataObjectException("Cannot create PersonDO, bad primary key." );
1634        }
1635        if ( null == bd )
1636            return null;
1637        return createExisting( bd , dbTrans);
1638    }
1639
1640
1641    /**
1642     * Creates a DO that has no ObjectId
1643     * but has a copy of an existing DO's data.
1644     * Such a DO is used to insert a new database entry
1645     * that is largely similar to an existing entry.
1646     *
1647     * @param data The data struct to copy values from.
1648     *
1649     * @return Created PersonDO object.
1650     *
1651     * @exception com.lutris.appserver.server.sql.ObjectIdException
1652     * If an object's id can't be allocated for this object.
1653     * @exception DatabaseManagerException
1654     * If a connection to the database cannot be established, etc.
1655
1656     */

1657    public static PersonDO createCopy( PersonDataStruct data )
1658    throws DatabaseManagerException, ObjectIdException {
1659        PersonDO ret = new PersonDO (true);
1660        ret.originalData_set(data);
1661        return ret;
1662    }
1663
1664    /**
1665     * Creates a DO that has no ObjectId
1666     * but has a copy of an existing DO's data.
1667     * Such a DO is used to insert a new database entry
1668     * that is largely similar to an existing entry.
1669     *
1670     * @param data The data struct to copy values from.
1671     * @param dbTrans The current database transaction
1672     * @return Created PersonDO object.
1673     *
1674     * @exception com.lutris.appserver.server.sql.ObjectIdException
1675     * If an object's id can't be allocated for this object.
1676     * @exception DatabaseManagerException
1677     * If a connection to the database cannot be established, etc.
1678     */

1679    public static PersonDO createCopy( PersonDataStruct data, DBTransaction dbTrans )
1680    throws DatabaseManagerException, ObjectIdException {
1681        PersonDO ret = new PersonDO (true, dbTrans);
1682        ret.originalData_set(data);
1683        ret.markClean();
1684        return ret;
1685    }
1686
1687
1688
1689    /**
1690     * Creates a DO that has no ObjectId
1691     * but has a copy of an existing DO's data.
1692     * Such a DO is used to insert a new database entry
1693     * that is largely similar to an existing entry.
1694     *
1695     * @param orig The original DO to copy.
1696     *
1697     * @return Created PersonDO object.
1698     *
1699     * @exception com.lutris.appserver.server.sql.ObjectIdException
1700     * If an object's id can't be allocated for this object.
1701     * @exception DatabaseManagerException
1702     * If a connection to the database cannot be established, etc.
1703     */

1704    public static PersonDO createCopy( PersonDO orig )
1705    throws DatabaseManagerException, ObjectIdException {
1706        if (null == orig)
1707            return null;
1708        PersonDO ret = new PersonDO (true);
1709        if (null != orig.originalData_get()) {
1710            ret.originalData_set(orig.originalData_get());
1711            ret.markClean();
1712            ret.transaction = orig.transaction;
1713            ret.setPersistent(orig.isPersistent());
1714        }
1715        return ret;
1716    }
1717
1718   /**
1719     *
1720     * @param orig The original DO to copy.
1721     * @param dbTrans The current database transaction
1722     * @return Created PersonDO object.
1723     *
1724     * @exception com.lutris.appserver.server.sql.ObjectIdException
1725     * If an object's id can't be allocated for this object.
1726     * @exception DatabaseManagerException
1727     * If a connection to the database cannot be established, etc.
1728     */

1729    public static PersonDO createCopy( PersonDO orig, DBTransaction dbTrans )
1730    throws DatabaseManagerException, ObjectIdException {
1731        if (null == orig)
1732            return null;
1733        PersonDO ret = new PersonDO (true, dbTrans);
1734        if (null != orig.originalData_get()) {
1735            ret.originalData_set(orig.originalData_get());
1736            ret.markClean();
1737            ret.setPersistent(orig.isPersistent());
1738        }
1739        return ret;
1740
1741    }
1742
1743
1744    /**
1745     * Causes the DO to refresh itself from the database
1746     * the next time a set or get method is called.
1747     */

1748    public void reload() {
1749        originalData = data = null;
1750    }
1751
1752    /**
1753     * The methods <CODE>
1754     * getHandle
1755     * hasMatchingHandle
1756
1757     * findCachedObjectByHandle
1758
1759     * </CODE> are used by Presentation Objects that need to populate
1760     * HTML select lists with Data Objects as options.
1761     * The <CODE>getHandle()</CODE> method is used
1762     * to set the value for each option,
1763     * and the <CODE>hasMatchingHandle()<CODE>
1764
1765     * methods are used to lookup the Data Object when the selection has
1766     * been made.
1767     *
1768     * @exception DatabaseManagerException
1769     * If a connection to the database cannot be established, etc.
1770     *
1771     * @return id of this DO as a string
1772     * If an object's id can't be allocated for this object.
1773     * @deprecated Use get_Handle() instead.
1774     */

1775    public String JavaDoc getHandle()
1776    throws DatabaseManagerException {
1777        return get_Handle();
1778    }
1779 
1780    
1781    /**
1782     * The methods <CODE>
1783     * get_Handle
1784     * hasMatchingHandle
1785
1786     * findCachedObjectByHandle
1787
1788     * </CODE> are used by Presentation Objects that need to populate
1789     * HTML select lists with Data Objects as options.
1790     * The <CODE>get_Handle()</CODE> method is used
1791     * to set the value for each option,
1792     * and the <CODE>hasMatchingHandle()<CODE>
1793
1794     * methods are used to lookup the Data Object when the selection has
1795     * been made.
1796     *
1797     * @exception DatabaseManagerException
1798     * If a connection to the database cannot be established, etc.
1799     *
1800     * @return id of this DO as a string
1801     * If an object's id can't be allocated for this object.
1802     */

1803    public String JavaDoc get_Handle()
1804    throws DatabaseManagerException {
1805        String JavaDoc ret = null;
1806        if ( null == get_OId() )
1807               throw new DatabaseManagerException( "ID not set " );
1808        ret = get_OId().toString();
1809        return ret;
1810    }
1811
1812    /**
1813     * Returns cache handle.
1814     *
1815     * @return cache handle.
1816     * @exception DatabaseManagerException
1817     * If a connection to the database cannot be established, etc.
1818     */

1819    public String JavaDoc get_CacheHandle()
1820    throws DatabaseManagerException {
1821        String JavaDoc ret = get_OriginDatabase() + "." + get_Handle();
1822        return ret;
1823    }
1824
1825    /**
1826     * Created DO with specified OID.
1827     *
1828     * @param obj DO which will be copied.
1829     * @return copy of DO (with the same id).
1830
1831     */

1832    public static GenericDO createDO(ObjectId oid) throws java.sql.SQLException JavaDoc, com.lutris.appserver.server.sql.ObjectIdException, com.lutris.dods.builder.generator.query.DataObjectException, com.lutris.appserver.server.sql.DatabaseManagerException{
1833        return new PersonDO(oid);
1834    }
1835
1836
1837    /**
1838     * Created DO with specified OID.
1839     *
1840     * @param obj DO which will be copied.
1841     * @param dbTrans The current database transaction.
1842     * @return copy of DO (with the same id).
1843     */

1844    public static GenericDO createDO(ObjectId oid, DBTransaction dbTrans) throws java.sql.SQLException JavaDoc, com.lutris.appserver.server.sql.ObjectIdException, com.lutris.dods.builder.generator.query.DataObjectException, com.lutris.appserver.server.sql.DatabaseManagerException{
1845        return new PersonDO(oid, dbTrans);
1846    }
1847
1848
1849   /**
1850     * Compare string version of the id of this DO and handle.
1851     *
1852     * @param handle
1853     * <CODE>String</CODE> version of DO id.
1854     *
1855     * @return boolean
1856     * True if the string version of the id of this DO matches passed handle.
1857     *
1858     * @see get_Handle
1859     */

1860    public boolean hasMatchingHandle( String JavaDoc handle ) {
1861        boolean ret = false;
1862        if ( null == get_OId() )
1863           return false;
1864        else {
1865           String JavaDoc thisHnadle = get_OId().toString();
1866           ret = thisHnadle.equals( handle );
1867        }
1868        return ret;
1869    }
1870
1871
1872   /**
1873     * Get data object with key cacheHandle from the cache.
1874     *
1875     * @param cacheHandle
1876     * <CODE>String</CODE> version of concatenation of:
1877     * name of the data object's database, followed by '.', followed by
1878     * data object's id.
1879     *
1880     * @return <CODE>PersonDO</CODE>
1881     * Object if one is found in cache, otherwise null.
1882     *
1883     * @see get_Handle
1884     */

1885    public PersonDO findTransactionCachedObjectByHandle( String JavaDoc cacheHandle ){
1886        if ( null == cacheHandle )
1887            return null;
1888        if(get_transaction()!=null && _tr_(get_transaction()).getTransactionCache()!= null)
1889            return (PersonDO)_tr_(get_transaction()).getTransactionCache().getDOByHandle( cacheHandle );
1890        else
1891            return null;
1892    }
1893
1894     /**
1895     * Get DataStruct object with key cacheHandle from the cache.
1896     *
1897     * @param cacheHandle
1898     * <CODE>String</CODE> version of concatenation of:
1899     * name of the data object's database, followed by '.', followed by
1900     * data object's id.
1901     *
1902     * @return <CODE>PersonDataStruct</CODE>
1903     * Object if one is found in cache, otherwise null.
1904     *
1905     * @see get_Handle
1906     */

1907    public static PersonDataStruct findCachedObjectByHandle( String JavaDoc cacheHandle ){
1908        if ( null == cacheHandle )
1909            return null;
1910        return ( PersonDataStruct ) cache.getDataStructByHandle( cacheHandle );
1911    }
1912
1913
1914
1915    /**
1916     * Assigns the DataStruct of an existing DO to this DO.
1917     * Does not duplicate data. Just assigns the reference.
1918     *
1919     * @param orig The original DO.
1920     *
1921     */

1922    protected void makeIdentical( PersonDO orig ) {
1923        super.makeIdentical(orig);
1924        originalData = orig.originalData;
1925        data = orig.data;
1926    }
1927
1928    /**
1929     * @deprecated Use get_Version()
1930     * @return Data object's version.
1931     */

1932    public int getVersion() {
1933        return get_Version();
1934    }
1935
1936    /**
1937     * get_Version makes the protected method public in CoreDO.
1938     *
1939     * @return Data object's version.
1940     */

1941    public int get_Version() {
1942        return (null != data)?data.get_Version():super.get_Version();
1943    }
1944
1945    /**
1946     * getNewVersion overloaded
1947     *
1948     * @return Data object's version.
1949     * @deprecated get_NewVersion()
1950     */

1951    public int getNewVersion() {
1952        if (null != data)
1953            return data.get_Version();
1954        else
1955            return super.get_Version();
1956    }
1957
1958    /**
1959     * get_NewVersion overloaded
1960     *
1961     * @return Data object's version.
1962     */

1963    public int get_NewVersion() {
1964        if (null != data)
1965            return data.get_Version();
1966        else
1967            return super.get_Version();
1968    }
1969
1970    /**
1971     * setVersion overloaded
1972     * @deprecated Use set_Version()
1973     */

1974    public void setVersion(int _ver) {
1975         set_Version(_ver);
1976    }
1977
1978    /**
1979     * set_Version overloaded
1980     *
1981     */

1982    public void set_Version(int _ver) {
1983        if(_ver < get_Version()) {
1984            new Throwable JavaDoc("WOW, ("+get_OId()+") oldVer:"+get_Version()+", new one is "+_ver).printStackTrace();
1985        } else if (null != data)
1986            data.set_Version(_ver);
1987        else
1988            super.set_Version(_ver);
1989    }
1990
1991    /**
1992     * setNewVersion overloaded
1993     * @deprecated
1994     */

1995    public void setNewVersion(int _ver){}
1996
1997    // WebDocWf extension for writeable fully cached objects
1998
/**
1999     * Mark the object as read-only.
2000     *
2001     * WebDocWf extension
2002     *
2003     */

2004    public void makeReadOnly() {
2005        if (null != data) {
2006          try{
2007            checkDup();
2008          }catch(Exception JavaDoc ex) {
2009            String JavaDoc trace="";
2010            StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
2011            for(int i=0; i < traceElements.length; i++)
2012               trace+=traceElements[i].toString()+"\n";
2013            DODS.getLogChannel().write(Logger.DEBUG, " MakeReadOnly failed: Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
2014          }
2015        }
2016         data.readOnly = true;
2017    }
2018
2019    /**
2020     * Mark the object as read-write.
2021     *
2022     * WebDocWf extension
2023     */

2024    public void makeReadWrite() {
2025        if (null != data) {
2026          try{
2027            checkDup();
2028          }catch(Exception JavaDoc ex) {
2029            String JavaDoc trace="";
2030            StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
2031            for(int i=0; i < traceElements.length; i++)
2032               trace+=traceElements[i].toString()+"\n";
2033            DODS.getLogChannel().write(Logger.DEBUG, " MakeReadWrite failed: Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
2034          }
2035        }
2036         data.readOnly = false;
2037    }
2038    // end of WebDocWf extension for writeable fully cached objects
2039

2040    // WebDocWf extension for writeable fully cached objects
2041

2042    /**
2043     * Set reference objects
2044     *
2045     */

2046    private void set_refs(HashMap JavaDoc queryRefs) {
2047        refs = queryRefs;
2048    }
2049
2050    private Object JavaDoc getRefs(String JavaDoc key) {
2051        if(get_transaction()!=null && _tr_(get_transaction()).getTransactionCache()!= null) {
2052            return _tr_(get_transaction()).getTransactionCache().getDOByHandle(key);
2053        } else if (null == refs) {
2054            refs = new HashMap JavaDoc();
2055            return null;
2056        } else {
2057            return refs.get(key);
2058        }
2059    }
2060
2061    private void addRefs(String JavaDoc key, Object JavaDoc newRefs) {
2062        if (null == refs) {
2063            refs = new HashMap JavaDoc();
2064        }
2065        refs.put(key, newRefs);
2066    }
2067
2068    /**
2069     * Get reference objects
2070     *
2071     */

2072    private HashMap JavaDoc get_refs() {
2073        return refs;
2074    }
2075
2076    /**
2077     * @deprecated Use get_OId()
2078     * @return this object's identifier.
2079     */

2080    public ObjectId getOId() {
2081    return get_OId();
2082    }
2083
2084    /**
2085     * Returns this object's identifier.
2086     * @return this object's identifier.
2087     */

2088    public ObjectId get_OId() {
2089    return get_DataStruct().get_OId();
2090    }
2091
2092    /**
2093     * @deprecated Use set_OId()
2094     * @param oId this object's identifier.
2095     */

2096    protected void setOId(ObjectId _oId) {
2097    set_OId(_oId);
2098    }
2099
2100    /**
2101     * Sets this object's identifier.
2102     * @param oId this object's identifier.
2103     */

2104    protected void set_OId(ObjectId _oId) {
2105        if (get_DataStruct() == null)
2106            originalData = new PersonDataStruct();
2107         get_DataStruct().set_OId(_oId);
2108    }
2109
2110    /**
2111     * Creates a clone of the object, but ensures that
2112     * a new and unique object id is created for the object
2113     * and that the version number is set to zero.
2114     * @exception DatabaseManagerException if an error occurs while
2115     * allocation a new object id from the default logical database.
2116     * @exception ObjectIdException if a new object id could not be
2117     * allocated.
2118     */

2119    public synchronized Object JavaDoc cloneUnique()
2120        throws DatabaseManagerException, ObjectIdException {
2121
2122    PersonDO _clone = createVirgin(get_transaction());
2123        
2124    try {
2125        PersonDataStruct toClone = (null != get_Data())
2126             ?(PersonDataStruct)get_Data()
2127             :(PersonDataStruct)originalData_get();
2128        if (null != toClone) {
2129        _clone.set_Data(toClone.duplicate());
2130        ((PersonDataStruct)_clone.get_Data()).set_OId(((PersonDataStruct)_clone.originalData_get()).get_OId());
2131        ((PersonDataStruct)_clone.get_Data()).set_Version(0);
2132                changedFlags_set(true);
2133            }
2134    } catch (Exception JavaDoc e) {
2135            String JavaDoc trace="";
2136            StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
2137            for(int i=0; i < traceElements.length; i++)
2138               trace+=traceElements[i].toString()+"\n";
2139            DODS.getLogChannel().write(Logger.DEBUG," cloneUnique failed: Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
2140    }
2141    return _clone;
2142    }
2143
2144    protected boolean deleted;
2145
2146    /**
2147     * @return true if DO has been deleted, but not commited yet
2148     */

2149    public boolean isDeleted() {
2150        return deleted;
2151    }
2152
2153    /**
2154     * @param flag true if DO has been deleted, but not commited yet
2155     */

2156    public void setDeleted(boolean flag) {
2157        deleted = flag;
2158    }
2159
2160
2161    /**
2162     * If transaction succeeded marks this object as clean.
2163     * @param success true if the transaction succeeded
2164     * and this object was successfully inserted into the database.
2165     */

2166    public void finalizeInsert(boolean success) {
2167    // on rollback reject inserted (createdVirgin) DO
2168
if (!success && !isPersistent())
2169        setDeleted(true);
2170        super.finalizeInsert(success);
2171        if (success)
2172            syncStructs(true);
2173    }
2174
2175    /**
2176     * If transaction succeeded marks this object as clean.
2177     * @param success true if the transaction succeeded
2178     * and this object was successfully updated in the database.
2179     */

2180    public void finalizeUpdate(boolean success) {
2181        super.finalizeUpdate(success);
2182        if (success)
2183            syncStructs(true);
2184    }
2185
2186    /**
2187     * Currently does nothing.
2188     *
2189     * @param success true if the transaction succeeded
2190     * and this object was successfully deleted from the
2191     * database.
2192     */

2193    public void finalizeDelete(boolean success) {
2194        super.finalizeDelete(success);
2195        if (success) {
2196            deleteFromCache();
2197        }
2198    }
2199
2200    /**
2201     *
2202     */

2203    private synchronized void syncStructs(boolean _updateCache) {
2204        if (null != data)
2205            originalData = data;
2206        data = null;
2207        changedFlags_set(false);
2208        ((PersonDataStruct)originalData).readOnly = true;
2209        if (_updateCache)
2210            updateCache();
2211    }
2212
2213    /**
2214     * @return true for DO that's created virgin and hasn't been commited yet.
2215     */

2216    public boolean isVirgin() {
2217    return !isPersistent();
2218    }
2219
2220    /**
2221     * Make DO's data from cache visible
2222     */

2223    public void makeVisible () {
2224        try {
2225            ((QueryCacheImpl)cache).makeVisible(get_CacheHandle());
2226        } catch (DatabaseManagerException dme) {
2227        System.err.println("makeVisible for "+super.toString()+"failed");
2228        }
2229    }
2230
2231    /**
2232     * Make DO's data from cache Invisible
2233     */

2234    public void makeInvisible () {
2235        try {
2236            ((QueryCacheImpl)cache).makeInvisible(get_CacheHandle());
2237        } catch (DatabaseManagerException dme) {
2238        System.err.println("makeInvisible for "+super.toString()+"failed");
2239        }
2240    }
2241
2242    /**
2243     * Inserts this object into the database.
2244     *
2245     * @param conn the database connection.
2246     * @exception java.sql.SQLException if a database access error occurs.
2247     * @exception DBRowUpdateException If a version error occurs.
2248     */

2249    public synchronized void executeInsert(DBConnection conn)
2250    throws SQLException, DBRowUpdateException {
2251    if (dirty) {
2252            super.executeInsert(conn);
2253            changedFlags_set(false);
2254    }
2255    }
2256
2257
2258    /**
2259     */

2260    protected boolean isAutoSave()
2261    {
2262      boolean flag = false;
2263      try {
2264        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(get_OriginDatabase()))).getDatabaseConfiguration().getAutoSave();
2265      } catch (Exception JavaDoc ex) {
2266      }
2267      return flag;
2268    }
2269
2270    /**
2271     */

2272    protected boolean isAutoSaveCreateVirgin()
2273    {
2274      boolean flag = false;
2275      try {
2276        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(get_OriginDatabase()))).getDatabaseConfiguration().getAutoSaveCreateVirgin();
2277      } catch (Exception JavaDoc ex) {
2278      }
2279      return flag;
2280    }
2281
2282    /**
2283     */

2284    protected boolean isTransactionCheck()
2285    {
2286      boolean flag = false;
2287      try {
2288        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(get_OriginDatabase()))).getDatabaseConfiguration().getTransactionCheck();
2289      } catch (Exception JavaDoc ex) {
2290      }
2291      return flag;
2292    }
2293
2294    /**
2295     */

2296    protected boolean isTransactionCaches()
2297    {
2298      boolean flag = false;
2299      try {
2300        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(get_OriginDatabase()))).getDatabaseConfiguration().getTransactionCaches();
2301      } catch (Exception JavaDoc ex) {
2302      }
2303      return flag;
2304    }
2305
2306    /**
2307     */

2308    protected boolean isDeleteCheckVersion()
2309    {
2310      boolean flag = false;
2311      try {
2312        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(this.get_OriginDatabase()))).getDatabaseConfiguration().getDeleteCheckVersion();
2313      } catch (Exception JavaDoc ex) {
2314      }
2315      return flag;
2316    }
2317
2318
2319    /**
2320     */

2321    protected static boolean isAllReadOnly()
2322    {
2323      boolean flag = false;
2324      try {
2325        flag = ((StandardLogicalDatabase)(DODS.getDatabaseManager().findLogicalDatabase(get_logicalDBName()))).getDatabaseConfiguration().isAllReadOnly();
2326      } catch (Exception JavaDoc ex) {
2327      }
2328      return flag;
2329    }
2330
2331
2332
2333     /**
2334     *
2335     */

2336    public void undo()throws com.lutris.dods.builder.generator.query.DataObjectException
2337    {
2338      try{
2339        if(null != transaction){
2340            if((data!=null) || (data==null && isDeleted())){
2341                int tempVersion=get_Version();
2342                if(isDeleted() && !isDeletedFromDatabase){
2343                        unDelete(transaction);
2344                }else if (isDeleted() && isDeletedFromDatabase){
2345                    data =((PersonDataStruct)originalData).duplicate();
2346                    set_Version(tempVersion);
2347                    persistent=false;
2348                    deleted=false;
2349                    isDeletedFromDatabase=false;
2350                    if (isAutoSave()) {
2351                        save(transaction,false);
2352                    }
2353                }else{
2354                    data =((PersonDataStruct)originalData).duplicate();
2355                    set_Version(tempVersion);
2356                    if ( isAutoSave()) {
2357                        save(transaction,false);
2358                    }
2359                }
2360            }
2361        }else{
2362            throw new DataObjectException("Error during Undo operation");
2363        }
2364      }catch(Exception JavaDoc ex){
2365        throw new DataObjectException("Error during Undo operation");
2366      }
2367
2368    }
2369
2370
2371
2372
2373
2374
2375    ////////////////////////// data member FirstName
2376

2377    /**
2378     * static final RDBColumn FirstName for use with QueryBuilder.
2379     * See RDBColumn PrimaryKey at the top of this file for usage example.
2380     */

2381    static public final RDBColumn FirstName = new RDBColumn( table, "firstName", true);
2382
2383    private boolean changedFirstName = false;
2384
2385    /**
2386     * Use for query caching.
2387     */

2388    static public final int COLUMN_FIRSTNAME = 0;
2389    static public final int firstName_MaxLength = 32;
2390
2391    /**
2392     * Get firstName of the person.
2393     *
2394     * @return firstName of the person.
2395     *
2396     * @exception DataObjectException
2397     * If the object is not found in the database.
2398     */

2399    public String JavaDoc getFirstName ()
2400    throws DataObjectException {
2401        checkLoad();
2402        
2403        return get_DataStruct().getFirstName();
2404    }
2405
2406
2407    /**
2408     * Get original firstName of the person.
2409     *
2410     * @return firstName of the person.
2411     *
2412     * @exception DataObjectException
2413     * If the object is not found in the database.
2414     */

2415    public String JavaDoc originalData_getFirstName ()
2416    throws DataObjectException {
2417        checkLoad();
2418        return ((PersonDataStruct)originalData_get()).getFirstName();
2419    }
2420
2421
2422
2423    /**
2424     * Set firstName of the person.
2425     *
2426     * @param firstName of the person.
2427     *
2428     * @exception DataObjectException
2429     * If the object is not found in the database.
2430     */

2431    public void setFirstName ( String JavaDoc firstName )
2432    throws DataObjectException {
2433        _setFirstName ( firstName );
2434    }
2435    
2436    /**
2437     * _setFirstName is a protected method that is called by
2438     * setFirstName if firstName is not part of
2439     * a multicolumn foreign key.
2440     *
2441     * @param firstName of the person.
2442     *
2443     * @exception DataObjectException
2444     * If the object is not found in the database.
2445     */

2446    protected void _setFirstName ( String JavaDoc firstName )
2447    throws DataObjectException {
2448        checkLoad();
2449        
2450        try {
2451            checkDup();
2452        } catch (Exception JavaDoc e) {
2453            throw new DataObjectException ("Coudn't duplicate DataStruct:", e);
2454        }
2455        if (data.isEmpty)
2456            data.isEmpty = false;
2457        data.setFirstName(markNewValue(get_DataStruct().getFirstName(), firstName, 0, firstName_MaxLength, false));
2458        changedFirstName = colChanged;
2459        if (changedFirstName) {
2460            if (autoSaveAllowed&&isAutoSave()&&null != transaction) {
2461                try {
2462                    save(transaction,false);
2463                } catch (Exception JavaDoc ex) {
2464                    throw new DataObjectException("Error during transaction's writting data into database",ex);
2465                }
2466            }
2467        }
2468    }
2469
2470
2471
2472
2473    ////////////////////////// data member LastName
2474

2475    /**
2476     * static final RDBColumn LastName for use with QueryBuilder.
2477     * See RDBColumn PrimaryKey at the top of this file for usage example.
2478     */

2479    static public final RDBColumn LastName = new RDBColumn( table, "lastName", true);
2480
2481    private boolean changedLastName = false;
2482
2483    /**
2484     * Use for query caching.
2485     */

2486    static public final int COLUMN_LASTNAME = 1;
2487    static public final int lastName_MaxLength = 32;
2488
2489    /**
2490     * Get lastName of the person.
2491     *
2492     * @return lastName of the person.
2493     *
2494     * @exception DataObjectException
2495     * If the object is not found in the database.
2496     */

2497    public String JavaDoc getLastName ()
2498    throws DataObjectException {
2499        checkLoad();
2500        
2501        return get_DataStruct().getLastName();
2502    }
2503
2504
2505    /**
2506     * Get original lastName of the person.
2507     *
2508     * @return lastName of the person.
2509     *
2510     * @exception DataObjectException
2511     * If the object is not found in the database.
2512     */

2513    public String JavaDoc originalData_getLastName ()
2514    throws DataObjectException {
2515        checkLoad();
2516        return ((PersonDataStruct)originalData_get()).getLastName();
2517    }
2518
2519
2520
2521    /**
2522     * Set lastName of the person.
2523     *
2524     * @param lastName of the person.
2525     *
2526     * @exception DataObjectException
2527     * If the object is not found in the database.
2528     */

2529    public void setLastName ( String JavaDoc lastName )
2530    throws DataObjectException {
2531        _setLastName ( lastName );
2532    }
2533    
2534    /**
2535     * _setLastName is a protected method that is called by
2536     * setLastName if lastName is not part of
2537     * a multicolumn foreign key.
2538     *
2539     * @param lastName of the person.
2540     *
2541     * @exception DataObjectException
2542     * If the object is not found in the database.
2543     */

2544    protected void _setLastName ( String JavaDoc lastName )
2545    throws DataObjectException {
2546        checkLoad();
2547        
2548        try {
2549            checkDup();
2550        } catch (Exception JavaDoc e) {
2551            throw new DataObjectException ("Coudn't duplicate DataStruct:", e);
2552        }
2553        if (data.isEmpty)
2554            data.isEmpty = false;
2555        data.setLastName(markNewValue(get_DataStruct().getLastName(), lastName, 0, lastName_MaxLength, false));
2556        changedLastName = colChanged;
2557        if (changedLastName) {
2558            if (autoSaveAllowed&&isAutoSave()&&null != transaction) {
2559                try {
2560                    save(transaction,false);
2561                } catch (Exception JavaDoc ex) {
2562                    throw new DataObjectException("Error during transaction's writting data into database",ex);
2563                }
2564            }
2565        }
2566    }
2567
2568
2569
2570
2571    ////////////////////////// data member PhoneNumber
2572

2573    /**
2574     * static final RDBColumn PhoneNumber for use with QueryBuilder.
2575     * See RDBColumn PrimaryKey at the top of this file for usage example.
2576     */

2577    static public final RDBColumn PhoneNumber = new RDBColumn( table, "phoneNumber", true);
2578
2579    private boolean changedPhoneNumber = false;
2580
2581    /**
2582     * Use for query caching.
2583     */

2584    static public final int COLUMN_PHONENUMBER = 2;
2585    static public final int phoneNumber_MaxLength = 32;
2586
2587    /**
2588     * Get phoneNumber of the person.
2589     *
2590     * @return phoneNumber of the person.
2591     *
2592     * @exception DataObjectException
2593     * If the object is not found in the database.
2594     */

2595    public String JavaDoc getPhoneNumber ()
2596    throws DataObjectException {
2597        checkLoad();
2598        
2599        return get_DataStruct().getPhoneNumber();
2600    }
2601
2602
2603    /**
2604     * Get original phoneNumber of the person.
2605     *
2606     * @return phoneNumber of the person.
2607     *
2608     * @exception DataObjectException
2609     * If the object is not found in the database.
2610     */

2611    public String JavaDoc originalData_getPhoneNumber ()
2612    throws DataObjectException {
2613        checkLoad();
2614        return ((PersonDataStruct)originalData_get()).getPhoneNumber();
2615    }
2616
2617
2618
2619    /**
2620     * Set phoneNumber of the person.
2621     *
2622     * @param phoneNumber of the person.
2623     *
2624     * @exception DataObjectException
2625     * If the object is not found in the database.
2626     */

2627    public void setPhoneNumber ( String JavaDoc phoneNumber )
2628    throws DataObjectException {
2629        _setPhoneNumber ( phoneNumber );
2630    }
2631    
2632    /**
2633     * _setPhoneNumber is a protected method that is called by
2634     * setPhoneNumber if phoneNumber is not part of
2635     * a multicolumn foreign key.
2636     *
2637     * @param phoneNumber of the person.
2638     *
2639     * @exception DataObjectException
2640     * If the object is not found in the database.
2641     */

2642    protected void _setPhoneNumber ( String JavaDoc phoneNumber )
2643    throws DataObjectException {
2644        checkLoad();
2645        
2646        try {
2647            checkDup();
2648        } catch (Exception JavaDoc e) {
2649            throw new DataObjectException ("Coudn't duplicate DataStruct:", e);
2650        }
2651        if (data.isEmpty)
2652            data.isEmpty = false;
2653        data.setPhoneNumber(markNewValue(get_DataStruct().getPhoneNumber(), phoneNumber, 0, phoneNumber_MaxLength, false));
2654        changedPhoneNumber = colChanged;
2655        if (changedPhoneNumber) {
2656            if (autoSaveAllowed&&isAutoSave()&&null != transaction) {
2657                try {
2658                    save(transaction,false);
2659                } catch (Exception JavaDoc ex) {
2660                    throw new DataObjectException("Error during transaction's writting data into database",ex);
2661                }
2662            }
2663        }
2664    }
2665
2666
2667
2668    /**
2669     * Compares whether this DO satisfies condition cond.
2670     *
2671     * @param cond condition.
2672     *
2673     * @return true if DO satisfies condition cond, otherwise false.
2674     */

2675    public boolean compareCond(Condition cond) {
2676        try {
2677            switch(cond.getColumnIndex()) {
2678        case COLUMN_FIRSTNAME:
2679                    return QueryBuilder.compare(getFirstName(),cond.getValue(),cond.getOperator());
2680        case COLUMN_LASTNAME:
2681                    return QueryBuilder.compare(getLastName(),cond.getValue(),cond.getOperator());
2682        case COLUMN_PHONENUMBER:
2683                    return QueryBuilder.compare(getPhoneNumber(),cond.getValue(),cond.getOperator());
2684            }
2685        } catch (Exception JavaDoc e) {
2686        }
2687        return false;
2688    }
2689
2690    static {
2691    }
2692
2693    /**
2694     * logicalDbName is logical database name
2695     * set by setLogicalDBName()
2696     * and retrieved by get_logicalDBName().
2697     */

2698    static private String JavaDoc logicalDbName = null;
2699
2700    /**
2701     * setLogicalDBName sets the logical database name that will be used
2702     * to create DBTransaction and DBQuery objects used by
2703     * PersonDO and the corresponding Query class.
2704     *
2705     * @param logicalDbNameInConfFile The logical database specified in the
2706     * application's .conf file.
2707     *
2708     * @deprecated It is dangeruous to use this method in multiuser environment because,
2709     * this setings are applied to all users (sets logical database to all users)
2710     */

2711    static public synchronized void setLogicalDBName( String JavaDoc logicalDbNameInConfFile ) {
2712        if ( null != logicalDbNameInConfFile && 0 != logicalDbNameInConfFile.length() )
2713            logicalDbName = logicalDbNameInConfFile;
2714        else
2715            logicalDbName = DODS.getDatabaseManager().getDefaultDB();
2716    }
2717    
2718    /**
2719     * get_logicalDBName retrieves the logical database name
2720     * set by setLogicalDBName().
2721     *
2722     * @return the logical database name that was set by method setLogicalDBName()
2723     *
2724     */

2725    static public synchronized String JavaDoc get_logicalDBName() {
2726        if (logicalDbName == null)
2727            logicalDbName = DODS.getDatabaseManager().getDefaultDB();
2728        return logicalDbName;
2729    }
2730
2731    /**
2732     * createTransaction() creates a new DBTransaction.
2733     * This method uses the logical database name set by method setLogicalDBName().
2734     *
2735     * If setLogicalDBName() was used to set the logical database name
2736     * to something other than the value of DatabaseManager.DefaultDatabase
2737     * in the application's .conf file, then any DBTransaction passed to
2738     * save(DBTransaction) or delete(DBTransaction) should be created using
2739     * PersonDO.createTransaction().
2740     *
2741     * The PersonDO save() and delete() methods use this method.
2742     *
2743     * @return A DBTransaction object to use with the PersonDO class.
2744     */

2745    static public DBTransaction createTransaction()
2746    throws DatabaseManagerException, SQLException {
2747        DBTransaction ret;
2748        try {
2749            ret = DODS.getDatabaseManager().createTransaction(get_logicalDBName());
2750            ret.setDatabaseName(get_logicalDBName());
2751            return ret;
2752        } catch ( DatabaseManagerException e ) {
2753            String JavaDoc err = "";
2754            if ( null != get_logicalDBName() )
2755                err = "ERROR: Could not create a DBTransaction. " +
2756                      "PersonDO.logicalDbName='" + get_logicalDBName() + "'. "+
2757                      "The application .conf file must list this name in " +
2758                      "DatabaseManager.Databases[], and there must be " +
2759                      "DatabaseManager.DB." + get_logicalDBName() + " settings.";
2760            throw new DatabaseManagerException( err, e );
2761        }
2762    }
2763    
2764
2765    /**
2766     * createQuery() creates a new DBQuery.
2767     * This method uses the logical database name set by method setLogicalDBName().
2768     *
2769     * If setLogicalDBName() was used to set the logical database name
2770     * to something other than the value of DatabaseManager.DefaultDatabase
2771     * in the application's .conf file, then any DBQuery object used to
2772     * access the 'person' table should be created using
2773     * PersonDO.createQuery().
2774     *
2775     * The Query class corresponding to PersonDO uses this method.
2776     *
2777     * @return A DBQuery object to use in accessing the 'person' table.
2778          
2779     */

2780    static public DBQuery createQuery()
2781    throws DatabaseManagerException, SQLException {
2782        try {
2783        return DODS.getDatabaseManager().createQuery(get_logicalDBName());
2784        } catch ( DatabaseManagerException e ) {
2785            String JavaDoc err = "";
2786            if ( null != get_logicalDBName() )
2787                err = "ERROR: Could not create a DBQuery. " +
2788                      "PersonDO.logicalDBName='" + get_logicalDBName() + "'. "+
2789                      "The application .conf file must list this name in " +
2790                      "DatabaseManager.Databases[], and there must be " +
2791                      "DatabaseManager.DB." + get_logicalDBName() + " settings.";
2792            throw new DatabaseManagerException( err, e );
2793        }
2794    }
2795
2796
2797    /**
2798     * createQuery() creates a new DBQuery.
2799     * This method uses the logical database name set by method setLogicalDBName().
2800     *
2801     * If setLogicalDBName() was used to set the logical database name
2802     * to something other than the value of DatabaseManager.DefaultDatabase
2803     * in the application's .conf file, then any DBQuery object used to
2804     * access the 'person' table should be created using
2805     * PersonDO.createQuery().
2806     *
2807     * The Query class corresponding to PersonDO uses this method.
2808     *
2809     * @return A DBQuery object to use in accessing the 'person' table.
2810     */

2811    static public DBQuery createQuery(DBTransaction trans)
2812    throws DatabaseManagerException, SQLException {
2813
2814        try {
2815        return (null==trans)?createQuery():trans.createQuery();
2816        } catch ( DatabaseManagerException e ) {
2817            String JavaDoc err = "";
2818            if ( null != get_logicalDBName() )
2819                err = "ERROR: Could not create a DBQuery. " +
2820                      "PersonDO.logicalDBName='" + get_logicalDBName() + "'. "+
2821                      "The application .conf file must list this name in " +
2822                      "DatabaseManager.Databases[], and there must be " +
2823                      "DatabaseManager.DB." + get_logicalDBName() + " settings.";
2824            throw new DatabaseManagerException( err, e );
2825        }
2826    }
2827
2828
2829    /**
2830     * Protected constructor.
2831     *
2832     * @param rs Result set from which to obtain product data.
2833     *
2834     * @exception DataObjectException
2835     * If the object is not found in the database.
2836     * @exception com.lutris.appserver.server.sql.ObjectIdException
2837     * If an object's id can't be allocated for this object.
2838     * @exception DatabaseManagerException
2839     * If a connection to the database cannot be established, etc.
2840     * @exception SQLException
2841     * If the database rejects the SQL generated to retrieve data
2842     * for this object, or if the table contains a bad foreign key, etc.
2843     */

2844    protected PersonDO(ResultSet rs)
2845    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
2846        super(rs);
2847        initFromResultSet( rs );
2848        originDatabase = get_logicalDBName();
2849        get_DataStruct().set_Database(originDatabase);
2850        set_OId(new ObjectId(rs.getBigDecimal(get_OIdColumnName())));
2851        if ( versioning )
2852            set_Version(rs.getInt(get_versionColumnName()));
2853        if(isTransactionCheck()) {
2854            String JavaDoc trace="";
2855            StackTraceElement JavaDoc[] traceElements= (new Throwable JavaDoc()).getStackTrace();
2856            for(int i=0; i < traceElements.length; i++)
2857               trace+=traceElements[i].toString()+"\n";
2858            DODS.getLogChannel().write(Logger.WARNING, "DO without transaction context is created : Database: "+get_OriginDatabase()+" PersonDO class, oid: "+get_OId()+", version: "+get_Version()+" \n"+trace);
2859        }
2860    }
2861
2862    /**
2863     * Protected constructor.
2864     *
2865     * @param rs Result set from which to obtain product data.
2866     *
2867     * @exception DataObjectException
2868     * If the object is not found in the database.
2869     * @exception com.lutris.appserver.server.sql.ObjectIdException
2870     * If an object's id can't be allocated for this object.
2871     * @exception DatabaseManagerException
2872     * If a connection to the database cannot be established, etc.
2873     * @exception SQLException
2874     * If the database rejects the SQL generated to retrieve data
2875     * for this object, or if the table contains a bad foreign key, etc.
2876     */

2877    protected PersonDO(ResultSet rs, HashMap JavaDoc queryRefs)
2878    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
2879        this(rs,queryRefs,null);
2880    }
2881
2882    /**
2883     * Protected constructor.
2884     *
2885     * @param rs Result set from which to obtain product data.
2886     *
2887     * @exception DataObjectException
2888     * If the object is not found in the database.
2889     * @exception com.lutris.appserver.server.sql.ObjectIdException
2890     * If an object's id can't be allocated for this object.
2891     * @exception DatabaseManagerException
2892     * If a connection to the database cannot be established, etc.
2893     * @exception SQLException
2894     * If the database rejects the SQL generated to retrieve data
2895     * for this object, or if the table contains a bad foreign key, etc.
2896     */

2897    protected PersonDO(ResultSet rs, HashMap JavaDoc queryRefs, DBTransaction dbTrans)
2898    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
2899        super(rs);
2900        set_refs(queryRefs);
2901    setTransaction(dbTrans);
2902        initFromResultSet( rs );
2903        if(dbTrans!=null)
2904            originDatabase = dbTrans.getDatabaseName();
2905        if(originDatabase==null)
2906           originDatabase = get_logicalDBName();
2907        get_DataStruct().set_Database(originDatabase);
2908        addToTransactionCache();
2909        if(dbTrans!=null)
2910            dbTrans.lockDO(this);
2911    }
2912
2913    /**
2914     * Protected constructor.
2915     *
2916     * @param rs Result set from which to obtain product data.
2917     * @param dbTrans The current database transaction
2918     * @exception DataObjectException
2919     * If the object is not found in the database.
2920     * @exception com.lutris.appserver.server.sql.ObjectIdException
2921     * If an object's id can't be allocated for this object.
2922     * @exception DatabaseManagerException
2923     * If a connection to the database cannot be established, etc.
2924     * @exception SQLException
2925     * If the database rejects the SQL generated to retrieve data
2926     * for this object, or if the table contains a bad foreign key, etc.
2927     */

2928    protected PersonDO(ResultSet rs, DBTransaction dbTrans)
2929    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
2930        this(rs, null, dbTrans);
2931    }
2932    
2933    
2934
2935
2936
2937    /**
2938     * while in initFromResultSet, auto save can't be allowed
2939     */

2940    private boolean autoSaveAllowed = true;
2941
2942    /**
2943     * initFromResultSet initializes the data members of person.
2944     * This code was separated from the ResultSet constructor
2945     * so that createExisting(ResultSet) could handle VIEWs.
2946     *
2947     * @param rs ResultSet from which data members are initialized.
2948     */

2949    private void initFromResultSet( ResultSet rs )
2950    throws SQLException, ObjectIdException, DataObjectException, DatabaseManagerException {
2951        autoSaveAllowed = false;
2952        // Constructing a DO from a ResultSet means we definitely need the
2953
// DataStruct ready for the setXxx methods invoked below.
2954
if (null == get_DataStruct())
2955            originalData = new PersonDataStruct ();
2956    get_DataStruct().isEmpty = false;
2957        // writeMemberStuff uses the ResultSetExtraction.template
2958
// to build up the value for this tag:
2959
// the value is a series of calls to the DO set methods.
2960

2961             setFirstName( rs.getString( "firstName" ) );
2962
2963             setLastName( rs.getString( "lastName" ) );
2964
2965             setPhoneNumber( rs.getString( "phoneNumber" ) );
2966
2967        get_DataStruct().isEmpty = false;
2968        if ( versioning )
2969            set_Version(rs.getInt(get_versionColumnName()));
2970        setPersistent(true);
2971        markClean();
2972        syncStructs(false);
2973// refs = null;
2974
autoSaveAllowed = true;
2975    }
2976
2977
2978    private int[] param = null;
2979    private boolean isDeletedFromDatabase = false;
2980    /**
2981     * Prepares the statement used to insert this object
2982     * into the database.
2983     *
2984     * @param conn The database connection.
2985     *
2986     * @return The insert statement.
2987     *
2988     * @exception java.sql.SQLException if an error occurs.
2989     */

2990    public PreparedStatement getInsertStatement(DBConnection conn)
2991    throws SQLException {
2992        ObjectId oid;
2993    
2994    if (isDeletedFromDatabase)
2995            throw new SQLException("Object "+get_OId()+" is already deleted");
2996
2997        PreparedStatement stmt = conn.prepareStatement(
2998            "insert into person ( firstName, lastName, phoneNumber, " + get_OIdColumnName() + ", " + get_versionColumnName() + " )" +
2999            "values ( ?, ?, ?, ?, ? )"
3000        );
3001
3002        param = new int[1]; param[0] = 1;
3003        // writeMemberStuff uses the JDBCsetCalls.template
3004
// to build up the value for this tag:
3005
// the value is a series of calls to setPrepStmtParam_TYPE methods.
3006
// Those methods are defined in GenericDO.
3007
try {
3008            setPrepStmtParam_String ( stmt, param, getFirstName());
3009            setPrepStmtParam_String ( stmt, param, getLastName());
3010            setPrepStmtParam_String ( stmt, param, getPhoneNumber());
3011
3012            /* The ObjecId/Version columns form the primary key. */
3013            setPrepStmtParam_BigDecimal( stmt, param, get_OId().toBigDecimal() );
3014            setPrepStmtParam_int( stmt, param, get_NewVersion() );
3015
3016        } catch ( Exception JavaDoc e ) {
3017            throw new SQLException( "Data Object error: " + e.getMessage() );
3018        }
3019        statistics.incrementInsertNum();
3020        return stmt;
3021    }
3022
3023
3024    /**
3025     *
3026     */

3027    private boolean _lockDO = false;
3028
3029    /**
3030     * Specifies whether to lock this DO (row) in database just before commit.
3031     * Locking is attempted via "dummy" update:
3032     * "update set version=OLD_ONE where OID=X and version=OLD_ONE".
3033     * @param value true for locking, false otherwise
3034     */

3035    public void doCheck(boolean value) {
3036        _lockDO = value;
3037    }
3038
3039    /**
3040     * Locks this DO in database by performing
3041     * "update set version=OLD_ONE where OID=X and version=OLD_ONE".
3042     */

3043    public void doLock() throws SQLException {
3044        if (null!=transaction) {
3045            boolean _ol = _lockDO;
3046            _lockDO = true;
3047            transaction.lockDO(this);
3048            _lockDO = _ol;
3049        }
3050    }
3051
3052    private boolean incrementVersionToo = true;
3053    /**
3054     * Locks this DO in database by performing
3055     * "update set version=OLD_ONE where OID=X and version=INCREMENTED".
3056     */

3057    public void doTouch()
3058    throws SQLException, DatabaseManagerException,
3059    com.lutris.appserver.server.sql.ObjectIdException, DataObjectException {
3060        if (null!=transaction) {
3061        checkLoad();
3062        checkDup();
3063        markNewValue();
3064            incrementVersionToo = true;
3065            boolean _ol = _lockDO;
3066            _lockDO = true;
3067            transaction.lockDO(this);
3068            _lockDO = _ol;
3069        }
3070    }
3071
3072    /**
3073     * Prepares and executes the statement used to lock this object
3074     * in the database.
3075     *
3076     * @param conn The database connection
3077     *
3078     * @exception java.sql.SQLException if an error occurs.
3079     */

3080    public void executeLockingStatement(DBConnection conn) throws SQLException {
3081        if (!_lockDO)
3082            return;
3083        StringBuffer JavaDoc updateStmt = new StringBuffer JavaDoc();
3084        PreparedStatement stmt = null;
3085        if (isDeletedFromDatabase)
3086            throw new SQLException("person ("
3087                    +get_OId()+") is already deleted, "
3088                    +"cannot lock it.");
3089
3090        param = new int[1]; param[0] = 1;
3091        try {
3092            updateStmt.append("Update person set ");
3093            updateStmt.append(get_versionColumnName()).append(" = ? ");
3094            updateStmt.append(" where " + get_OIdColumnName() + " = ? and " + get_versionColumnName() + " = ?");
3095
3096            stmt = conn.prepareStatement(updateStmt.toString());
3097            setPrepStmtParam_int(stmt, param, get_Version()+(incrementVersionToo?1:0));
3098            setPrepStmtParam_BigDecimal( stmt, param, get_OId().toBigDecimal() );
3099            setPrepStmtParam_int(stmt, param, get_Version());
3100            if (null != stmt) {
3101            conn.executeUpdate(stmt, "execute update");
3102                if (incrementVersionToo) {
3103                    set_Version(get_Version()+1);
3104                }
3105            }
3106        } catch ( Exception JavaDoc e ) {
3107                e.printStackTrace();
3108            throw new SQLException( "Data Object error: " + e.getMessage() );
3109        }
3110    }
3111
3112
3113    /**
3114     * Prepares the statement used to update this object
3115     * in the database.
3116     *
3117     * @param conn The database connection
3118     *
3119     * @return The update statement.
3120     *
3121     * @exception java.sql.SQLException if an error occurs.
3122     */

3123    public PreparedStatement getUpdateStatement(DBConnection conn)
3124    throws SQLException {
3125        StringBuffer JavaDoc updateStmt = new StringBuffer JavaDoc();
3126        PreparedStatement stmt;
3127
3128         if (isDeletedFromDatabase)
3129            throw new SQLException("Object "+get_OId()+" is already deleted");
3130
3131        data.set_Version(get_Version()+1);
3132        param = new int[1]; param[0] = 1;
3133        try {
3134            updateStmt.append("Update person set ");
3135            updateStmt.append(get_versionColumnName()).append(" = ? ");
3136
3137            if (changedFirstName)
3138                updateStmt.append(", FirstName = ? ");
3139            if (changedLastName)
3140                updateStmt.append(", LastName = ? ");
3141            if (changedPhoneNumber)
3142                updateStmt.append(", PhoneNumber = ? ");
3143            updateStmt.append(" where " + get_OIdColumnName() + " = ? and " + get_versionColumnName() + " = ?");
3144
3145            stmt = conn.prepareStatement(updateStmt.toString());
3146            setPrepStmtParam_int(stmt, param, get_Version());
3147
3148            if (changedFirstName) {
3149                setPrepStmtParam_String( stmt, param, getFirstName());
3150                changedFirstName = false;
3151            }
3152            if (changedLastName) {
3153                setPrepStmtParam_String( stmt, param, getLastName());
3154                changedLastName = false;
3155            }
3156            if (changedPhoneNumber) {
3157                setPrepStmtParam_String( stmt, param, getPhoneNumber());
3158                changedPhoneNumber = false;
3159            }
3160            setPrepStmtParam_BigDecimal( stmt, param, get_OId().toBigDecimal() );
3161            setPrepStmtParam_int(stmt, param, get_Version() - 1);
3162        } catch ( Exception JavaDoc e ) {
3163                e.printStackTrace();
3164            throw new SQLException( "Data Object error: " + e.getMessage() );
3165        }
3166        statistics.incrementUpdateNum();
3167        return stmt;
3168    }
3169
3170    /**
3171     * Prepares the statement used to delete this object
3172     * from the database.
3173     *
3174     * @param conn The database connection
3175     *
3176     * @return The delete statement.
3177     *
3178     * @exception java.sql.SQLException if an error occurs.
3179     */

3180    public PreparedStatement getDeleteStatement(DBConnection conn)
3181    throws SQLException {
3182        String JavaDoc sql="";
3183        if(isDeleteCheckVersion())
3184            sql =
3185            "delete from person \n" +
3186            "where " + get_OIdColumnName() + " = ? and " + get_versionColumnName() + " = ?";
3187        else
3188            sql =
3189            "delete from person \n" +
3190            "where " + get_OIdColumnName() + " = ?";
3191        PreparedStatement stmt = conn.prepareStatement(sql);
3192        stmt.setBigDecimal(1, get_OId().toBigDecimal());
3193        if(isDeleteCheckVersion()) {
3194            stmt.setInt(2, get_Version());
3195        }
3196        statistics.incrementDeleteNum();
3197        isDeletedFromDatabase = true;
3198        return stmt;
3199    }
3200    
3201
3202
3203    /*
3204     * toString - for debugging
3205     *
3206     * @return String for debugging.
3207     *
3208     */

3209    public String JavaDoc toString(){
3210        return toString( 1 );
3211    }
3212
3213    public String JavaDoc toString( int indentCount ){
3214        String JavaDoc indent = "";
3215        for ( int i = 0; i < indentCount; i++ ) {
3216            indent += ". ";
3217        }
3218        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
3219        sb.append(indent + "PersonDO:");
3220
3221        ObjectId oid = get_OId();
3222        String JavaDoc id = "virgin";
3223        if ( null != oid )
3224            id = oid.toString();
3225        sb.append(" OID=" + id + ",VERSION=" + get_Version());
3226        if (isLoaded()) {
3227                sb.append("\n" + indent + "firstName=" + get_DataStruct().getFirstName());
3228    
3229                sb.append("\n" + indent + "lastName=" + get_DataStruct().getLastName());
3230    
3231                sb.append("\n" + indent + "phoneNumber=" + get_DataStruct().getPhoneNumber());
3232;
3233            sb.append("\n" + indent + "SUPER=" + super.toString( indentCount ));
3234        }
3235        return sb.toString();
3236    }
3237
3238    /**
3239     * A stub method for implementing pre-commit assertions
3240     * for this PersonDO.
3241     * Implement this stub to throw an RefAssertionException for cases
3242     * where this object is not valid for writing to the database.
3243     */

3244    protected void okToCommit()
3245    throws RefAssertionException {
3246    }
3247
3248    /**
3249     * A stub method for implementing pre-delete assertions
3250     * for this PersonDO.
3251     * Implement this stub to throw an RefAssertionException for cases
3252     * where this object is not valid for deletion from the database.
3253     */

3254    protected void okToDelete() throws RefAssertionException { }
3255
3256    /**
3257     * Inserts/Updates the DO into its table.
3258     *
3259     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3260     * @exception RefAssertionException Thrown by okTo method.
3261     * @exception java.sql.SQLException If any SQL errors occur.
3262     *
3263     * @deprecated Use save() instead.
3264     */

3265    public void commit()
3266    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3267        commit(null);
3268    }
3269
3270    /**
3271     * Inserts/Updates the DO into its table.
3272     * The transaction is likely provided by the commit() method of another DO
3273     * which references this DO.
3274     *
3275     * @param dbt The transaction object used for this operation.
3276     *
3277     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3278     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3279     * @exception RefAssertionException Thrown by okTo method.
3280     * @exception java.sql.SQLException If any SQL errors occur.
3281     *
3282     * @deprecated Use save() instead.
3283     */

3284    public void commit(DBTransaction dbt)
3285    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3286        if (cache.getTableConfiguration().isReadOnly())
3287            throw new AssertionDataObjectException("PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3288        // WebDocWf extension for generic store
3289
try {
3290            DBTransaction dbtlocal = dbt;
3291            boolean needToCommit = false;
3292            if (dbtlocal == null) {
3293               if( get_transaction()==null) {
3294                  dbtlocal = DODS.getDatabaseManager().createTransaction(get_OriginDatabase());
3295                  dbtlocal.setDatabaseName(get_OriginDatabase());
3296                  needToCommit = true;
3297               }else
3298                  dbtlocal=transaction;
3299            } else {
3300                if(get_transaction()!=null) {
3301                   if(!get_transaction().equals(dbt))
3302                         throw new DatabaseManagerException("DO doesn't belong this transaction.");
3303                }
3304            }
3305            modifyDO( dbtlocal, false );
3306            if (needToCommit) {
3307                dbtlocal.commit();
3308                dbtlocal.release();
3309            }
3310        } catch (DataObjectException e) {
3311            modifyDO( dbt, false );
3312        }
3313        // end of WebDocWf extension for generic store
3314
}
3315
3316    /**
3317     * Inserts/Updates the DO into its table.
3318     *
3319     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3320     * @exception RefAssertionException Thrown by okTo method.
3321     * @exception java.sql.SQLException If any SQL errors occur.
3322     *
3323     * WebDocWf extension
3324     */

3325    public void save()
3326    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3327        save(null,true);
3328    }
3329
3330    /**
3331     * Inserts/Updates the DO into its table.
3332     *
3333     * @param references True if references should be saved with this DO.
3334     *
3335     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3336     * @exception RefAssertionException Thrown by okTo method.
3337     * @exception java.sql.SQLException If any SQL errors occur.
3338     *
3339     * WebDocWf extension
3340     */

3341    public void save(boolean references)
3342    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3343        save(null,references);
3344    }
3345
3346    /**
3347     * Inserts/Updates the DO into its table.
3348     * The transaction is likely provided by the commit() method of another DO
3349     * which references this DO.
3350     *
3351     * @param dbt The transaction object used for this operation.
3352     *
3353     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3354     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3355     * @exception RefAssertionException Thrown by okTo method.
3356     * @exception java.sql.SQLException If any SQL errors occur.
3357     *
3358     * WebDocWf extension
3359     */

3360    public void save(DBTransaction dbt)
3361    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3362        save(dbt, true);
3363    }
3364
3365    /**
3366     * Inserts/Updates the DO into its table.
3367     * The transaction is likely provided by the commit() method of another DO
3368     * which references this DO.
3369     *
3370     * @param dbt The transaction object used for this operation.
3371     * @param references True if references of this DO should be saved.
3372     *
3373     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3374     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3375     * @exception RefAssertionException Thrown by okTo method.
3376     * @exception java.sql.SQLException If any SQL errors occur.
3377     *
3378     * WebDocWf extension
3379     */

3380    public void save(DBTransaction dbt, boolean references)
3381    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3382        if (cache.getTableConfiguration().isReadOnly()) {
3383            throw new AssertionDataObjectException("PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3384        }
3385        // before: modifyDO( dbt, false );
3386
// The following line has been inserted:
3387
try {
3388            // WebDocWf extension for generic store
3389
// The following line has been inserted:
3390
DBTransaction dbtlocal = dbt;
3391            boolean needToCommit = false;
3392
3393            if (dbtlocal == null) {
3394              if( get_transaction()==null) {
3395                dbtlocal = DODS.getDatabaseManager().createTransaction(get_OriginDatabase());
3396                dbtlocal.setDatabaseName(get_OriginDatabase());
3397                needToCommit = true;
3398              }
3399             else
3400                dbtlocal=transaction;
3401            } else {
3402                if(get_transaction()!=null) {
3403                    if(!get_transaction().equals(dbt))
3404                          throw new DatabaseManagerException("DO doesn't belong this transaction.");
3405                }
3406            }
3407
3408            // The following line has been changed:
3409
modifyDO( dbtlocal, false, references );
3410            if (needToCommit) {
3411                dbtlocal.commit();
3412                dbtlocal.release();
3413            }
3414        } catch (DataObjectException e) {
3415            modifyDO( dbt, false );
3416        }
3417        // end of WebDocWf extension for generic store
3418
}
3419
3420    /**
3421     * Deletes the DO from its table.
3422     *
3423     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3424     * @exception RefAssertionException Thrown by okTo method.
3425     * @exception java.sql.SQLException If any SQL errors occur.
3426     */

3427    public void delete()
3428    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3429        delete((DBTransaction)null);
3430    }
3431
3432
3433    /**
3434     * UnDeletes the DO and inserts to the table.
3435     *
3436     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3437     * @exception RefAssertionException Thrown by okTo method.
3438     * @exception java.sql.SQLException If any SQL errors occur.
3439     */

3440    public void unDelete()
3441    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3442        unDelete((DBTransaction)null);
3443    }
3444    
3445    /**
3446     * Deletes the DO from its table.
3447     * The transaction is likely provided by the delete() method of another DO
3448     * which references this DO.
3449     *
3450     * @param dbt The transaction object used for this operation.
3451     *
3452     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3453     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3454     * @exception RefAssertionException Thrown by okTo method.
3455     * @exception java.sql.SQLException If any SQL errors occur.
3456     */

3457    public void delete(DBTransaction dbt)
3458    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3459        if (cache.getTableConfiguration().isReadOnly())
3460            throw new AssertionDataObjectException("PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3461        // WebDocWf extension for generic store
3462
// The following lines have been inserted:
3463
try {
3464            DBTransaction dbtlocal = dbt;
3465            boolean needToCommit = false;
3466            if (dbtlocal == null) {
3467              if(get_transaction()==null) {
3468                dbtlocal = DODS.getDatabaseManager().createTransaction(get_OriginDatabase());
3469                dbtlocal.setDatabaseName(get_OriginDatabase());
3470                needToCommit = true;
3471              }
3472              else
3473                dbtlocal=transaction;
3474            } else {
3475                if(get_transaction()!=null) {
3476                    if(!get_transaction().equals(dbtlocal))
3477                        throw new DatabaseManagerException("DO doesn't belong this transaction.");
3478                }
3479            }
3480            // The following line has been changed:
3481
modifyDO( dbtlocal, true );
3482            // end of WebDocWf extension for generic store
3483
if (needToCommit) {
3484                dbtlocal.commit();
3485                dbtlocal.release();
3486            }
3487        } catch (DataObjectException e) {
3488            modifyDO( dbt, true );
3489        }
3490    }
3491
3492    /**
3493     * UnDeletes the DO and inserts to the table.
3494     *
3495     * @param dbt The transaction object used for this operation.
3496     *
3497     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3498     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3499     * @exception RefAssertionException Thrown by okTo method.
3500     * @exception java.sql.SQLException If any SQL errors occur.
3501     */

3502    public void unDelete(DBTransaction dbt)
3503    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3504     
3505     if (cache.getTableConfiguration().isReadOnly())
3506            throw new AssertionDataObjectException("PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3507        // WebDocWf extension for generic store
3508
// The following lines have been inserted:
3509
try {
3510            DBTransaction dbtlocal = dbt;
3511            boolean needToCommit = false;
3512            if (dbtlocal == null) {
3513              if(get_transaction()==null) {
3514                dbtlocal = DODS.getDatabaseManager().createTransaction(get_OriginDatabase());
3515                dbtlocal.setDatabaseName(get_OriginDatabase());
3516                needToCommit = true;
3517              }
3518              else
3519                dbtlocal=transaction;
3520            } else {
3521           if(get_transaction()!=null) {
3522                if(!get_transaction().equals(dbtlocal))
3523                    throw new DatabaseManagerException("DO didn't belong this transaction.");
3524           }
3525          }
3526          setDeleted(false);
3527     isDeletedFromDatabase = false;
3528          persistent=false;
3529          modifyDO( dbtlocal, false );
3530          if (needToCommit) {
3531                dbtlocal.commit();
3532                dbtlocal.release();
3533          }
3534          isDeletedFromDatabase = false;
3535        } catch (DataObjectException e) {
3536            persistent=true;
3537            setDeleted(true);
3538        }
3539    }
3540
3541    
3542    /**
3543     * Modifies the DO within its table.
3544     * Performs recursive commit/delete on referenced DOs;
3545     * all operations occur within a single transaction
3546     * to allow rollback in the event of error.
3547     * Only the creator of the transaction releases it.
3548     *
3549     * @param dbt The transaction object used for this operation.
3550     * @param delete True if doing a delete, otherwise false (for insert/update).
3551     *
3552     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3553     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3554     * @exception RefAssertionException Thrown by okTo method.
3555     * @exception java.sql.SQLException If any SQL errors occur.
3556     *
3557     * WebDocWf extension
3558     */

3559    protected void modifyDO( DBTransaction dbt, boolean delete)
3560    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3561        modifyDO( dbt, delete, true);
3562    }
3563
3564    /**
3565     * Modifies the DO within its table.
3566     * Performs recursive commit/delete on referenced DOs;
3567     * all operations occur within a single transaction
3568     * to allow rollback in the event of error.
3569     * Only the creator of the transaction releases it.
3570     *
3571     * @param dbt The transaction object used for this operation.
3572     * @param delete True if doing a delete, otherwise false (for insert/update).
3573     * @param references True if references should be saved
3574     *
3575     * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3576     * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3577     * @exception RefAssertionException Thrown by okTo method.
3578     * @exception java.sql.SQLException If any SQL errors occur.
3579     *
3580     * WebDocWf extension
3581     */

3582    protected void modifyDO( DBTransaction dbt, boolean delete, boolean references )
3583    throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException, DBRowUpdateException, QueryException {
3584        if ( delete )
3585            okToDelete();
3586        else
3587            okToCommit();
3588        boolean ownTransaction = false;
3589        try {
3590            if ( null == dbt ) {
3591                if( null==get_transaction()) {
3592                    DatabaseManager dbm = DODS.getDatabaseManager();
3593                    dbt = dbm.createTransaction(get_OriginDatabase()); // create a transaction
3594
dbt.setDatabaseName(get_OriginDatabase());
3595                    ownTransaction = true;
3596                } else {
3597                    dbt=transaction;
3598                }
3599            } else {
3600
3601                if(get_transaction()!=null) {
3602                    if(!get_transaction().equals(dbt))
3603                        throw new DatabaseManagerException("DO doesn't belong this transaction.");
3604                }
3605                // WebDocWf fix for circular references
3606
// The following lines have been inserted
3607
CoreDO foundDO = _tr_(dbt).getDO(this);
3608                if (foundDO!=null)
3609                    return;
3610                
3611            }
3612            // end of WebDocWf fix for circular references
3613
if ( null == dbt )
3614                throw new DatabaseManagerException("DatabaseManager.createTransaction returned null." );
3615            if ( delete ) {
3616               _tr_(dbt).addDeletedDO(this);
3617                // Code to perform cascading deletes is generated here
3618
// if cascading deletes are not supported by the database.
3619

3620                // The following line keeps the compiler happy
3621
// when the CASCADING_DELETES tag is empty.
3622
if ( false )
3623                    throw new QueryException("XXX");
3624            } else {
3625                // WebDocWf extension for save without references
3626
// The following line has been inserted
3627
if (references) {
3628                    // end of WebDocWf extension for save without references
3629
// commit referenced DOs.
3630

3631                    // WebDocWf extension for save without references
3632
// The following line has been inserted
3633
}
3634                // end of WebDocWf extension for save without references
3635
}
3636            if ( false ) {
3637                // This throw is here to keep the compiler happy
3638
// in the case of a DO that does not refer to other DOs.
3639
// In that case, the above delete/commit code blocks will be empty
3640
// and throw nothing.
3641
throw new DataObjectException( "foo" );
3642            }
3643            if ( delete ) {
3644              dbt.delete( this );
3645              setDeleted(true);
3646              _tr_(dbt).resetDeletedDOs();
3647            } else {
3648                if ( isLoaded() )
3649                    dbt.insert( this ); // dbt.insert() handles insertions and updates
3650
}
3651            if (ownTransaction) {
3652                dbt.commit(); // commit the transaction
3653
}
3654        } catch (SQLException sqle) {
3655            StringBuffer JavaDoc message = new StringBuffer JavaDoc("Failed to insert/update DO: ");
3656            message.append(sqle.getMessage());
3657            // rollback, if necessary
3658
if (ownTransaction) {
3659                try {
3660                    dbt.rollback();
3661                } catch (SQLException sqle2) {
3662                    message.insert(0,"\n");
3663                    message.insert(0,sqle2.getMessage());
3664                    message.insert(0,"Rollback failed: ");
3665                }
3666            }
3667            throw new SQLException(message.toString());
3668        } finally {
3669            // release the transaction, if any
3670
if (ownTransaction) {
3671                dbt.release();
3672            }
3673        }
3674    }
3675
3676    private void changedFlags_set(boolean value) {
3677        changedFirstName = value;
3678        changedLastName = value;
3679        changedPhoneNumber = value;
3680    }
3681/* protected void finalize() throws Throwable {
3682        System.err.println("("+get_OId().toString()+") refs size("+refs.size()+")");
3683    }*/

3684}
3685
Popular Tags