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