Source Code Cross Referenced for PersonDO.java in  » J2EE » enhydra » jspPhoneBook » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » enhydra » jspPhoneBook.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*-----------------------------------------------------------------------------
0002:         * Enhydra Java Application Server
0003:         * Copyright 1997-2000 Lutris Technologies, Inc.
0004:         * All rights reserved.
0005:         *
0006:         * Redistribution and use in source and binary forms, with or without
0007:         * modification, are permitted provided that the following conditions
0008:         * are met:
0009:         * 1. Redistributions of source code must retain the above copyright
0010:         *    notice, this list of conditions and the following disclaimer.
0011:         * 2. Redistributions in binary form must reproduce the above copyright
0012:         *    notice, this list of conditions and the following disclaimer in
0013:         *    the documentation and/or other materials provided with the distribution.
0014:         * 3. All advertising materials mentioning features or use of this software
0015:         *    must display the following acknowledgement:
0016:         *    This product includes Enhydra software developed by Lutris
0017:         *    Technologies, Inc. and its contributors.
0018:         * 4. Neither the name of Lutris Technologies nor the names of its contributors
0019:         *    may be used to endorse or promote products derived from this software
0020:         *    without specific prior written permission.
0021:         *
0022:         * THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
0023:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0024:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0025:         * ARE DISCLAIMED.  IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE
0026:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0027:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0028:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0031:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0032:         * POSSIBILITY OF SUCH DAMAGE.
0033:         *
0034:         * contains WebDocWf extensions
0035:         *
0036:         *-----------------------------------------------------------------------------
0037:         * phoneList.data/PersonDO.java
0038:         *-----------------------------------------------------------------------------
0039:         */
0040:
0041:        package jspPhoneBook.data;
0042:
0043:        import java.io.*;
0044:        import java.sql.*;
0045:        import java.math.*;
0046:        import java.util.Hashtable;
0047:        import java.util.Collection;
0048:        import java.util.Properties;
0049:        import java.io.FileInputStream;
0050:        import java.util.Vector;
0051:        import java.util.Map;
0052:        import java.util.HashSet;
0053:        import java.util.HashMap;
0054:        import java.util.Iterator;
0055:        import java.lang.reflect.Method;
0056:
0057:        import com.lutris.logging.LogChannel;
0058:        import com.lutris.logging.Logger;
0059:        import org.enhydra.dods.DODS;
0060:        import com.lutris.util.Config;
0061:        import com.lutris.util.ConfigException;
0062:        import com.lutris.appserver.server.sql.*;
0063:        import com.lutris.appserver.server.sql.standard.*;
0064:        import com.lutris.dods.builder.generator.dataobject.*;
0065:        import com.lutris.dods.builder.generator.query.*;
0066:        import org.enhydra.dods.cache.Condition;
0067:        import org.enhydra.dods.cache.DataStructCache;
0068:        import org.enhydra.dods.cache.QueryCache;
0069:        import org.enhydra.dods.cache.QueryCacheImpl;
0070:        import org.enhydra.dods.cache.QueryResult;
0071:        import org.enhydra.dods.cache.ConfigurationAdministration;
0072:        import org.enhydra.dods.statistics.Statistics;
0073:        import com.lutris.classloader.MultiClassLoader;
0074:        import org.enhydra.xml.XMLConfig;
0075:        import org.enhydra.dods.Common;
0076:        import org.enhydra.dods.cache.CacheConstants;
0077:        import org.enhydra.dods.exceptions.AssertionDataObjectException;
0078:        import org.enhydra.dods.exceptions.CacheObjectException;
0079:
0080:        /**
0081:         * Data core class, used to set and retrieve the PersonDO information.
0082:         *
0083:         * @version $Revision: 1.1 $
0084:         * @author  EnhydraTeam
0085:         * @since   PhoneList
0086:         */
0087:        public class PersonDO extends
0088:                com.lutris.dods.builder.generator.dataobject.GenericDO
0089:                implements  PersonDOI, java.io.Serializable {
0090:            /**
0091:             * Static final data members name the table and columns for this DO.
0092:             * By using these members with an instance of the QueryBuilder class,
0093:             * an application can perform straight SQL queries while retaining
0094:             * compile-time checking of table and column usage.
0095:             *
0096:             * Example:  List the Cities containing Persons named Bob:
0097:             *
0098:             *    Using straight SQL with QueryBuilder:
0099:             *      Pro: code runs faster because you create fewer objects
0100:             *      Con: code is less clear
0101:             *
0102:             *         Vector fields = new Vector();
0103:             *         fields.addElement( AddressDO.City );
0104:             *         QueryBuilder qb = new QueryBuilder( fields );
0105:             *         qb.addWhere( PersonDO.FirstName, "Bob" );
0106:             *         qb.addWhere( PersonDO.PrimaryKey, AddressDO.Person );
0107:             *         RDBRow row;
0108:             *         while ( null != ( row = qb.getNextRow() ) ) {
0109:             *             String city = row.get( AddressDO.City ).getString();
0110:             *         }
0111:             *
0112:             *    Using Query/DO classes:
0113:             *      Pro: code is (often) clearer
0114:             *      Con: code runs slower because you create more objects
0115:             *
0116:             *         PersonQuery pq = new PersonQuery();
0117:             *         pq.setQueryFirstName( "Bob" );
0118:             *         PersonDO[] bobs = pq.getDOArray();
0119:             *         for ( int i = 0; i < bobs.length; i++ ) {
0120:             *             AddressQuery aq = new AddressQuery();
0121:             *             aq.setQueryPerson( bobs[i] );
0122:             *             AddressDO addr = aq.getNextDO();
0123:             *             String city = addr.getCity();
0124:             *         }
0125:             */
0126:            static public final RDBTable table = new RDBTable("person");
0127:
0128:            /**
0129:             * List of reference objects
0130:             */
0131:            private HashMap refs = null;
0132:
0133:            /**
0134:             * Name of the logical database for which DO object was created
0135:             */
0136:            protected String originDatabase = null;
0137:
0138:            /**
0139:             * Return the name of the logical database for which DO object was created.
0140:             *
0141:             * @deprecated Use get_OriginDatabase()
0142:             * @return origin logical database name.
0143:             *
0144:             */
0145:            public String getOriginDatabase() {
0146:                return get_OriginDatabase();
0147:            }
0148:
0149:            /**
0150:             * Return the name of the logical database for which DO object was created.
0151:             *
0152:             * @return origin logical database name.
0153:             *
0154:             */
0155:            public String get_OriginDatabase() {
0156:                return get_DataStruct().get_Database();
0157:            }
0158:
0159:            /**
0160:             * Return person as the name of the table in the database
0161:             * which contains PersonDO objects.
0162:             * This method overrides CoreDO.getTableName()
0163:             * and is used by CoreDO.executeUpdate() during error handling.
0164:             *
0165:             * @return The database table name.
0166:             *
0167:             * @see CoreDO
0168:             * @author Jay Gunter
0169:             */
0170:            public String getTableName() {
0171:                return "person";
0172:            }
0173:
0174:            /**
0175:             * static final RDBColumn PrimaryKey for use with QueryBuilder.
0176:             * See example above.
0177:             */
0178:            static public final RDBColumn PrimaryKey = new RDBColumn(table,
0179:                    get_primaryKeyName());
0180:
0181:            /* RDBColumns for PersonDO attributes are defined below. */
0182:
0183:            /* Using a DO (and its Query class) to access a VIEW instead of a TABLE:
0184:             *
0185:             * A DO (and its Query class) can be used to access a VIEW
0186:             * instead of a TABLE.  The Data Object is created as usual in DODS,
0187:             * but the "create table" SQL command for that DO is not used.
0188:             * Instead, you substitute a "create view" command to create a
0189:             * virtual table in the database; this is often done to provide
0190:             * convenient access to a collection of tables joined together.
0191:             *
0192:             * A VIEW usually does not return "oid" and "version" columns;
0193:             * often (but now always) a VIEW is defined to return the "oid" column
0194:             * for one of the tables joined together in the definition of the VIEW.
0195:             *
0196:             * If notUsingOId is true, PersonDO.createExisting(ResultSet)
0197:             * will NOT invoke the GenericDO(ResultSet) constructor
0198:             * so to avoid attempting to extract the "oid" and "version" columns
0199:             * from the ResultSet.
0200:             */
0201:            static protected final boolean notUsingOId = false;
0202:
0203:            /**
0204:             * A DO class contains a reference to a DataStruct class.
0205:             * This reference can be null (when the data for the DO
0206:             * has not yet been retrieved from the database),
0207:             * allowing a DO object to be a lightweight placeholder
0208:             * until its data is needed.
0209:             */
0210:            private PersonDataStruct data = null;
0211:
0212:            /**
0213:             * A DO class contains a reference to a DBTransaction class.
0214:             * This reference can be null (when the DO is created without
0215:             * transaction).
0216:             */
0217:            private DBTransaction transaction = null;
0218:
0219:            /**
0220:             * Return transaction which DO belongs.
0221:             *
0222:             * @return DBTransaction or null if not specified.
0223:             *
0224:             */
0225:            public DBTransaction get_transaction() {
0226:                return transaction;
0227:            }
0228:
0229:            /**
0230:             * Set Transaction to current DO.
0231:             *
0232:             * @param DBTransaction.
0233:             *
0234:             */
0235:            protected boolean setTransaction(DBTransaction trans) {
0236:                boolean isOK = false;
0237:                if (get_transaction() == null) {
0238:                    transaction = trans;
0239:                    isOK = true;
0240:                } else {
0241:                    if (get_transaction().equals(trans))
0242:                        isOK = true;
0243:                }
0244:                return isOK;
0245:            }
0246:
0247:            /**
0248:             * Return information whether the data for this object has been marked read-only.
0249:             *
0250:             * @return True if the data for this object has been marked read-only.
0251:             *
0252:             */
0253:            public boolean isReadOnly() {
0254:                return getConfigurationAdministration().getTableConfiguration()
0255:                        .isReadOnly();
0256:            }
0257:
0258:            /**
0259:             * Sets DO's data.
0260:             * @deprecated Use set_Data()
0261:             */
0262:            public void setData(Object data) {
0263:                set_Data(data);
0264:            }
0265:
0266:            /**
0267:             * Sets DO's data.
0268:             */
0269:            public void set_Data(Object data) {
0270:                this .data = (PersonDataStruct) data;
0271:            }
0272:
0273:            /**
0274:             * Sets original DO's data.
0275:             */
0276:            public void originalData_set(Object data) {
0277:                originalData = (PersonDataStruct) data;
0278:            }
0279:
0280:            /**
0281:             * Returns DO's data.
0282:             * @deprecated Use get_Data()
0283:             */
0284:            public Object getData() {
0285:                return get_Data();
0286:            }
0287:
0288:            /**
0289:             * Returns DO's data.
0290:             */
0291:            public Object get_Data() {
0292:                return (null != data) ? data : originalData;
0293:            }
0294:
0295:            /**
0296:             * Returns dataStruct.
0297:             * @deprecated Use get_DataStruct()
0298:             */
0299:            public PersonDataStruct getDataStruct() {
0300:                return get_DataStruct();
0301:            }
0302:
0303:            /**
0304:             * Returns dataStruct.
0305:             */
0306:            public PersonDataStruct get_DataStruct() {
0307:                return (PersonDataStruct) get_Data();
0308:            }
0309:
0310:            /**
0311:             * Returns original DO's data.
0312:             */
0313:            public Object originalData_get() {
0314:                return originalData;
0315:            }
0316:
0317:            public void checkDup() throws DatabaseManagerException,
0318:                    com.lutris.appserver.server.sql.ObjectIdException {
0319:                if (isDeletedFromDatabase)
0320:                    throw new DatabaseManagerException("Object " + get_OId()
0321:                            + " is deleted");
0322:                if (null == data) {
0323:                    data = ((PersonDataStruct) originalData).duplicate();
0324:                    data.readOnly = false;
0325:                }
0326:            }
0327:
0328:            /**
0329:             * Protected constructor. Only derived classes should call it.
0330:             *
0331:             * @param is_view
0332:             *
0333:             * @exception DatabaseManagerException
0334:             *   If a connection to the database cannot be established, etc.
0335:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0336:             *   If an object's id can't be allocated for this object.
0337:             */
0338:            protected PersonDO(boolean is_view) throws ObjectIdException,
0339:                    DatabaseManagerException {
0340:                super (is_view);
0341:                if (isTransactionCheck()) {
0342:                    String trace = "";
0343:                    StackTraceElement[] traceElements = (new Throwable())
0344:                            .getStackTrace();
0345:                    for (int i = 0; i < traceElements.length; i++)
0346:                        trace += traceElements[i].toString() + "\n";
0347:                    DODS.getLogChannel().write(
0348:                            Logger.WARNING,
0349:                            "DO without transaction context is created :"
0350:                                    + (is_view ? "" : " Database: "
0351:                                            + get_OriginDatabase()
0352:                                            + " PersonDO class, oid: "
0353:                                            + get_OId() + ", version: "
0354:                                            + get_Version()) + " \n" + trace);
0355:                }
0356:            }
0357:
0358:            /**
0359:             * Protected constructor. Only derived classes should call it.
0360:             *
0361:             * @param is_view
0362:             * @dbTrans Database transaction.
0363:             *
0364:             * @exception DatabaseManagerException
0365:             *   If a connection to the database cannot be established, etc.
0366:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0367:             *   If an object's id can't be allocated for this object.
0368:             */
0369:            protected PersonDO(boolean is_view, DBTransaction dbTrans)
0370:                    throws ObjectIdException, DatabaseManagerException {
0371:                super (is_view);
0372:                setTransaction(dbTrans);
0373:                if (dbTrans != null) {
0374:                    originDatabase = dbTrans.getDatabaseName();
0375:                }
0376:                if (originDatabase == null)
0377:                    originDatabase = get_logicalDBName();
0378:                get_DataStruct().set_Database(originDatabase);
0379:                addToTransactionCache();
0380:
0381:            }
0382:
0383:            /**
0384:             * Protected constructor.  Only derived classes should call it.
0385:             *
0386:             * @exception DatabaseManagerException
0387:             *   If a connection to the database cannot be established, etc.
0388:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0389:             *   If an object's id can't be allocated for this object.
0390:             */
0391:            protected PersonDO() throws ObjectIdException,
0392:                    DatabaseManagerException {
0393:                super (notUsingOId);
0394:                originDatabase = get_logicalDBName();
0395:                get_DataStruct().set_Database(originDatabase);
0396:                if (isTransactionCheck()) {
0397:                    String trace = "";
0398:                    StackTraceElement[] traceElements = (new Throwable())
0399:                            .getStackTrace();
0400:                    for (int i = 0; i < traceElements.length; i++)
0401:                        trace += traceElements[i].toString() + "\n";
0402:                    DODS.getLogChannel().write(
0403:                            Logger.WARNING,
0404:                            "DO without transaction context is created : Database: "
0405:                                    + get_OriginDatabase()
0406:                                    + " PersonDO class, oid: " + get_OId()
0407:                                    + ", version: " + get_Version() + " \n"
0408:                                    + trace);
0409:                }
0410:                if (autoSaveAllowed && isAutoSaveCreateVirgin()
0411:                        && null != transaction) {
0412:                    try {
0413:                        save(transaction, false);
0414:                    } catch (Exception ex) {
0415:                        DODS.getLogChannel().write(
0416:                                Logger.DEBUG,
0417:                                "Faild to AutoSave virgin DO: "
0418:                                        + get_OriginDatabase()
0419:                                        + " PersonDO class\n");
0420:                    }
0421:                }
0422:            }
0423:
0424:            /**
0425:             * Protected constructor.  Only derived classes should call it.
0426:             * @param dbTrans The current database transaction.
0427:             * @exception DatabaseManagerException
0428:             *   If a connection to the database cannot be established, etc.
0429:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0430:             *   If an object's id can't be allocated for this object.
0431:             */
0432:            protected PersonDO(DBTransaction dbTrans) throws ObjectIdException,
0433:                    DatabaseManagerException {
0434:                super (notUsingOId);
0435:                setTransaction(dbTrans);
0436:                if (dbTrans != null) {
0437:                    originDatabase = dbTrans.getDatabaseName();
0438:                }
0439:                if (originDatabase == null)
0440:                    originDatabase = get_logicalDBName();
0441:                get_DataStruct().set_Database(originDatabase);
0442:
0443:                addToTransactionCache();
0444:                if (autoSaveAllowed && isAutoSaveCreateVirgin()
0445:                        && null != transaction) {
0446:                    try {
0447:                        save(transaction, false);
0448:                    } catch (Exception ex) {
0449:                        DODS.getLogChannel().write(
0450:                                Logger.DEBUG,
0451:                                "Faild to AutoSave virgin DO: "
0452:                                        + get_OriginDatabase()
0453:                                        + " PersonDO class\n");
0454:                    }
0455:                }
0456:            }
0457:
0458:            /**
0459:             * isLoaded()
0460:             * Returns information whether object's data is loaded from database.
0461:             * @return true if the data for this object has been retrieved
0462:             * from the database.
0463:             */
0464:            public boolean isLoaded() {
0465:                return (null != originalData) && (!get_DataStruct().isEmpty);
0466:            }
0467:
0468:            /**
0469:             * Load the fields for the DO from the database.
0470:             *
0471:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0472:             *   If an object's id can't be allocated for this object.
0473:             * @exception DataObjectException
0474:             *   If the object is not found in the database.
0475:             * @exception SQLException
0476:             *   If the database rejects the SQL generated to retrieve data
0477:             *   for this object, or if the table contains a bad foreign key, etc.
0478:             */
0479:            public void loadData() throws SQLException, ObjectIdException,
0480:                    DataObjectException {
0481:                if (null == originalData && !get_DataStruct().isEmpty) {
0482:                    originalData = new PersonDataStruct();
0483:                }
0484:
0485:                ObjectId id = get_OId();
0486:                if (null == id)
0487:                    return;
0488:                if (!isPersistent()) // DO from createVirgin
0489:                    return;
0490:                // DO from createExisting.  Complain if no record in database.
0491:                PersonQuery query;
0492:
0493:                query = new PersonQuery(get_transaction());
0494:
0495:                //        if(get_refs()!=null)
0496:                //        {
0497:                query.setRefs(get_refs());
0498:                //        }
0499:                query.setQueryOId(id);
0500:                query.requireUniqueInstance();
0501:                query.setLoadData(true);
0502:                PersonDO obj;
0503:                try {
0504:                    obj = query.getNextDO();
0505:                    if (null == obj)
0506:                        throw new DataObjectException(
0507:                                "PersonDO DO not found for id=" + id);
0508:                    makeIdentical(obj);
0509:                    set_Version(obj.get_Version());
0510:                    get_DataStruct().isEmpty = false;
0511:                } catch (NonUniqueQueryException e) {
0512:                    throw new ObjectIdException("Duplicate ObjectId");
0513:                }
0514:
0515:            }
0516:
0517:            /**
0518:             * Load the actual DO data if necessary.
0519:             * Called by get/set methods.
0520:             *
0521:             * @exception DataObjectException If a data access error occurs.
0522:             */
0523:            protected void checkLoad() throws DataObjectException {
0524:                if (null == originalData || get_DataStruct().isEmpty) {
0525:                    try {
0526:                        loadData();
0527:                    } catch (Exception e) {
0528:                        throw new DataObjectException(
0529:                                "Unable to load data for PersonDO id="
0530:                                        + get_OId() + ", error = ", e);
0531:                    }
0532:                }
0533:            }
0534:
0535:            /**
0536:             * Protected constructor used by createExisting(ObjectId) above.
0537:             *
0538:             * @param id The ObjectId for the object.
0539:             *
0540:             * @exception DataObjectException
0541:             *   If the object is not found in the database.
0542:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0543:             *   If an object's id can't be allocated for this object.
0544:             * @exception DatabaseManagerException
0545:             *   If a connection to the database cannot be established, etc.
0546:             * @exception SQLException
0547:             *   Should never see this exception since GenericDO.ctor(ObjectId)
0548:             *   never accesses the database.
0549:             */
0550:            protected PersonDO(ObjectId id) throws SQLException,
0551:                    ObjectIdException, DataObjectException,
0552:                    DatabaseManagerException {
0553:                super (id);
0554:                originDatabase = get_logicalDBName();
0555:                get_DataStruct().set_Database(originDatabase);
0556:                if (isTransactionCheck()) {
0557:                    String trace = "";
0558:                    StackTraceElement[] traceElements = (new Throwable())
0559:                            .getStackTrace();
0560:                    for (int i = 0; i < traceElements.length; i++)
0561:                        trace += traceElements[i].toString() + "\n";
0562:                    DODS.getLogChannel().write(
0563:                            Logger.WARNING,
0564:                            "DO without transaction context is created : Database: "
0565:                                    + get_OriginDatabase()
0566:                                    + " PersonDO class, oid: " + get_OId()
0567:                                    + ", version: " + get_Version() + " \n"
0568:                                    + trace);
0569:                }
0570:
0571:            }
0572:
0573:            /**
0574:             * Protected constructor used by createExisting(ObjectId, DBTransaction) above.
0575:             *
0576:             * @param id The ObjectId for the object.
0577:             * @param dbTrans The current database transaction
0578:             * @exception DataObjectException
0579:             *   If the object is not found in the database.
0580:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0581:             *   If an object's id can't be allocated for this object.
0582:             * @exception DatabaseManagerException
0583:             *   If a connection to the database cannot be established, etc.
0584:             * @exception SQLException
0585:             *   Should never see this exception since GenericDO.ctor(ObjectId)
0586:             *   never accesses the database.
0587:             */
0588:            protected PersonDO(ObjectId id, DBTransaction dbTrans)
0589:                    throws SQLException, ObjectIdException,
0590:                    DataObjectException, DatabaseManagerException {
0591:                super (id);
0592:                setTransaction(dbTrans);
0593:                if (dbTrans != null) {
0594:                    originDatabase = dbTrans.getDatabaseName();
0595:                }
0596:                if (originDatabase == null)
0597:                    originDatabase = get_logicalDBName();
0598:                get_DataStruct().set_Database(originDatabase);
0599:                addToTransactionCache();
0600:            }
0601:
0602:            /**
0603:             * Represents table and cache (if there is caching) statistics.
0604:             */
0605:            protected static Statistics statistics;
0606:
0607:            /**
0608:             * Get table statistics.
0609:             *
0610:             * @return Table statistics.
0611:             */
0612:            public static Statistics get_statistics() {
0613:                statistics = cache.getStatistics();
0614:                return statistics;
0615:            }
0616:
0617:            /**
0618:             * Refresh table statistics.
0619:             */
0620:            public static void refreshStatistics() {
0621:                cache.refreshStatistics();
0622:            }
0623:
0624:            /**
0625:             * Get all used logical databases.
0626:             *
0627:             * @deprecated Use get_UsedLogicalDatabases()
0628:             * @return Array that contains names of all used logical databases.
0629:             *
0630:             */
0631:            public static String[] getUsedLogicalDatabases() {
0632:                return get_UsedLogicalDatabases();
0633:            }
0634:
0635:            /**
0636:             * Get all used logical databases.
0637:             *
0638:             * @return Array that contains names of all used logical databases.
0639:             *
0640:             */
0641:            public static String[] get_UsedLogicalDatabases() {
0642:                String[] str = { get_logicalDBName() };
0643:                return str;
0644:            }
0645:
0646:            protected static DataStructCache cache; // cache for PersonDO
0647:
0648:            /**
0649:             * Read cache configuration from application configuration file:
0650:             * cache size for phoneList.data.person table or default cache size.
0651:             */
0652:            public static void readCacheConfiguration(String database)
0653:                    throws CacheObjectException {
0654:                if (getConfigurationAdministration().isDisabled()) {
0655:                    throw new CacheObjectException("Caching is disabled");
0656:                }
0657:                Config tableConfig = null;
0658:                Config cacheConfig = null;
0659:                try {
0660:                    tableConfig = (Config) DODS.getDatabaseManager()
0661:                            .getConfig().getSection(
0662:                                    "DB." + database + ".person");
0663:                } catch (Exception ex) {
0664:                }
0665:                try {
0666:                    cacheConfig = (Config) DODS.getDatabaseManager()
0667:                            .getConfig().getSection(
0668:                                    "DB." + database + ".person.cache");
0669:                } catch (Exception e) {
0670:                }
0671:
0672:                cache.readConfiguration(tableConfig, cacheConfig, database);
0673:            }
0674:
0675:            /**
0676:             * Get name of the table that is cached.
0677:             *
0678:             * @return Name of the table that is cached.
0679:             */
0680:            public static String getCacheDodsTableName() {
0681:                return "person";
0682:            }
0683:
0684:            /**
0685:             * Returns person table cache.
0686:             *
0687:             * @return person table cache.
0688:             */
0689:            public static ConfigurationAdministration getConfigurationAdministration() {
0690:                return cache;
0691:            }
0692:
0693:            /**
0694:             * Queries all rows in table, and for each row
0695:             * creates a DO instance in the cache.
0696:             * For these DOs, data.readOnly = true,
0697:             * which causes set methods to throw an exception.
0698:             *
0699:             * @exception DataObjectException
0700:             *   If the object is not found in the database.
0701:             * @exception com.lutris.appserver.server.sql.ObjectIdException
0702:             *   If an object's id can't be allocated for this object.
0703:             * @exception DatabaseManagerException
0704:             *   If a connection to the database cannot be established, etc.
0705:             * @exception SQLException
0706:             *   If the database rejects the SQL generated to retrieve data
0707:             *   for this object, or if the table contains a bad foreign key, etc.
0708:             */
0709:            public static void refreshCache() throws java.sql.SQLException,
0710:                    DatabaseManagerException, ObjectIdException,
0711:                    DataObjectException {
0712:                getConfigurationAdministration().getCacheAdministration(
0713:                        CacheConstants.DATA_CACHE).refresh();
0714:                String querySnt = cache.getInitialQueryCache();
0715:                int maxSize = 0;
0716:                cache.checkFull();
0717:                if (querySnt != null) {
0718:                    PersonQuery query;
0719:
0720:                    query = new PersonQuery((DBTransaction) null);
0721:                    query.hitDatabase();
0722:                    maxSize = cache.getCacheAdministration(
0723:                            CacheConstants.DATA_CACHE).getMaxCacheSize();
0724:                    if (maxSize > 0)
0725:                        try {
0726:                            query.setMaxRows(maxSize);
0727:                        } catch (NonUniqueQueryException nuEx) {
0728:                            System.out
0729:                                    .println("NonUniqueQueryException in refreshCache() method : too many rows were	found.");
0730:                        }
0731:                    if (!querySnt.equals("*")) {
0732:                        QueryBuilder builder = query.getQueryBuilder();
0733:                        builder.addWhere(querySnt);
0734:                    }
0735:                    PersonDO obj;
0736:                    try {
0737:                        query.setLoadData(true);
0738:                        query.getNextDO();
0739:                    } catch (NonUniqueQueryException ex) {
0740:                        // Since we do not call query.requireUniqueInstance()
0741:                        // this should never happen.
0742:                        throw new ObjectIdException("Duplicate ObjectId");
0743:                    }
0744:
0745:                }
0746:                cache.refreshStatistics();
0747:            }
0748:
0749:            private static boolean isDisabledCaching = false;
0750:
0751:            /**
0752:             * Disable caching
0753:             */
0754:            public static void disableCaching() throws java.sql.SQLException,
0755:                    DatabaseManagerException, ObjectIdException,
0756:                    DataObjectException {
0757:                isDisabledCaching = true;
0758:                getConfigurationAdministration().getCacheAdministration(
0759:                        CacheConstants.DATA_CACHE).disable();
0760:            }
0761:
0762:            /**
0763:             * Enable caching
0764:             */
0765:            public static void enableCaching() throws java.sql.SQLException,
0766:                    DatabaseManagerException, ObjectIdException,
0767:                    DataObjectException {
0768:                if (isDisabledCaching) {
0769:                    getConfigurationAdministration().getCacheAdministration(
0770:                            CacheConstants.DATA_CACHE).enable();
0771:                    String querySnt = cache.getInitialQueryCache();
0772:                    if (querySnt != null) {
0773:                        PersonQuery query;
0774:
0775:                        query = new PersonQuery((DBTransaction) null);
0776:                        query.hitDatabase();
0777:                        if (!querySnt.equals("*")) {
0778:                            QueryBuilder builder = query.getQueryBuilder();
0779:                            builder.addWhere(querySnt);
0780:                        }
0781:                        PersonDO obj;
0782:                        try {
0783:                            query.getNextDO();
0784:                        } catch (NonUniqueQueryException ex) {
0785:                            // Since we do not call query.requireUniqueInstance()
0786:                            // this should never happen.
0787:                            throw new ObjectIdException("Duplicate ObjectId");
0788:                        }
0789:
0790:                    }
0791:                }
0792:            }
0793:
0794:            private static StandardDBTransaction _tr_(DBTransaction dbt) {
0795:                return (StandardDBTransaction) dbt;
0796:            }
0797:
0798:            /**
0799:             * Add DO to cache.
0800:             * If DO already exists in cache, just the data member is replaced,
0801:             * so that application references to the DO remain valid.
0802:             * If there  is no caching newDO object is returned.
0803:             *
0804:             * param newDO Data object that will be added to cache.
0805:             *
0806:             * return Data object added to cache.
0807:             */
0808:            private PersonDO addToTransactionCache(PersonDO newDO) {
0809:                PersonDO ret = null;
0810:                if (get_transaction() != null
0811:                        && _tr_(get_transaction()).getTransactionCache() != null) {
0812:                    ret = (PersonDO) _tr_(get_transaction())
0813:                            .getTransactionCache().addDO(newDO);
0814:                }
0815:                if (ret == null)
0816:                    return newDO;
0817:                return ret;
0818:            }
0819:
0820:            /**
0821:             * Add DataStruct object to cache.
0822:             * If there is no caching newDO object is returned.
0823:             *
0824:             * param newDS DataStruct object that will be added to cache.
0825:             *
0826:             * return DataStruct object added to cache.
0827:             */
0828:            public static synchronized PersonDataStruct addToCache(
0829:                    PersonDataStruct newDS) {
0830:                PersonDataStruct ret = (PersonDataStruct) cache
0831:                        .addDataStruct(newDS);
0832:                if (ret == null)
0833:                    return newDS;
0834:                return ret;
0835:            }
0836:
0837:            /**
0838:             * Add DO's original data object to cache.
0839:             */
0840:            public void addToCache() {
0841:                addToCache((PersonDataStruct) this .originalData_get());
0842:            }
0843:
0844:            /**
0845:             * Add DO to cache.
0846:             * If DO already exists in cache, just the data member is replaced,
0847:             * so that application references to the DO remain valid.
0848:             * This method overides method addToCache of the class CoreDO.
0849:             */
0850:            private void addToTransactionCache() {
0851:                addToTransactionCache(this );
0852:            }
0853:
0854:            /**
0855:             * UpdateCache for given DataStruct object
0856:             *
0857:             * @param data DataStruct object
0858:             */
0859:            public static synchronized PersonDataStruct updateCache(
0860:                    PersonDataStruct updDS) {
0861:                PersonDataStruct ret = (PersonDataStruct) cache
0862:                        .updateDataStruct(updDS);
0863:                if (ret == null)
0864:                    return updDS;
0865:                return ret;
0866:            }
0867:
0868:            /**
0869:             * Update Cache
0870:             */
0871:            public void updateCache() {
0872:                updateCache((PersonDataStruct) this .originalData_get());
0873:            }
0874:
0875:            /**
0876:             * Delete DataStruct object from cache
0877:             *
0878:             * @param data DataStruct object for deleting
0879:             *
0880:             * @return Deleted DataStruct object
0881:             */
0882:            public static synchronized PersonDataStruct deleteFromCache(
0883:                    PersonDataStruct data) {
0884:                cache.deleteDataStruct(data);
0885:                return data;
0886:            }
0887:
0888:            /**
0889:             * Remove DataStruct object from cache.
0890:             *
0891:             * @param dbName Logical name of the database from which
0892:             * PersonDataStruct object will be removed.
0893:             * @param handle Handle of DataStruct object which will be re moved.
0894:             */
0895:            public static synchronized void removeFromCache(String dbName,
0896:                    String handle) {
0897:                String cacheHandle = dbName + "." + handle;
0898:                cache.removeDataStruct(cacheHandle);
0899:            }
0900:
0901:            /**
0902:             * Delete object from cache
0903:             */
0904:            public void deleteFromCache() {
0905:                deleteFromCache((PersonDataStruct) this .originalData_get());
0906:            }
0907:
0908:            /**
0909:             * Remove DataStruct from cache.
0910:             *
0911:             * @param data DataStruct object which will be removed.
0912:             *
0913:             * @return Removed DataStruct object or null if DataStruct object doesn't
0914:             * exist in the cache.
0915:             */
0916:            public static synchronized PersonDataStruct removeFromCache(
0917:                    PersonDataStruct data) {
0918:                return (PersonDataStruct) cache.removeDataStruct(data);
0919:            }
0920:
0921:            /**
0922:             * Remove DataStruct from cache.
0923:             */
0924:            public void evict() {
0925:                if (!isPersistent())
0926:                    removeFromCache((PersonDataStruct) this .originalData_get());
0927:            }
0928:
0929:            /**
0930:             * Remove DataStruct objects from cache.
0931:             *
0932:             * @param DSs Array of DataStruct objects which will be removed from cache.
0933:             */
0934:            public static void evict(PersonDataStruct[] DSs) {
0935:                for (int i = 0; i < DSs.length; i++)
0936:                    removeFromCache((PersonDataStruct) DSs[i]);
0937:            }
0938:
0939:            /**
0940:             * Remove DataStruct objects from cache.
0941:             *
0942:             * @param dbName Logical name of the database from which
0943:             * PersonDataStruct object will be removed.
0944:             * @param handles array of DataStruct object handles that will be removed
0945:             * from cache.
0946:             */
0947:            public static void evict(String dbName, String[] handles) {
0948:                if (handles != null) {
0949:                    for (int i = 0; i < handles.length; i++)
0950:                        removeFromCache(dbName, handles[i]);
0951:                }
0952:            }
0953:
0954:            /**
0955:             * The cache is used automatically by the class.
0956:             * Callers of the create() methods do not know whether
0957:             * the returned DO instance is shared or not.
0958:             * This prevents the existence of multiple instances in memory
0959:             * of the same database object.
0960:             * The cache is instantiated when the first DO instance is created.
0961:             */
0962:
0963:            /**
0964:             * Class that contains unchanging (static) data from the database
0965:             * will have a cache of DOs representing the entire contents of the table.
0966:             */
0967:            static {
0968:                try {
0969:                    XMLConfig dodsConf = Common.getDodsConf();
0970:                    String cacheClassPath = null;
0971:                    String cacheClassName = null;
0972:                    try {
0973:                        cacheClassPath = dodsConf.getText("CacheJar");
0974:                        cacheClassName = dodsConf.getText("CacheClassName");
0975:                        if (cacheClassPath != null && cacheClassName != null) {
0976:                            MultiClassLoader loader = new MultiClassLoader(null);
0977:                            loader.setClassPath(cacheClassPath);
0978:                            Class cacheClass = loader.loadClass(cacheClassName);
0979:                            cache = (DataStructCache) cacheClass.newInstance();
0980:                            cache = cache.newInstance();
0981:                        } else {
0982:                            cache = new QueryCacheImpl();
0983:                        }
0984:                    } catch (Exception e) {
0985:                    }
0986:                    if (cache == null) {
0987:                        cache = new QueryCacheImpl();
0988:                    }
0989:                    readCacheConfiguration(get_logicalDBName());
0990:                    get_statistics(); // set statistics
0991:                    refreshCache();
0992:                } catch (Exception e) {
0993:                    // cannot throw from static block
0994:                }
0995:            }
0996:
0997:            /**
0998:             * This method is invoked whenever object needs to be loaded from database.
0999:             *
1000:             * @exception DataObjectException If a data access error occurs.
1001:             */
1002:            public void refresh() throws DataObjectException {
1003:                try {
1004:                    loadData();
1005:                } catch (Exception e) {
1006:                    throw new DataObjectException(
1007:                            "Unable to load data for PersonDO id=" + get_OId()
1008:                                    + ", error = ", e);
1009:                }
1010:            }
1011:
1012:            /**
1013:             * This method is invoked whenever objects needs to be loaded from database.
1014:             *
1015:             * @param DOs Array of DOs which will be red from database.
1016:             *
1017:             * @exception DataObjectException If a data access error occurs.
1018:             */
1019:            public static void refresh(PersonDO[] DOs)
1020:                    throws DataObjectException {
1021:                for (int i = 0; i < DOs.length; i++)
1022:                    DOs[i].refresh();
1023:            }
1024:
1025:            /**
1026:             * Refresh
1027:             *
1028:             * @exception QueryException If a data access error occurs.
1029:             */
1030:            public static void refresh(String querySnt) throws QueryException {
1031:                try {
1032:                    QueryBuilder qb = new QueryBuilder();
1033:                    qb.select(PersonDO.PrimaryKey);
1034:                    qb.addWhere(querySnt);
1035:                    BigDecimal objId;
1036:                    String handle;
1037:                    String database = get_logicalDBName();
1038:                    RDBRow row;
1039:                    try {
1040:                        while (null != (row = qb.getNextRow())) {
1041:                            objId = row.get(PersonDO.PrimaryKey)
1042:                                    .getBigDecimal();
1043:                            handle = objId.toString();
1044:                            removeFromCache(database, handle);
1045:                        }
1046:                    } catch (Exception e) {
1047:                        throw new QueryException(" Query Exception occured,");
1048:                    }
1049:                } catch (Exception ex) {
1050:                    System.out
1051:                            .println("Error in refresh(String) of DO object.");
1052:                }
1053:            }
1054:
1055:            /**
1056:             * createVirgin()
1057:             * Creates a DO that has no ObjectId or data.
1058:             * Such a DO is used to insert a new database entry
1059:             * after its data has been set.
1060:             *
1061:             * @return Created data object.
1062:             *
1063:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1064:             *   If an object's id can't be allocated for this object.
1065:             * @exception DatabaseManagerException
1066:             *   If a connection to the database cannot be established, etc.
1067:             *
1068:
1069:             */
1070:            public static PersonDO createVirgin()
1071:                    throws DatabaseManagerException, ObjectIdException {
1072:                return new PersonDO();
1073:            }
1074:
1075:            /**
1076:             * createVirgin(DBTransaction)
1077:             * @param dbTrans The current database transaction
1078:             * @return Created data object.
1079:             *
1080:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1081:             *   If an object's id can't be allocated for this object.
1082:             * @exception DatabaseManagerException
1083:             *   If a connection to the database cannot be established, etc.
1084:             */
1085:            public static PersonDO createVirgin(DBTransaction dbTrans)
1086:                    throws DatabaseManagerException, ObjectIdException {
1087:                return new PersonDO(dbTrans);
1088:            }
1089:
1090:            /**
1091:             * createExisting( BigDecimal )
1092:             *
1093:             * Factory method creates a PersonDO object by searching for it
1094:             * in the database using the passed BigDecimal value as the primary key.
1095:             *
1096:             * Creates a DO that represents an existing entry in the database.
1097:             * Such a DO is used to examine and possibly update such an entry.
1098:             * createExisting() is called only from the code that retrieves
1099:             * an ObjectId from a ResultSet (database query result).
1100:             * createExisting() is protected because no other DO or BO should ever
1101:             * need to call it.
1102:             * FIX unfortunately the createExisting(BigDecimal) form *does* need
1103:             * to be public because it is called by the public ctors of other DOs.
1104:             * For example:
1105:             * AaaDO contains a ref to a BbbDO,
1106:             * so there is a method AaaDO.setBbb(BbbDO).
1107:             * In the ctor AaaDO(ResultSet), we have the call
1108:             * setBbb( BbbDO.createExisting( rs.getBigDecimal( "bbb")));
1109:             * Since AaaDO is not in the same package as BbbDO,
1110:             * BbbDO.createExisting(BigDecimal) must be public, not protected.
1111:             * Java needs the C++ 'friend' idea.
1112:             *
1113:             * @param bd The BigDecimal representation of the ObjectId for the object.
1114:             *
1115:             * @return Created PersonDO object.
1116:             *
1117:             * @exception DataObjectException
1118:             *   If the object is not found in the database.
1119:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1120:             *   If an object's id can't be allocated for this object.
1121:             * @exception DatabaseManagerException
1122:             *   If a connection to the database cannot be established, etc.
1123:             * @exception SQLException
1124:             *   If the database rejects the SQL generated to retrieve data
1125:             *   for this object, or if the table contains a bad foreign key, etc.
1126:
1127:             */
1128:            public static PersonDO createExisting(BigDecimal bd)
1129:                    throws SQLException, ObjectIdException,
1130:                    DataObjectException, DatabaseManagerException {
1131:                if (null == bd)
1132:                    return null;
1133:                return createExisting(new ObjectId(bd));
1134:            }
1135:
1136:            /**
1137:             * createExisting( BigDecimal, DBTransaction )
1138:             *
1139:             * @param bd The BigDecimal representation of the ObjectId for the object.
1140:             *
1141:             * @param dbTrans The current database transaction.
1142:             *
1143:             * @return Created PersonDO object.
1144:             *
1145:             * @exception DataObjectException
1146:             *   If the object is not found in the database.
1147:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1148:             *   If an object's id can't be allocated for this object.
1149:             * @exception DatabaseManagerException
1150:             *   If a connection to the database cannot be established, etc.
1151:             * @exception SQLException
1152:             *   If the database rejects the SQL generated to retrieve data
1153:             *   for this object, or if the table contains a bad foreign key, etc.
1154:             */
1155:            public static PersonDO createExisting(BigDecimal bd,
1156:                    DBTransaction dbTrans) throws SQLException,
1157:                    ObjectIdException, DataObjectException,
1158:                    DatabaseManagerException {
1159:                if (null == bd)
1160:                    return null;
1161:                return createExisting(new ObjectId(bd), dbTrans);
1162:            }
1163:
1164:            /**
1165:             * createExisting( BigDecimal, HashMap, DBTransaction )
1166:             *
1167:             * @param bd The BigDecimal representation of the ObjectId for the object.
1168:             *
1169:             * @param queryRefs HashMap Created referenced DO's (key datamaseName.Oid)
1170:             *
1171:             * @param dbTrans The current database transaction.
1172:             *
1173:             * @return Created PersonDO object.
1174:             *
1175:             * @exception DataObjectException
1176:             *   If the object is not found in the database.
1177:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1178:             *   If an object's id can't be allocated for this object.
1179:             * @exception DatabaseManagerException
1180:             *   If a connection to the database cannot be established, etc.
1181:             * @exception SQLException
1182:             *   If the database rejects the SQL generated to retrieve data
1183:             *   for this object, or if the table contains a bad foreign key, etc.
1184:             */
1185:            public static PersonDO createExisting(BigDecimal bd,
1186:                    HashMap queryRefs, DBTransaction dbTrans)
1187:                    throws SQLException, ObjectIdException,
1188:                    DataObjectException, DatabaseManagerException {
1189:                if (null == bd)
1190:                    return null;
1191:                return createExisting(new ObjectId(bd), queryRefs, dbTrans);
1192:            }
1193:
1194:            /**
1195:             * createExisting( String )
1196:             *
1197:             * The createExisting method is used to create a <CODE>PersonDO</CODE>
1198:             * from a string handle.
1199:             *
1200:             * @param handle String representation of the ObjectId for the object.
1201:             *
1202:             * @return Created PersonDO object.
1203:
1204:             */
1205:            public static PersonDO createExisting(String handle) {
1206:                PersonDO ret = null;
1207:                try {
1208:                    BigDecimal bd = new BigDecimal(handle);
1209:                    ret = createExisting(bd);
1210:                } catch (Exception e) {
1211:                }
1212:                return ret;
1213:            }
1214:
1215:            /**
1216:             * createExisting( String, DBTransaction )
1217:             *
1218:             * The createExisting method is used to create a <CODE>PersonDO</CODE>
1219:             * from a string handle.
1220:             *
1221:             * @param handle String representation of the ObjectId for the object.
1222:             * @param dbTrans The current database transaction
1223:             * @return Created PersonDO object.
1224:             */
1225:            public static PersonDO createExisting(String handle,
1226:                    DBTransaction dbTrans) {
1227:                PersonDO ret = null;
1228:                try {
1229:                    BigDecimal bd = new BigDecimal(handle);
1230:                    ret = createExisting(bd, dbTrans);
1231:                } catch (Exception e) {
1232:                }
1233:                return ret;
1234:            }
1235:
1236:            /**
1237:             * createExisting( ObjectId , DBTransaction)
1238:             *
1239:             * Factory method creates a PersonDO object by searching for it
1240:             * in the database using the passed ObjectID value as the primary key.
1241:             *
1242:             * @param id The ObjectId for the object.
1243:             * @param dbTrans The current database transaction.
1244:             * @return Created PersonDO object.
1245:             *
1246:             * @exception DataObjectException
1247:             *   If the object is not found in the database.
1248:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1249:             *   If an object's id can't be allocated for this object.
1250:             * @exception DatabaseManagerException
1251:             *   If a connection to the database cannot be established, etc.
1252:             * @exception SQLException
1253:             *   If the database rejects the SQL generated to retrieve data
1254:             *   for this object, or if the table contains a bad foreign key, etc.
1255:             */
1256:            protected static PersonDO createExisting(ObjectId id,
1257:                    DBTransaction dbTrans) throws SQLException,
1258:                    ObjectIdException, DataObjectException,
1259:                    DatabaseManagerException {
1260:                if (null == id)
1261:                    return null;
1262:                return createExisting(id, null, dbTrans);
1263:            }
1264:
1265:            /**
1266:             * createExisting( ObjectId , HashMap queryRefs, DBTransaction)
1267:             *
1268:             * Factory method creates a PersonDO object by searching for it
1269:             * in the database using the passed ObjectID value as the primary key.
1270:             *
1271:             * @param id The ObjectId for the object.
1272:             * @param queryRefs HashMap of available references.
1273:             * @param dbTrans The current database transaction.
1274:             * @return Created PersonDO object.
1275:             *
1276:             * @exception DataObjectException
1277:             *   If the object is not found in the database.
1278:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1279:             *   If an object's id can't be allocated for this object.
1280:             * @exception DatabaseManagerException
1281:             *   If a connection to the database cannot be established, etc.
1282:             * @exception SQLException
1283:             *   If the database rejects the SQL generated to retrieve data
1284:             *   for this object, or if the table contains a bad foreign key, etc.
1285:             */
1286:            protected static PersonDO createExisting(ObjectId id,
1287:                    HashMap queryRefs, DBTransaction dbTrans)
1288:                    throws SQLException, ObjectIdException,
1289:                    DataObjectException, DatabaseManagerException {
1290:                if (null == id)
1291:                    return null;
1292:                String cacheHandle = get_logicalDBName() + "." + id.toString();
1293:                PersonDO ret = null;
1294:                PersonDataStruct data = null;
1295:                if (queryRefs == null)
1296:                    queryRefs = new HashMap();
1297:                if (queryRefs.containsKey(cacheHandle)) {
1298:                    ret = (PersonDO) queryRefs.get(cacheHandle);
1299:                    return ret;
1300:                }
1301:                if (dbTrans != null
1302:                        && _tr_(dbTrans).getTransactionCache() != null) {
1303:                    ret = (PersonDO) _tr_(dbTrans).getTransactionCache()
1304:                            .getDOByHandle(cacheHandle);
1305:                    if (ret != null)
1306:                        return ret;
1307:                }
1308:                if (null != ret)
1309:                    return ret;
1310:                data = (PersonDataStruct) findCachedObjectByHandle(cacheHandle);
1311:                if (data != null) {
1312:                    ret = (PersonDO) createDO(data.get_OId(), dbTrans);
1313:                    if (ret != null) {
1314:                        ret.originalData_set(data);
1315:                        ret.setPersistent(true);
1316:                    }
1317:                    return ret;
1318:                }
1319:                // 14.XI        if(dbTrans!=null)
1320:                ret = new PersonDO(id, dbTrans);
1321:                // 14.XI        else
1322:                // 14.XI            ret = new PersonDO( id );
1323:                ret.setPersistent(true); // mark DO as persistent (preexisting)
1324:                /*14.XI
1325:                 if(queryRefs==null)
1326:                 queryRefs = new HashMap();
1327:                 if(queryRefs.containsKey(cacheHandle)) {
1328:                 ret = (PersonDO)queryRefs.get(cacheHandle);
1329:                 return ret;
1330:                 }
1331:                 14.XI */
1332:
1333:                if (queryRefs != null) {
1334:                    ret.set_refs(queryRefs);
1335:                    ret.addRefs(cacheHandle, ret);
1336:                }
1337:                if (!cache.getTableConfiguration().isLazyLoading()) { // If not lazy-loading, fetch DO data now.
1338:                    ret.loadData();
1339:                } else {
1340:                    statistics.incrementLazyLoadingNum();
1341:                }
1342:                // unset the GenericDO.dirty flag.
1343:                ret.markClean();
1344:
1345:                return ret;
1346:            }
1347:
1348:            /**
1349:             * createExisting( ObjectId )
1350:             *
1351:             * Factory method creates a PersonDO object by searching for it
1352:             * in the database using the passed ObjectID value as the primary key.
1353:             *
1354:             * @param id The ObjectId for the object.
1355:             *
1356:             * @return Created PersonDO object.
1357:             *
1358:             * @exception DataObjectException
1359:             *   If the object is not found in the database.
1360:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1361:             *   If an object's id can't be allocated for this object.
1362:             * @exception DatabaseManagerException
1363:             *   If a connection to the database cannot be established, etc.
1364:             * @exception SQLException
1365:             *   If the database rejects the SQL generated to retrieve data
1366:             *   for this object, or if the table contains a bad foreign key, etc.
1367:
1368:             */
1369:            protected static PersonDO createExisting(ObjectId id)
1370:                    throws SQLException, ObjectIdException,
1371:                    DataObjectException, DatabaseManagerException {
1372:                if (null == id)
1373:                    return null;
1374:                return createExisting(id, null);
1375:            }
1376:
1377:            /**
1378:             * createExisting( ResultSet )
1379:             *
1380:             * Factory method used to create an instance of this class to
1381:             * represent a Data Object already existing in the database.
1382:             *
1383:             * @param rs The ResultSet returned by the Query class for
1384:             * an existing Data Object stored in the database.
1385:             *
1386:             * @return Created PersonDO object.
1387:             *
1388:             * @exception DataObjectException
1389:             *   If the object is not found in the database.
1390:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1391:             *   If an object's id can't be allocated for this object.
1392:             * @exception DatabaseManagerException
1393:             *   If a connection to the database cannot be established, etc.
1394:             * @exception SQLException
1395:             *   If the database rejects the SQL generated to retrieve data
1396:             *   for this object, or if the table contains a bad foreign key, etc.
1397:
1398:             */
1399:            protected static PersonDO createExisting(ResultSet rs)
1400:                    throws SQLException, ObjectIdException,
1401:                    DataObjectException, DatabaseManagerException {
1402:                if (null == rs)
1403:                    return null;
1404:                PersonDO ret = null;
1405:                if (notUsingOId) {
1406:                    ret = new PersonDO();
1407:                    ret.initFromResultSet(rs);
1408:                } else {
1409:                    ret = new PersonDO(rs);
1410:                }
1411:                return ret;
1412:            }
1413:
1414:            /**
1415:             * createExisting( ResultSet, DBTransaction )
1416:             *
1417:             * @param rs The ResultSet returned by the Query class for
1418:             * an existing Data Object stored in the database.
1419:             * @param dbTrans The current database transaction
1420:             * @return Created PersonDO object.
1421:             *
1422:             * @exception DataObjectException
1423:             *   If the object is not found in the database.
1424:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1425:             *   If an object's id can't be allocated for this object.
1426:             * @exception DatabaseManagerException
1427:             *   If a connection to the database cannot be established, etc.
1428:             * @exception SQLException
1429:             *   If the database rejects the SQL generated to retrieve data
1430:             *   for this object, or if the table contains a bad foreign key, etc.
1431:             */
1432:            protected static PersonDO createExisting(ResultSet rs,
1433:                    DBTransaction dbTrans) throws SQLException,
1434:                    ObjectIdException, DataObjectException,
1435:                    DatabaseManagerException {
1436:                if (null == rs)
1437:                    return null;
1438:                PersonDO ret = null;
1439:                if (notUsingOId) {
1440:                    ret = new PersonDO(dbTrans);
1441:                    ret.initFromResultSet(rs);
1442:                } else {
1443:                    ret = new PersonDO(rs, dbTrans);
1444:                }
1445:                return ret;
1446:            }
1447:
1448:            /**
1449:             * createExisting( ResultSet , HashMap)
1450:             *
1451:             * Factory method used to create an instance of this class to
1452:             * represent a Data Object already existing in the database.
1453:             *
1454:             * @param rs The ResultSet returned by the Query class for
1455:             * an existing Data Object stored in the database.
1456:             * @param queryRefs list of created refernce objects.
1457:             *
1458:             * @return Created PersonDO object.
1459:             *
1460:             * @exception DataObjectException
1461:             *   If the object is not found in the database.
1462:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1463:             *   If an object's id can't be allocated for this object.
1464:             * @exception DatabaseManagerException
1465:             *   If a connection to the database cannot be established, etc.
1466:             * @exception SQLException
1467:             *   If the database rejects the SQL generated to retrieve data
1468:             *   for this object, or if the table contains a bad foreign key, etc.
1469:
1470:             */
1471:            protected static PersonDO createExisting(ResultSet rs,
1472:                    HashMap queryRefs) throws SQLException, ObjectIdException,
1473:                    DataObjectException, DatabaseManagerException {
1474:                if (null == rs)
1475:                    return null;
1476:                PersonDO ret = null;
1477:                if (notUsingOId) {
1478:                    ret = new PersonDO();
1479:                    ret.set_refs(queryRefs);
1480:                    ret.initFromResultSet(rs);
1481:                } else {
1482:                    ret = new PersonDO(rs, queryRefs);
1483:                }
1484:                return ret;
1485:            }
1486:
1487:            /**
1488:             * createExisting( ResultSet , HashMap, DBTransaction)
1489:             *
1490:             * @param rs The ResultSet returned by the Query class for
1491:             * an existing Data Object stored in the database.
1492:             * @param queryRefs list of created refernce objects.
1493:             * @param dbTrans The current database transaction
1494:             * @return Created PersonDO object.
1495:             *
1496:             * @exception DataObjectException
1497:             *   If the object is not found in the database.
1498:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1499:             *   If an object's id can't be allocated for this object.
1500:             * @exception DatabaseManagerException
1501:             *   If a connection to the database cannot be established, etc.
1502:             * @exception SQLException
1503:             *   If the database rejects the SQL generated to retrieve data
1504:             *   for this object, or if the table contains a bad foreign key, etc.
1505:             */
1506:            protected static PersonDO createExisting(ResultSet rs,
1507:                    HashMap queryRefs, DBTransaction dbTrans)
1508:                    throws SQLException, ObjectIdException,
1509:                    DataObjectException, DatabaseManagerException {
1510:                if (null == rs)
1511:                    return null;
1512:                PersonDO ret = null;
1513:                if (notUsingOId) {
1514:                    ret = new PersonDO(dbTrans);
1515:                    ret.set_refs(queryRefs);
1516:                    ret.initFromResultSet(rs);
1517:                } else {
1518:                    if (queryRefs == null)
1519:                        queryRefs = new HashMap();
1520:                    String cacheHandle = get_logicalDBName() + "."
1521:                            + rs.getBigDecimal(get_OIdColumnName());
1522:                    if (queryRefs.containsKey(cacheHandle)) {
1523:                        ret = (PersonDO) queryRefs.get(cacheHandle);
1524:                        if (!ret.isLoaded()) {
1525:                            ret.set_refs(queryRefs);
1526:                            ret.initFromResultSet(rs);
1527:                        }
1528:                        return ret;
1529:                    }
1530:                    ret = new PersonDO(rs, queryRefs, dbTrans);
1531:                }
1532:                return ret;
1533:            }
1534:
1535:            /**
1536:             * createExisting( RDBRow )
1537:             *
1538:             * Factory method creates a PersonDO object by searching for it
1539:             * in the database using the PersonDO.PrimaryKey value
1540:             * in the passed RDBRow.
1541:             *
1542:             * @param RDBRow A row returned by QueryBuilder.getNextRow().
1543:             *
1544:             * @return Created PersonDO object.
1545:             *
1546:             * @exception DataObjectException
1547:             *   If the RDBRow does not contain a PersonDO.PrimaryKey.
1548:             *   If the object is not found in the database.
1549:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1550:             *   If an object's id can't be allocated for this object.
1551:             * @exception DatabaseManagerException
1552:             *   If a connection to the database cannot be established, etc.
1553:             * @exception SQLException
1554:             *   If the database rejects the SQL generated to retrieve data
1555:             *   for this object, or if the table contains a bad foreign key, etc.
1556:
1557:             */
1558:            protected static PersonDO createExisting(RDBRow row)
1559:                    throws SQLException, ObjectIdException,
1560:                    DataObjectException, DatabaseManagerException {
1561:                if (null == row)
1562:                    return null;
1563:                RDBColumnValue pk = null;
1564:                try {
1565:                    pk = row.get(PersonDO.PrimaryKey);
1566:                    return createExisting(pk);
1567:                } catch (Exception e) {
1568:                    throw new DataObjectException(
1569:                            "Cannot create PersonDO, row does not "
1570:                                    + "contain PersonDO primary key.");
1571:                }
1572:            }
1573:
1574:            /**
1575:             * createExisting( RDBRow , DBTransaction)
1576:             *
1577:             * Factory method creates a PersonDO object by searching for it
1578:             * in the database using the PersonDO.PrimaryKey value
1579:             * in the passed RDBRow.
1580:             *
1581:             * @param RDBRow A row returned by QueryBuilder.getNextRow().
1582:             * @param DBTransaction The current database transaction
1583:             * @return Created PersonDO object.
1584:             *
1585:             * @exception DataObjectException
1586:             *   If the RDBRow does not contain a PersonDO.PrimaryKey.
1587:             *   If the object is not found in the database.
1588:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1589:             *   If an object's id can't be allocated for this object.
1590:             * @exception DatabaseManagerException
1591:             *   If a connection to the database cannot be established, etc.
1592:             * @exception SQLException
1593:             *   If the database rejects the SQL generated to retrieve data
1594:             *   for this object, or if the table contains a bad foreign key, etc.
1595:             */
1596:            protected static PersonDO createExisting(RDBRow row,
1597:                    DBTransaction dbTrans) throws SQLException,
1598:                    ObjectIdException, DataObjectException,
1599:                    DatabaseManagerException {
1600:                if (null == row)
1601:                    return null;
1602:                RDBColumnValue pk = null;
1603:                try {
1604:                    pk = row.get(PersonDO.PrimaryKey);
1605:                    return createExisting(pk, dbTrans);
1606:                } catch (Exception e) {
1607:                    throw new DataObjectException(
1608:                            "Cannot create PersonDO, row does not "
1609:                                    + "contain PersonDO primary key.");
1610:                }
1611:            }
1612:
1613:            /**
1614:             * createExisting( RDBColumnValue )
1615:             *
1616:             * Factory method creates a PersonDO object by searching for it
1617:             * in the database using the passed PersonDO.PrimaryKey.
1618:             *
1619:             * @param RDBColumnValue a PrimaryKey column value from a row
1620:             * that was returned by QueryBuilder.getNextRow().
1621:             *
1622:             * @return Created PersonDO object.
1623:             *
1624:             * @exception DataObjectException
1625:             *   If the RDBColumnValue does not contain a PersonDO.PrimaryKey.
1626:             *   If the object is not found in the database.
1627:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1628:             *   If an object's id can't be allocated for this object.
1629:             * @exception DatabaseManagerException
1630:             *   If a connection to the database cannot be established, etc.
1631:             * @exception SQLException
1632:             *   If the database rejects the SQL generated to retrieve data
1633:             *   for this object, or if the table contains a bad foreign key, etc.
1634:
1635:             */
1636:            protected static PersonDO createExisting(RDBColumnValue pk)
1637:                    throws SQLException, ObjectIdException,
1638:                    DataObjectException, DatabaseManagerException {
1639:                if (null == pk)
1640:                    return null;
1641:                if (!pk.equals(PersonDO.PrimaryKey))
1642:                    throw new DataObjectException("Cannot create PersonDO, "
1643:                            + "RDBColumnValue is not PersonDO.PrimaryKey.");
1644:                BigDecimal bd = null;
1645:                try {
1646:                    bd = pk.getBigDecimal();
1647:                } catch (Exception e) {
1648:                    throw new DataObjectException(
1649:                            "Cannot create PersonDO, bad primary key.");
1650:                }
1651:                if (null == bd)
1652:                    return null;
1653:                return createExisting(bd);
1654:            }
1655:
1656:            /**
1657:             * createExisting( RDBColumnValue, DBTransaction )
1658:             *
1659:             * Factory method creates a PersonDO object by searching for it
1660:             * in the database using the passed PersonDO.PrimaryKey.
1661:             *
1662:             * @param RDBColumnValue a PrimaryKey column value from a row
1663:             * that was returned by QueryBuilder.getNextRow().
1664:             *
1665:             * @return Created PersonDO object.
1666:             *
1667:             * @exception DataObjectException
1668:             *   If the RDBColumnValue does not contain a PersonDO.PrimaryKey.
1669:             *   If the object is not found in the database.
1670:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1671:             *   If an object's id can't be allocated for this object.
1672:             * @exception DatabaseManagerException
1673:             *   If a connection to the database cannot be established, etc.
1674:             * @exception SQLException
1675:             *   If the database rejects the SQL generated to retrieve data
1676:             *   for this object, or if the table contains a bad foreign key, etc.
1677:             */
1678:            protected static PersonDO createExisting(RDBColumnValue pk,
1679:                    DBTransaction dbTrans) throws SQLException,
1680:                    ObjectIdException, DataObjectException,
1681:                    DatabaseManagerException {
1682:                if (null == pk)
1683:                    return null;
1684:                if (!pk.equals(PersonDO.PrimaryKey))
1685:                    throw new DataObjectException("Cannot create PersonDO, "
1686:                            + "RDBColumnValue is not PersonDO.PrimaryKey.");
1687:                BigDecimal bd = null;
1688:                try {
1689:                    bd = pk.getBigDecimal();
1690:                } catch (Exception e) {
1691:                    throw new DataObjectException(
1692:                            "Cannot create PersonDO, bad primary key.");
1693:                }
1694:                if (null == bd)
1695:                    return null;
1696:                return createExisting(bd, dbTrans);
1697:            }
1698:
1699:            /**
1700:             * Creates a DO that has no ObjectId
1701:             * but has a copy of an existing DO's data.
1702:             * Such a DO is used to insert a new database entry
1703:             * that is largely similar to an existing entry.
1704:             *
1705:             * @param data The data struct to copy values from.
1706:             *
1707:             * @return Created PersonDO object.
1708:             *
1709:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1710:             *   If an object's id can't be allocated for this object.
1711:             * @exception DatabaseManagerException
1712:             *   If a connection to the database cannot be established, etc.
1713:
1714:             */
1715:            public static PersonDO createCopy(PersonDataStruct data)
1716:                    throws DatabaseManagerException, ObjectIdException {
1717:                PersonDO ret = new PersonDO(true);
1718:                ret.originalData_set(data);
1719:                return ret;
1720:            }
1721:
1722:            /**
1723:             * Creates a DO that has no ObjectId
1724:             * but has a copy of an existing DO's data.
1725:             * Such a DO is used to insert a new database entry
1726:             * that is largely similar to an existing entry.
1727:             *
1728:             * @param data The data struct to copy values from.
1729:             * @param dbTrans The current database transaction
1730:             * @return Created PersonDO object.
1731:             *
1732:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1733:             *   If an object's id can't be allocated for this object.
1734:             * @exception DatabaseManagerException
1735:             *   If a connection to the database cannot be established, etc.
1736:             */
1737:            public static PersonDO createCopy(PersonDataStruct data,
1738:                    DBTransaction dbTrans) throws DatabaseManagerException,
1739:                    ObjectIdException {
1740:                PersonDO ret = new PersonDO(true, dbTrans);
1741:                ret.originalData_set(data);
1742:                ret.markClean();
1743:                return ret;
1744:            }
1745:
1746:            /**
1747:             * Creates a DO that has no ObjectId
1748:             * but has a copy of an existing DO's data.
1749:             * Such a DO is used to insert a new database entry
1750:             * that is largely similar to an existing entry.
1751:             *
1752:             * @param orig The original DO to copy.
1753:             *
1754:             * @return Created PersonDO object.
1755:             *
1756:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1757:             *   If an object's id can't be allocated for this object.
1758:             * @exception DatabaseManagerException
1759:             *   If a connection to the database cannot be established, etc.
1760:             */
1761:            public static PersonDO createCopy(PersonDO orig)
1762:                    throws DatabaseManagerException, ObjectIdException {
1763:                if (null == orig)
1764:                    return null;
1765:                PersonDO ret = new PersonDO(true);
1766:                if (null != orig.originalData_get()) {
1767:                    ret.originalData_set(orig.originalData_get());
1768:                    ret.markClean();
1769:                    ret.transaction = orig.transaction;
1770:                    ret.setPersistent(orig.isPersistent());
1771:                }
1772:                return ret;
1773:            }
1774:
1775:            /**
1776:             *
1777:             * @param orig The original DO to copy.
1778:             * @param dbTrans The current database transaction
1779:             * @return Created PersonDO object.
1780:             *
1781:             * @exception com.lutris.appserver.server.sql.ObjectIdException
1782:             *   If an object's id can't be allocated for this object.
1783:             * @exception DatabaseManagerException
1784:             *   If a connection to the database cannot be established, etc.
1785:             */
1786:            public static PersonDO createCopy(PersonDO orig,
1787:                    DBTransaction dbTrans) throws DatabaseManagerException,
1788:                    ObjectIdException {
1789:                if (null == orig)
1790:                    return null;
1791:                PersonDO ret = new PersonDO(true, dbTrans);
1792:                if (null != orig.originalData_get()) {
1793:                    ret.originalData_set(orig.originalData_get());
1794:                    ret.markClean();
1795:                    ret.setPersistent(orig.isPersistent());
1796:                }
1797:                return ret;
1798:
1799:            }
1800:
1801:            /**
1802:             * Causes the DO to refresh itself from the database
1803:             * the next time a set or get method is called.
1804:             */
1805:            public void reload() {
1806:                originalData = data = null;
1807:            }
1808:
1809:            /**
1810:             * The methods <CODE>
1811:             *     getHandle
1812:             *     hasMatchingHandle
1813:
1814:             *     findCachedObjectByHandle
1815:
1816:             * </CODE> are used by Presentation Objects that need to populate
1817:             * HTML select lists with Data Objects as options.
1818:             * The <CODE>getHandle()</CODE> method is used
1819:             * to set the value for each option,
1820:             * and the <CODE>hasMatchingHandle()<CODE>
1821:
1822:             * methods are used to lookup the Data Object when the selection has
1823:             * been made.
1824:             *
1825:             * @exception DatabaseManagerException
1826:             *   If a connection to the database cannot be established, etc.
1827:             *
1828:             * @return id of this DO as a string
1829:             *   If an object's id can't be allocated for this object.
1830:             * @deprecated Use get_Handle() instead.     
1831:             */
1832:            public String getHandle() throws DatabaseManagerException {
1833:                return get_Handle();
1834:            }
1835:
1836:            /**
1837:             * The methods <CODE>
1838:             *     get_Handle
1839:             *     hasMatchingHandle
1840:
1841:             *     findCachedObjectByHandle
1842:
1843:             * </CODE> are used by Presentation Objects that need to populate
1844:             * HTML select lists with Data Objects as options.
1845:             * The <CODE>get_Handle()</CODE> method is used
1846:             * to set the value for each option,
1847:             * and the <CODE>hasMatchingHandle()<CODE>
1848:
1849:             * methods are used to lookup the Data Object when the selection has
1850:             * been made.
1851:             *
1852:             * @exception DatabaseManagerException
1853:             *   If a connection to the database cannot be established, etc.
1854:             *
1855:             * @return id of this DO as a string
1856:             *   If an object's id can't be allocated for this object.
1857:             */
1858:            public String get_Handle() throws DatabaseManagerException {
1859:                String ret = null;
1860:                if (null == get_OId())
1861:                    throw new DatabaseManagerException("ID not set ");
1862:                ret = get_OId().toString();
1863:                return ret;
1864:            }
1865:
1866:            /**
1867:             * Returns cache handle.
1868:             *
1869:             * @return cache handle.
1870:             * @exception DatabaseManagerException
1871:             *   If a connection to the database cannot be established, etc.
1872:             */
1873:            public String get_CacheHandle() throws DatabaseManagerException {
1874:                String ret = get_OriginDatabase() + "." + get_Handle();
1875:                return ret;
1876:            }
1877:
1878:            /**
1879:             * Created DO with specified OID.
1880:             *
1881:             * @param obj DO which will be copied.
1882:             * @return copy of DO (with the same id).
1883:
1884:             */
1885:            public static GenericDO createDO(ObjectId oid)
1886:                    throws java.sql.SQLException,
1887:                    com.lutris.appserver.server.sql.ObjectIdException,
1888:                    com.lutris.dods.builder.generator.query.DataObjectException,
1889:                    com.lutris.appserver.server.sql.DatabaseManagerException {
1890:                return new PersonDO(oid);
1891:            }
1892:
1893:            /**
1894:             * Created DO with specified OID.
1895:             *
1896:             * @param obj DO which will be copied.
1897:             * @param dbTrans The current database transaction.
1898:             * @return copy of DO (with the same id).
1899:             */
1900:            public static GenericDO createDO(ObjectId oid, DBTransaction dbTrans)
1901:                    throws java.sql.SQLException,
1902:                    com.lutris.appserver.server.sql.ObjectIdException,
1903:                    com.lutris.dods.builder.generator.query.DataObjectException,
1904:                    com.lutris.appserver.server.sql.DatabaseManagerException {
1905:                return new PersonDO(oid, dbTrans);
1906:            }
1907:
1908:            /**
1909:             * Compare string version of the id of this DO and handle.
1910:             *
1911:             * @param handle
1912:             *   <CODE>String</CODE> version of DO id.
1913:             *
1914:             * @return boolean
1915:             *   True if the string version of the id of this DO matches passed handle.
1916:             *
1917:             * @see get_Handle
1918:             */
1919:            public boolean hasMatchingHandle(String handle) {
1920:                boolean ret = false;
1921:                if (null == get_OId())
1922:                    return false;
1923:                else {
1924:                    String this Hnadle = get_OId().toString();
1925:                    ret = this Hnadle.equals(handle);
1926:                }
1927:                return ret;
1928:            }
1929:
1930:            /**
1931:             * Get data object with key cacheHandle from the cache.
1932:             *
1933:             * @param cacheHandle
1934:             *   <CODE>String</CODE> version of concatenation of:
1935:             * name of the data object's database, followed by '.', followed by
1936:             * data object's id.
1937:             *
1938:             * @return <CODE>PersonDO</CODE>
1939:             *   Object if one is found in cache, otherwise null.
1940:             *
1941:             * @see get_Handle
1942:             */
1943:            public PersonDO findTransactionCachedObjectByHandle(
1944:                    String cacheHandle) {
1945:                if (null == cacheHandle)
1946:                    return null;
1947:                if (get_transaction() != null
1948:                        && _tr_(get_transaction()).getTransactionCache() != null)
1949:                    return (PersonDO) _tr_(get_transaction())
1950:                            .getTransactionCache().getDOByHandle(cacheHandle);
1951:                else
1952:                    return null;
1953:            }
1954:
1955:            /**
1956:             * Get DataStruct object with key cacheHandle from the cache.
1957:             *
1958:             * @param cacheHandle
1959:             *   <CODE>String</CODE> version of concatenation of:
1960:             * name of the data object's database, followed by '.', followed by
1961:             * data object's id.
1962:             *
1963:             * @return <CODE>PersonDataStruct</CODE>
1964:             *   Object if one is found in cache, otherwise null.
1965:             *
1966:             * @see get_Handle
1967:             */
1968:            public static PersonDataStruct findCachedObjectByHandle(
1969:                    String cacheHandle) {
1970:                if (null == cacheHandle)
1971:                    return null;
1972:                return (PersonDataStruct) cache
1973:                        .getDataStructByHandle(cacheHandle);
1974:            }
1975:
1976:            /**
1977:             * Assigns the DataStruct of an existing DO to this DO.
1978:             * Does not duplicate data. Just assigns the reference.
1979:             *
1980:             * @param orig The original DO.
1981:             *
1982:             */
1983:            protected void makeIdentical(PersonDO orig) {
1984:                super .makeIdentical(orig);
1985:                originalData = orig.originalData;
1986:                data = orig.data;
1987:            }
1988:
1989:            /**
1990:             * @deprecated Use get_Version()
1991:             * @return Data object's version.
1992:             */
1993:            public int getVersion() {
1994:                return get_Version();
1995:            }
1996:
1997:            /**
1998:             * get_Version makes the protected method public in CoreDO.
1999:             *
2000:             * @return Data object's version.
2001:             */
2002:            public int get_Version() {
2003:                return (null != data) ? data.get_Version() : super 
2004:                        .get_Version();
2005:            }
2006:
2007:            /**
2008:             * getNewVersion overloaded
2009:             *
2010:             * @return Data object's version.
2011:             * @deprecated get_NewVersion()      
2012:             */
2013:            public int getNewVersion() {
2014:                if (null != data)
2015:                    return data.get_Version();
2016:                else
2017:                    return super .get_Version();
2018:            }
2019:
2020:            /**
2021:             * get_NewVersion overloaded
2022:             *
2023:             * @return Data object's version.
2024:             */
2025:            public int get_NewVersion() {
2026:                if (null != data)
2027:                    return data.get_Version();
2028:                else
2029:                    return super .get_Version();
2030:            }
2031:
2032:            /**
2033:             * setVersion overloaded
2034:             * @deprecated Use set_Version()
2035:             */
2036:            public void setVersion(int _ver) {
2037:                set_Version(_ver);
2038:            }
2039:
2040:            /**
2041:             * set_Version overloaded
2042:             *
2043:             */
2044:            public void set_Version(int _ver) {
2045:                if (_ver < get_Version()) {
2046:                    new Throwable("WOW, (" + get_OId() + ") oldVer:"
2047:                            + get_Version() + ", new one is " + _ver)
2048:                            .printStackTrace();
2049:                } else if (null != data)
2050:                    data.set_Version(_ver);
2051:                else
2052:                    super .set_Version(_ver);
2053:            }
2054:
2055:            /**
2056:             * setNewVersion overloaded
2057:             * @deprecated 
2058:             */
2059:            public void setNewVersion(int _ver) {
2060:            }
2061:
2062:            // WebDocWf extension for writeable fully cached objects
2063:            /**
2064:             * Mark the object as read-only.
2065:             *
2066:             * WebDocWf extension
2067:             *
2068:             */
2069:            public void makeReadOnly() {
2070:                if (null != data) {
2071:                    try {
2072:                        checkDup();
2073:                    } catch (Exception ex) {
2074:                        String trace = "";
2075:                        StackTraceElement[] traceElements = (new Throwable())
2076:                                .getStackTrace();
2077:                        for (int i = 0; i < traceElements.length; i++)
2078:                            trace += traceElements[i].toString() + "\n";
2079:                        DODS.getLogChannel().write(
2080:                                Logger.DEBUG,
2081:                                " MakeReadOnly failed: Database: "
2082:                                        + get_OriginDatabase()
2083:                                        + " PersonDO class, oid: " + get_OId()
2084:                                        + ", version: " + get_Version() + " \n"
2085:                                        + trace);
2086:                    }
2087:                }
2088:                data.readOnly = true;
2089:            }
2090:
2091:            /**
2092:             * Mark the object as read-write.
2093:             *
2094:             * WebDocWf extension
2095:             */
2096:            public void makeReadWrite() {
2097:                if (null != data) {
2098:                    try {
2099:                        checkDup();
2100:                    } catch (Exception ex) {
2101:                        String trace = "";
2102:                        StackTraceElement[] traceElements = (new Throwable())
2103:                                .getStackTrace();
2104:                        for (int i = 0; i < traceElements.length; i++)
2105:                            trace += traceElements[i].toString() + "\n";
2106:                        DODS.getLogChannel().write(
2107:                                Logger.DEBUG,
2108:                                " MakeReadWrite failed: Database: "
2109:                                        + get_OriginDatabase()
2110:                                        + " PersonDO class, oid: " + get_OId()
2111:                                        + ", version: " + get_Version() + " \n"
2112:                                        + trace);
2113:                    }
2114:                }
2115:                data.readOnly = false;
2116:            }
2117:
2118:            // end of WebDocWf extension for writeable fully cached objects
2119:
2120:            // WebDocWf extension for writeable fully cached objects
2121:
2122:            /**
2123:             * Set reference objects
2124:             *
2125:             */
2126:            private void set_refs(HashMap queryRefs) {
2127:                refs = queryRefs;
2128:            }
2129:
2130:            private Object getRefs(String key) {
2131:                if (get_transaction() != null
2132:                        && _tr_(get_transaction()).getTransactionCache() != null) {
2133:                    return _tr_(get_transaction()).getTransactionCache()
2134:                            .getDOByHandle(key);
2135:                } else if (null == refs) {
2136:                    refs = new HashMap();
2137:                    return null;
2138:                } else {
2139:                    return refs.get(key);
2140:                }
2141:            }
2142:
2143:            private void addRefs(String key, Object newRefs) {
2144:                if (null == refs) {
2145:                    refs = new HashMap();
2146:                }
2147:                refs.put(key, newRefs);
2148:            }
2149:
2150:            /**
2151:             * Get reference objects
2152:             *
2153:             */
2154:            private HashMap get_refs() {
2155:                return refs;
2156:            }
2157:
2158:            /**
2159:             * @deprecated Use get_OId()
2160:             * @return this object's identifier.
2161:             */
2162:            public ObjectId getOId() {
2163:                return get_OId();
2164:            }
2165:
2166:            /**
2167:             * Returns this object's identifier.
2168:             * @return this object's identifier.
2169:             */
2170:            public ObjectId get_OId() {
2171:                return get_DataStruct().get_OId();
2172:            }
2173:
2174:            /**
2175:             * @deprecated Use set_OId()
2176:             * @param oId this object's identifier.
2177:             */
2178:            protected void setOId(ObjectId _oId) {
2179:                set_OId(_oId);
2180:            }
2181:
2182:            /**
2183:             * Sets this object's identifier.
2184:             * @param oId this object's identifier.
2185:             */
2186:            protected void set_OId(ObjectId _oId) {
2187:                if (get_DataStruct() == null)
2188:                    originalData = new PersonDataStruct();
2189:                get_DataStruct().set_OId(_oId);
2190:            }
2191:
2192:            /**
2193:             * Creates a clone of the object, but ensures that
2194:             * a new and unique object id is created for the object
2195:             * and that the version number is set to zero.
2196:             * @exception DatabaseManagerException if an error occurs while
2197:             * allocation a new object id from the default logical database.
2198:             * @exception ObjectIdException if a new object id could not be
2199:             * allocated.
2200:             */
2201:            public synchronized Object cloneUnique()
2202:                    throws DatabaseManagerException, ObjectIdException {
2203:
2204:                PersonDO _clone = createVirgin(get_transaction());
2205:
2206:                try {
2207:                    PersonDataStruct toClone = (null != get_Data()) ? (PersonDataStruct) get_Data()
2208:                            : (PersonDataStruct) originalData_get();
2209:                    if (null != toClone) {
2210:                        _clone.set_Data(toClone.duplicate());
2211:                        ((PersonDataStruct) _clone.get_Data())
2212:                                .set_OId(((PersonDataStruct) _clone
2213:                                        .originalData_get()).get_OId());
2214:                        ((PersonDataStruct) _clone.get_Data()).set_Version(0);
2215:                        changedFlags_set(true);
2216:                    }
2217:                } catch (Exception e) {
2218:                    String trace = "";
2219:                    StackTraceElement[] traceElements = (new Throwable())
2220:                            .getStackTrace();
2221:                    for (int i = 0; i < traceElements.length; i++)
2222:                        trace += traceElements[i].toString() + "\n";
2223:                    DODS.getLogChannel().write(
2224:                            Logger.DEBUG,
2225:                            " cloneUnique failed: Database: "
2226:                                    + get_OriginDatabase()
2227:                                    + " PersonDO class, oid: " + get_OId()
2228:                                    + ", version: " + get_Version() + " \n"
2229:                                    + trace);
2230:                }
2231:                return _clone;
2232:            }
2233:
2234:            protected boolean deleted;
2235:
2236:            /**
2237:             * @return true if DO has been deleted, but not commited yet
2238:             */
2239:            public boolean isDeleted() {
2240:                return deleted;
2241:            }
2242:
2243:            /**
2244:             * @param flag true if DO has been deleted, but not commited yet
2245:             */
2246:            public void setDeleted(boolean flag) {
2247:                deleted = flag;
2248:            }
2249:
2250:            /**
2251:             * If transaction succeeded marks this object as clean.
2252:             * @param success true if the transaction succeeded
2253:             *   and this object was successfully inserted into the database.
2254:             */
2255:            public void finalizeInsert(boolean success) {
2256:                // on rollback reject inserted (createdVirgin) DO
2257:                if (!success && !isPersistent())
2258:                    setDeleted(true);
2259:                super .finalizeInsert(success);
2260:                if (success)
2261:                    syncStructs(true);
2262:            }
2263:
2264:            /**
2265:             * If transaction succeeded marks this object as clean.
2266:             * @param success true if the transaction succeeded
2267:             *   and this object was successfully updated in the database.
2268:             */
2269:            public void finalizeUpdate(boolean success) {
2270:                super .finalizeUpdate(success);
2271:                if (success)
2272:                    syncStructs(true);
2273:            }
2274:
2275:            /**
2276:             * Currently does nothing.
2277:             *
2278:             * @param success true if the transaction succeeded
2279:             *   and this object was successfully deleted from the
2280:             *   database.
2281:             */
2282:            public void finalizeDelete(boolean success) {
2283:                super .finalizeDelete(success);
2284:                if (success) {
2285:                    deleteFromCache();
2286:                }
2287:            }
2288:
2289:            /**
2290:             *
2291:             */
2292:            private synchronized void syncStructs(boolean _updateCache) {
2293:                if (null != data)
2294:                    originalData = data;
2295:                data = null;
2296:                changedFlags_set(false);
2297:                ((PersonDataStruct) originalData).readOnly = true;
2298:                if (_updateCache)
2299:                    updateCache();
2300:            }
2301:
2302:            /**
2303:             * @return true for DO that's created virgin and hasn't been commited yet.
2304:             */
2305:            public boolean isVirgin() {
2306:                return !isPersistent();
2307:            }
2308:
2309:            /**
2310:             * Make DO's data from cache visible
2311:             */
2312:            public void makeVisible() {
2313:                try {
2314:                    ((QueryCacheImpl) cache).makeVisible(get_CacheHandle());
2315:                } catch (DatabaseManagerException dme) {
2316:                    System.err.println("makeVisible for " + super .toString()
2317:                            + "failed");
2318:                }
2319:            }
2320:
2321:            /**
2322:             * Make DO's  data from cache Invisible
2323:             */
2324:            public void makeInvisible() {
2325:                try {
2326:                    ((QueryCacheImpl) cache).makeInvisible(get_CacheHandle());
2327:                } catch (DatabaseManagerException dme) {
2328:                    System.err.println("makeInvisible for " + super .toString()
2329:                            + "failed");
2330:                }
2331:            }
2332:
2333:            /**
2334:             * Inserts this object into the database.
2335:             *
2336:             * @param conn the database connection.
2337:             * @exception java.sql.SQLException if a database access error occurs.
2338:             * @exception DBRowUpdateException If a version error occurs.
2339:             */
2340:            public synchronized void executeInsert(DBConnection conn)
2341:                    throws SQLException, DBRowUpdateException {
2342:                if (dirty) {
2343:                    super .executeInsert(conn);
2344:                    changedFlags_set(false);
2345:                }
2346:            }
2347:
2348:            /**
2349:             */
2350:            protected boolean isAutoSave() {
2351:                boolean flag = false;
2352:                try {
2353:                    flag = ((StandardLogicalDatabase) (DODS
2354:                            .getDatabaseManager()
2355:                            .findLogicalDatabase(get_OriginDatabase())))
2356:                            .getDatabaseConfiguration().getAutoSave();
2357:                } catch (Exception ex) {
2358:                }
2359:                return flag;
2360:            }
2361:
2362:            /**
2363:             */
2364:            protected boolean isAutoSaveCreateVirgin() {
2365:                boolean flag = false;
2366:                try {
2367:                    flag = ((StandardLogicalDatabase) (DODS
2368:                            .getDatabaseManager()
2369:                            .findLogicalDatabase(get_OriginDatabase())))
2370:                            .getDatabaseConfiguration()
2371:                            .getAutoSaveCreateVirgin();
2372:                } catch (Exception ex) {
2373:                }
2374:                return flag;
2375:            }
2376:
2377:            /**
2378:             */
2379:            protected boolean isTransactionCheck() {
2380:                boolean flag = false;
2381:                try {
2382:                    flag = ((StandardLogicalDatabase) (DODS
2383:                            .getDatabaseManager()
2384:                            .findLogicalDatabase(get_OriginDatabase())))
2385:                            .getDatabaseConfiguration().getTransactionCheck();
2386:                } catch (Exception ex) {
2387:                }
2388:                return flag;
2389:            }
2390:
2391:            /**
2392:             */
2393:            protected boolean isTransactionCaches() {
2394:                boolean flag = false;
2395:                try {
2396:                    flag = ((StandardLogicalDatabase) (DODS
2397:                            .getDatabaseManager()
2398:                            .findLogicalDatabase(get_OriginDatabase())))
2399:                            .getDatabaseConfiguration().getTransactionCaches();
2400:                } catch (Exception ex) {
2401:                }
2402:                return flag;
2403:            }
2404:
2405:            /**
2406:             */
2407:            protected boolean isDeleteCheckVersion() {
2408:                boolean flag = false;
2409:                try {
2410:                    flag = ((StandardLogicalDatabase) (DODS
2411:                            .getDatabaseManager().findLogicalDatabase(this 
2412:                            .get_OriginDatabase()))).getDatabaseConfiguration()
2413:                            .getDeleteCheckVersion();
2414:                } catch (Exception ex) {
2415:                }
2416:                return flag;
2417:            }
2418:
2419:            /**
2420:             */
2421:            protected static boolean isAllReadOnly() {
2422:                boolean flag = false;
2423:                try {
2424:                    flag = ((StandardLogicalDatabase) (DODS
2425:                            .getDatabaseManager()
2426:                            .findLogicalDatabase(get_logicalDBName())))
2427:                            .getDatabaseConfiguration().isAllReadOnly();
2428:                } catch (Exception ex) {
2429:                }
2430:                return flag;
2431:            }
2432:
2433:            /**
2434:             *
2435:             */
2436:            public void undo()
2437:                    throws com.lutris.dods.builder.generator.query.DataObjectException {
2438:                try {
2439:                    if (null != transaction) {
2440:                        if ((data != null) || (data == null && isDeleted())) {
2441:                            int tempVersion = get_Version();
2442:                            if (isDeleted() && !isDeletedFromDatabase) {
2443:                                unDelete(transaction);
2444:                            } else if (isDeleted() && isDeletedFromDatabase) {
2445:                                data = ((PersonDataStruct) originalData)
2446:                                        .duplicate();
2447:                                set_Version(tempVersion);
2448:                                persistent = false;
2449:                                deleted = false;
2450:                                isDeletedFromDatabase = false;
2451:                                if (isAutoSave()) {
2452:                                    save(transaction, false);
2453:                                }
2454:                            } else {
2455:                                data = ((PersonDataStruct) originalData)
2456:                                        .duplicate();
2457:                                set_Version(tempVersion);
2458:                                if (isAutoSave()) {
2459:                                    save(transaction, false);
2460:                                }
2461:                            }
2462:                        }
2463:                    } else {
2464:                        throw new DataObjectException(
2465:                                "Error during Undo operation");
2466:                    }
2467:                } catch (Exception ex) {
2468:                    throw new DataObjectException("Error during Undo operation");
2469:                }
2470:
2471:            }
2472:
2473:            ////////////////////////// data member FirstName
2474:
2475:            /**
2476:             * static final RDBColumn FirstName for use with QueryBuilder.
2477:             * See RDBColumn PrimaryKey at the top of this file for usage example.
2478:             */
2479:            static public final RDBColumn FirstName = new RDBColumn(table,
2480:                    "firstName", true);
2481:
2482:            private boolean changedFirstName = false;
2483:
2484:            /** 
2485:             * Use for query caching.
2486:             */
2487:            static public final int COLUMN_FIRSTNAME = 0;
2488:            static public final int firstName_MaxLength = 32;
2489:
2490:            /**
2491:             * Get firstName of the person.
2492:             *
2493:             * @return firstName of the person.
2494:             *
2495:             * @exception DataObjectException
2496:             *   If the object is not found in the database.
2497:             */
2498:            public String getFirstName() throws DataObjectException {
2499:                checkLoad();
2500:
2501:                return get_DataStruct().getFirstName();
2502:            }
2503:
2504:            /**
2505:             * Get original firstName of the person.
2506:             *
2507:             * @return firstName of the person.
2508:             *
2509:             * @exception DataObjectException
2510:             *   If the object is not found in the database.
2511:             */
2512:            public String originalData_getFirstName()
2513:                    throws DataObjectException {
2514:                checkLoad();
2515:                return ((PersonDataStruct) originalData_get()).getFirstName();
2516:            }
2517:
2518:            /**
2519:             * Set firstName of the person.
2520:             *
2521:             * @param firstName of the person.
2522:             *
2523:             * @exception DataObjectException
2524:             *   If the object is not found in the database.
2525:             */
2526:            public void setFirstName(String firstName)
2527:                    throws DataObjectException {
2528:                _setFirstName(firstName);
2529:            }
2530:
2531:            /**
2532:             * _setFirstName is a protected method that is called by 
2533:             * setFirstName if firstName is not part of 
2534:             * a multicolumn foreign key.
2535:             *
2536:             * @param firstName of the person.
2537:             * 
2538:             * @exception DataObjectException
2539:             *   If the object is not found in the database.
2540:             */
2541:            protected void _setFirstName(String firstName)
2542:                    throws DataObjectException {
2543:                checkLoad();
2544:
2545:                try {
2546:                    checkDup();
2547:                } catch (Exception e) {
2548:                    throw new DataObjectException(
2549:                            "Coudn't duplicate DataStruct:", e);
2550:                }
2551:                if (data.isEmpty)
2552:                    data.isEmpty = false;
2553:                data.setFirstName(markNewValue(get_DataStruct().getFirstName(),
2554:                        firstName, 0, firstName_MaxLength, false));
2555:                changedFirstName = colChanged;
2556:                if (changedFirstName) {
2557:                    if (autoSaveAllowed && isAutoSave() && null != transaction) {
2558:                        try {
2559:                            save(transaction, false);
2560:                        } catch (Exception ex) {
2561:                            throw new DataObjectException(
2562:                                    "Error during transaction's writting data into database",
2563:                                    ex);
2564:                        }
2565:                    }
2566:                }
2567:            }
2568:
2569:            ////////////////////////// data member LastName
2570:
2571:            /**
2572:             * static final RDBColumn LastName for use with QueryBuilder.
2573:             * See RDBColumn PrimaryKey at the top of this file for usage example.
2574:             */
2575:            static public final RDBColumn LastName = new RDBColumn(table,
2576:                    "lastName", true);
2577:
2578:            private boolean changedLastName = false;
2579:
2580:            /** 
2581:             * Use for query caching.
2582:             */
2583:            static public final int COLUMN_LASTNAME = 1;
2584:            static public final int lastName_MaxLength = 32;
2585:
2586:            /**
2587:             * Get lastName of the person.
2588:             *
2589:             * @return lastName of the person.
2590:             *
2591:             * @exception DataObjectException
2592:             *   If the object is not found in the database.
2593:             */
2594:            public String getLastName() throws DataObjectException {
2595:                checkLoad();
2596:
2597:                return get_DataStruct().getLastName();
2598:            }
2599:
2600:            /**
2601:             * Get original lastName of the person.
2602:             *
2603:             * @return lastName of the person.
2604:             *
2605:             * @exception DataObjectException
2606:             *   If the object is not found in the database.
2607:             */
2608:            public String originalData_getLastName() throws DataObjectException {
2609:                checkLoad();
2610:                return ((PersonDataStruct) originalData_get()).getLastName();
2611:            }
2612:
2613:            /**
2614:             * Set lastName of the person.
2615:             *
2616:             * @param lastName of the person.
2617:             *
2618:             * @exception DataObjectException
2619:             *   If the object is not found in the database.
2620:             */
2621:            public void setLastName(String lastName) throws DataObjectException {
2622:                _setLastName(lastName);
2623:            }
2624:
2625:            /**
2626:             * _setLastName is a protected method that is called by 
2627:             * setLastName if lastName is not part of 
2628:             * a multicolumn foreign key.
2629:             *
2630:             * @param lastName of the person.
2631:             * 
2632:             * @exception DataObjectException
2633:             *   If the object is not found in the database.
2634:             */
2635:            protected void _setLastName(String lastName)
2636:                    throws DataObjectException {
2637:                checkLoad();
2638:
2639:                try {
2640:                    checkDup();
2641:                } catch (Exception e) {
2642:                    throw new DataObjectException(
2643:                            "Coudn't duplicate DataStruct:", e);
2644:                }
2645:                if (data.isEmpty)
2646:                    data.isEmpty = false;
2647:                data.setLastName(markNewValue(get_DataStruct().getLastName(),
2648:                        lastName, 0, lastName_MaxLength, false));
2649:                changedLastName = colChanged;
2650:                if (changedLastName) {
2651:                    if (autoSaveAllowed && isAutoSave() && null != transaction) {
2652:                        try {
2653:                            save(transaction, false);
2654:                        } catch (Exception ex) {
2655:                            throw new DataObjectException(
2656:                                    "Error during transaction's writting data into database",
2657:                                    ex);
2658:                        }
2659:                    }
2660:                }
2661:            }
2662:
2663:            ////////////////////////// data member PhoneNumber
2664:
2665:            /**
2666:             * static final RDBColumn PhoneNumber for use with QueryBuilder.
2667:             * See RDBColumn PrimaryKey at the top of this file for usage example.
2668:             */
2669:            static public final RDBColumn PhoneNumber = new RDBColumn(table,
2670:                    "phoneNumber", true);
2671:
2672:            private boolean changedPhoneNumber = false;
2673:
2674:            /** 
2675:             * Use for query caching.
2676:             */
2677:            static public final int COLUMN_PHONENUMBER = 2;
2678:            static public final int phoneNumber_MaxLength = 32;
2679:
2680:            /**
2681:             * Get phoneNumber of the person.
2682:             *
2683:             * @return phoneNumber of the person.
2684:             *
2685:             * @exception DataObjectException
2686:             *   If the object is not found in the database.
2687:             */
2688:            public String getPhoneNumber() throws DataObjectException {
2689:                checkLoad();
2690:
2691:                return get_DataStruct().getPhoneNumber();
2692:            }
2693:
2694:            /**
2695:             * Get original phoneNumber of the person.
2696:             *
2697:             * @return phoneNumber of the person.
2698:             *
2699:             * @exception DataObjectException
2700:             *   If the object is not found in the database.
2701:             */
2702:            public String originalData_getPhoneNumber()
2703:                    throws DataObjectException {
2704:                checkLoad();
2705:                return ((PersonDataStruct) originalData_get()).getPhoneNumber();
2706:            }
2707:
2708:            /**
2709:             * Set phoneNumber of the person.
2710:             *
2711:             * @param phoneNumber of the person.
2712:             *
2713:             * @exception DataObjectException
2714:             *   If the object is not found in the database.
2715:             */
2716:            public void setPhoneNumber(String phoneNumber)
2717:                    throws DataObjectException {
2718:                _setPhoneNumber(phoneNumber);
2719:            }
2720:
2721:            /**
2722:             * _setPhoneNumber is a protected method that is called by 
2723:             * setPhoneNumber if phoneNumber is not part of 
2724:             * a multicolumn foreign key.
2725:             *
2726:             * @param phoneNumber of the person.
2727:             * 
2728:             * @exception DataObjectException
2729:             *   If the object is not found in the database.
2730:             */
2731:            protected void _setPhoneNumber(String phoneNumber)
2732:                    throws DataObjectException {
2733:                checkLoad();
2734:
2735:                try {
2736:                    checkDup();
2737:                } catch (Exception e) {
2738:                    throw new DataObjectException(
2739:                            "Coudn't duplicate DataStruct:", e);
2740:                }
2741:                if (data.isEmpty)
2742:                    data.isEmpty = false;
2743:                data.setPhoneNumber(markNewValue(get_DataStruct()
2744:                        .getPhoneNumber(), phoneNumber, 0,
2745:                        phoneNumber_MaxLength, false));
2746:                changedPhoneNumber = colChanged;
2747:                if (changedPhoneNumber) {
2748:                    if (autoSaveAllowed && isAutoSave() && null != transaction) {
2749:                        try {
2750:                            save(transaction, false);
2751:                        } catch (Exception ex) {
2752:                            throw new DataObjectException(
2753:                                    "Error during transaction's writting data into database",
2754:                                    ex);
2755:                        }
2756:                    }
2757:                }
2758:            }
2759:
2760:            /**
2761:             * Compares whether this DO satisfies condition cond.
2762:             *
2763:             * @param cond condition.
2764:             * 
2765:             * @return true if DO satisfies condition cond, otherwise false.
2766:             */
2767:            public boolean compareCond(Condition cond) {
2768:                try {
2769:                    switch (cond.getColumnIndex()) {
2770:                    case COLUMN_FIRSTNAME:
2771:                        return QueryBuilder.compare(getFirstName(), cond
2772:                                .getValue(), cond.getOperator());
2773:                    case COLUMN_LASTNAME:
2774:                        return QueryBuilder.compare(getLastName(), cond
2775:                                .getValue(), cond.getOperator());
2776:                    case COLUMN_PHONENUMBER:
2777:                        return QueryBuilder.compare(getPhoneNumber(), cond
2778:                                .getValue(), cond.getOperator());
2779:                    }
2780:                } catch (Exception e) {
2781:                }
2782:                return false;
2783:            }
2784:
2785:            static {
2786:            }
2787:
2788:            /**
2789:             * logicalDbName is logical database name
2790:             * set by setLogicalDBName()
2791:             * and retrieved by get_logicalDBName().
2792:             */
2793:            static private String logicalDbName = null;
2794:
2795:            /**
2796:             * setLogicalDBName sets the logical database name that will be used
2797:             * to create DBTransaction and DBQuery objects used by
2798:             * PersonDO and the corresponding Query class.
2799:             * 
2800:             * @param logicalDbNameInConfFile The logical database specified in the
2801:             * application's .conf file.
2802:             *
2803:             * @deprecated It is dangeruous to use this method in multiuser environment because, 
2804:             * this setings are applied to all users (sets logical database to all users)
2805:             */
2806:            static public synchronized void setLogicalDBName(
2807:                    String logicalDbNameInConfFile) {
2808:                if (null != logicalDbNameInConfFile
2809:                        && 0 != logicalDbNameInConfFile.length())
2810:                    logicalDbName = logicalDbNameInConfFile;
2811:                else
2812:                    logicalDbName = DODS.getDatabaseManager().getDefaultDB();
2813:            }
2814:
2815:            /**
2816:             * get_logicalDBName retrieves the logical database name 
2817:             * set by setLogicalDBName().
2818:             *
2819:             * @return the logical database name that was set by method setLogicalDBName()
2820:             *
2821:             */
2822:            static public synchronized String get_logicalDBName() {
2823:                if (logicalDbName == null)
2824:                    logicalDbName = DODS.getDatabaseManager().getDefaultDB();
2825:                return logicalDbName;
2826:            }
2827:
2828:            /**
2829:             * createTransaction() creates a new DBTransaction.
2830:             * This method uses the logical database name set by method setLogicalDBName().
2831:             *
2832:             * If setLogicalDBName() was used to set the logical database name
2833:             * to something other than the value of DatabaseManager.DefaultDatabase
2834:             * in the application's .conf file, then any DBTransaction passed to 
2835:             * save(DBTransaction) or delete(DBTransaction) should be created using 
2836:             * PersonDO.createTransaction().
2837:             *
2838:             * The PersonDO save() and delete() methods use this method.
2839:             *
2840:             * @return A DBTransaction object to use with the PersonDO class.
2841:             */
2842:            static public DBTransaction createTransaction()
2843:                    throws DatabaseManagerException, SQLException {
2844:                DBTransaction ret;
2845:                try {
2846:                    ret = DODS.getDatabaseManager().createTransaction(
2847:                            get_logicalDBName());
2848:                    ret.setDatabaseName(get_logicalDBName());
2849:                    return ret;
2850:                } catch (DatabaseManagerException e) {
2851:                    String err = "";
2852:                    if (null != get_logicalDBName())
2853:                        err = "ERROR: Could not create a DBTransaction.  "
2854:                                + "PersonDO.logicalDbName='"
2855:                                + get_logicalDBName()
2856:                                + "'.  "
2857:                                + "The application .conf file must list this name in "
2858:                                + "DatabaseManager.Databases[], and there must be "
2859:                                + "DatabaseManager.DB." + get_logicalDBName()
2860:                                + " settings.";
2861:                    throw new DatabaseManagerException(err, e);
2862:                }
2863:            }
2864:
2865:            /**
2866:             * createQuery() creates a new DBQuery.
2867:             * This method uses the logical database name set by method setLogicalDBName().
2868:             *
2869:             * If setLogicalDBName() was used to set the logical database name
2870:             * to something other than the value of DatabaseManager.DefaultDatabase
2871:             * in the application's .conf file, then any DBQuery object used to 
2872:             * access the 'person' table should be created using 
2873:             * PersonDO.createQuery().
2874:             *
2875:             * The Query class corresponding to PersonDO uses this method.
2876:             *
2877:             * @return A DBQuery object to use in accessing the 'person' table.
2878:                  
2879:             */
2880:            static public DBQuery createQuery()
2881:                    throws DatabaseManagerException, SQLException {
2882:                try {
2883:                    return DODS.getDatabaseManager().createQuery(
2884:                            get_logicalDBName());
2885:                } catch (DatabaseManagerException e) {
2886:                    String err = "";
2887:                    if (null != get_logicalDBName())
2888:                        err = "ERROR: Could not create a DBQuery.  "
2889:                                + "PersonDO.logicalDBName='"
2890:                                + get_logicalDBName()
2891:                                + "'.  "
2892:                                + "The application .conf file must list this name in "
2893:                                + "DatabaseManager.Databases[], and there must be "
2894:                                + "DatabaseManager.DB." + get_logicalDBName()
2895:                                + " settings.";
2896:                    throw new DatabaseManagerException(err, e);
2897:                }
2898:            }
2899:
2900:            /**
2901:             * createQuery() creates a new DBQuery.
2902:             * This method uses the logical database name set by method setLogicalDBName().
2903:             *
2904:             * If setLogicalDBName() was used to set the logical database name
2905:             * to something other than the value of DatabaseManager.DefaultDatabase
2906:             * in the application's .conf file, then any DBQuery object used to 
2907:             * access the 'person' table should be created using 
2908:             * PersonDO.createQuery().
2909:             *
2910:             * The Query class corresponding to PersonDO uses this method.
2911:             *
2912:             * @return A DBQuery object to use in accessing the 'person' table.
2913:             */
2914:            static public DBQuery createQuery(DBTransaction trans)
2915:                    throws DatabaseManagerException, SQLException {
2916:
2917:                try {
2918:                    return (null == trans) ? createQuery() : trans
2919:                            .createQuery();
2920:                } catch (DatabaseManagerException e) {
2921:                    String err = "";
2922:                    if (null != get_logicalDBName())
2923:                        err = "ERROR: Could not create a DBQuery.  "
2924:                                + "PersonDO.logicalDBName='"
2925:                                + get_logicalDBName()
2926:                                + "'.  "
2927:                                + "The application .conf file must list this name in "
2928:                                + "DatabaseManager.Databases[], and there must be "
2929:                                + "DatabaseManager.DB." + get_logicalDBName()
2930:                                + " settings.";
2931:                    throw new DatabaseManagerException(err, e);
2932:                }
2933:            }
2934:
2935:            /**
2936:             * Protected constructor.
2937:             *
2938:             * @param rs Result set from which to obtain product data.
2939:             *
2940:             * @exception DataObjectException
2941:             *   If the object is not found in the database.
2942:             * @exception com.lutris.appserver.server.sql.ObjectIdException
2943:             *   If an object's id can't be allocated for this object.
2944:             * @exception DatabaseManagerException
2945:             *   If a connection to the database cannot be established, etc.
2946:             * @exception SQLException
2947:             *   If the database rejects the SQL generated to retrieve data
2948:             *   for this object, or if the table contains a bad foreign key, etc.
2949:             */
2950:            protected PersonDO(ResultSet rs) throws SQLException,
2951:                    ObjectIdException, DataObjectException,
2952:                    DatabaseManagerException {
2953:                super (rs);
2954:                initFromResultSet(rs);
2955:                originDatabase = get_logicalDBName();
2956:                get_DataStruct().set_Database(originDatabase);
2957:                set_OId(new ObjectId(rs.getBigDecimal(get_OIdColumnName())));
2958:                if (versioning)
2959:                    set_Version(rs.getInt(get_versionColumnName()));
2960:                if (isTransactionCheck()) {
2961:                    String trace = "";
2962:                    StackTraceElement[] traceElements = (new Throwable())
2963:                            .getStackTrace();
2964:                    for (int i = 0; i < traceElements.length; i++)
2965:                        trace += traceElements[i].toString() + "\n";
2966:                    DODS.getLogChannel().write(
2967:                            Logger.WARNING,
2968:                            "DO without transaction context is created : Database: "
2969:                                    + get_OriginDatabase()
2970:                                    + " PersonDO class, oid: " + get_OId()
2971:                                    + ", version: " + get_Version() + " \n"
2972:                                    + trace);
2973:                }
2974:            }
2975:
2976:            /**
2977:             * Protected constructor.
2978:             *
2979:             * @param rs Result set from which to obtain product data.
2980:             *
2981:             * @exception DataObjectException
2982:             *   If the object is not found in the database.
2983:             * @exception com.lutris.appserver.server.sql.ObjectIdException
2984:             *   If an object's id can't be allocated for this object.
2985:             * @exception DatabaseManagerException
2986:             *   If a connection to the database cannot be established, etc.
2987:             * @exception SQLException
2988:             *   If the database rejects the SQL generated to retrieve data
2989:             *   for this object, or if the table contains a bad foreign key, etc.
2990:             */
2991:            protected PersonDO(ResultSet rs, HashMap queryRefs)
2992:                    throws SQLException, ObjectIdException,
2993:                    DataObjectException, DatabaseManagerException {
2994:                this (rs, queryRefs, null);
2995:            }
2996:
2997:            /**
2998:             * Protected constructor.
2999:             *
3000:             * @param rs Result set from which to obtain product data.
3001:             *
3002:             * @exception DataObjectException
3003:             *   If the object is not found in the database.
3004:             * @exception com.lutris.appserver.server.sql.ObjectIdException
3005:             *   If an object's id can't be allocated for this object.
3006:             * @exception DatabaseManagerException
3007:             *   If a connection to the database cannot be established, etc.
3008:             * @exception SQLException
3009:             *   If the database rejects the SQL generated to retrieve data
3010:             *   for this object, or if the table contains a bad foreign key, etc.
3011:             */
3012:            protected PersonDO(ResultSet rs, HashMap queryRefs,
3013:                    DBTransaction dbTrans) throws SQLException,
3014:                    ObjectIdException, DataObjectException,
3015:                    DatabaseManagerException {
3016:                super (rs);
3017:                set_refs(queryRefs);
3018:                setTransaction(dbTrans);
3019:                initFromResultSet(rs);
3020:                if (dbTrans != null)
3021:                    originDatabase = dbTrans.getDatabaseName();
3022:                if (originDatabase == null)
3023:                    originDatabase = get_logicalDBName();
3024:                get_DataStruct().set_Database(originDatabase);
3025:                addToTransactionCache();
3026:                if (dbTrans != null)
3027:                    dbTrans.lockDO(this );
3028:            }
3029:
3030:            /**
3031:             * Protected constructor.
3032:             *
3033:             * @param rs Result set from which to obtain product data.
3034:             * @param dbTrans The current database transaction
3035:             * @exception DataObjectException
3036:             *   If the object is not found in the database.
3037:             * @exception com.lutris.appserver.server.sql.ObjectIdException
3038:             *   If an object's id can't be allocated for this object.
3039:             * @exception DatabaseManagerException
3040:             *   If a connection to the database cannot be established, etc.
3041:             * @exception SQLException
3042:             *   If the database rejects the SQL generated to retrieve data
3043:             *   for this object, or if the table contains a bad foreign key, etc.
3044:             */
3045:            protected PersonDO(ResultSet rs, DBTransaction dbTrans)
3046:                    throws SQLException, ObjectIdException,
3047:                    DataObjectException, DatabaseManagerException {
3048:                this (rs, null, dbTrans);
3049:            }
3050:
3051:            /**
3052:             * while in initFromResultSet, auto save can't be allowed
3053:             */
3054:            private boolean autoSaveAllowed = true;
3055:
3056:            /**
3057:             * initFromResultSet initializes the data members of person.
3058:             * This code was separated from the ResultSet constructor
3059:             * so that createExisting(ResultSet) could handle VIEWs.
3060:             *
3061:             * @param rs ResultSet from which data members are initialized.
3062:             */
3063:            private void initFromResultSet(ResultSet rs) throws SQLException,
3064:                    ObjectIdException, DataObjectException,
3065:                    DatabaseManagerException {
3066:                autoSaveAllowed = false;
3067:                // Constructing a DO from a ResultSet means we definitely need the 
3068:                // DataStruct ready for the setXxx methods invoked below.
3069:                if (null == get_DataStruct())
3070:                    originalData = new PersonDataStruct();
3071:                get_DataStruct().isEmpty = false;
3072:                // writeMemberStuff uses the ResultSetExtraction.template
3073:                // to build up the value for this tag:
3074:                // the value is a series of calls to the DO set methods.
3075:
3076:                setFirstName(rs.getString("firstName"));
3077:
3078:                setLastName(rs.getString("lastName"));
3079:
3080:                setPhoneNumber(rs.getString("phoneNumber"));
3081:
3082:                get_DataStruct().isEmpty = false;
3083:                if (versioning)
3084:                    set_Version(rs.getInt(get_versionColumnName()));
3085:                setPersistent(true);
3086:                markClean();
3087:                syncStructs(false);
3088:                //        refs = null;
3089:                autoSaveAllowed = true;
3090:            }
3091:
3092:            private int[] param = null;
3093:            private boolean isDeletedFromDatabase = false;
3094:
3095:            /**
3096:             * Prepares the statement used to insert this object
3097:             * into the database.
3098:             *
3099:             * @param conn The database connection.
3100:             *
3101:             * @return The insert statement.
3102:             *
3103:             * @exception java.sql.SQLException if an error occurs.
3104:             */
3105:            public PreparedStatement getInsertStatement(DBConnection conn)
3106:                    throws SQLException {
3107:                ObjectId oid;
3108:
3109:                if (isDeletedFromDatabase)
3110:                    throw new SQLException("Object " + get_OId()
3111:                            + " is already deleted");
3112:
3113:                PreparedStatement stmt = conn
3114:                        .prepareStatement("insert into person ( firstName, lastName, phoneNumber, "
3115:                                + get_OIdColumnName()
3116:                                + ", "
3117:                                + get_versionColumnName()
3118:                                + " )"
3119:                                + "values ( ?, ?, ?, ?, ? )");
3120:
3121:                param = new int[1];
3122:                param[0] = 1;
3123:                // writeMemberStuff uses the JDBCsetCalls.template
3124:                // to build up the value for this tag:
3125:                // the value is a series of calls to setPrepStmtParam_TYPE methods.
3126:                // Those methods are defined in GenericDO.
3127:                try {
3128:                    setPrepStmtParam_String(stmt, param, getFirstName());
3129:                    setPrepStmtParam_String(stmt, param, getLastName());
3130:                    setPrepStmtParam_String(stmt, param, getPhoneNumber());
3131:
3132:                    /* The ObjecId/Version columns form the primary key.  */
3133:                    setPrepStmtParam_BigDecimal(stmt, param, get_OId()
3134:                            .toBigDecimal());
3135:                    setPrepStmtParam_int(stmt, param, get_NewVersion());
3136:
3137:                } catch (Exception e) {
3138:                    throw new SQLException("Data Object error: "
3139:                            + e.getMessage());
3140:                }
3141:                statistics.incrementInsertNum();
3142:                return stmt;
3143:            }
3144:
3145:            /**
3146:             *
3147:             */
3148:            private boolean _lockDO = false;
3149:
3150:            /**
3151:             * Specifies whether to lock this DO (row) in database just before commit.
3152:             * Locking is attempted via "dummy" update:
3153:             * "update set version=OLD_ONE where OID=X and version=OLD_ONE".
3154:             * @param value true for locking, false otherwise
3155:             */
3156:            public void doCheck(boolean value) {
3157:                _lockDO = value;
3158:            }
3159:
3160:            /**
3161:             * Locks this DO in database by performing
3162:             * "update set version=OLD_ONE where OID=X and version=OLD_ONE".
3163:             */
3164:            public void doLock() throws SQLException {
3165:                if (null != transaction) {
3166:                    boolean _ol = _lockDO;
3167:                    _lockDO = true;
3168:                    transaction.lockDO(this );
3169:                    _lockDO = _ol;
3170:                }
3171:            }
3172:
3173:            private boolean incrementVersionToo = true;
3174:
3175:            /**
3176:             * Locks this DO in database by performing
3177:             * "update set version=OLD_ONE where OID=X and version=INCREMENTED".
3178:             */
3179:            public void doTouch() throws SQLException,
3180:                    DatabaseManagerException,
3181:                    com.lutris.appserver.server.sql.ObjectIdException,
3182:                    DataObjectException {
3183:                if (null != transaction) {
3184:                    checkLoad();
3185:                    checkDup();
3186:                    markNewValue();
3187:                    incrementVersionToo = true;
3188:                    boolean _ol = _lockDO;
3189:                    _lockDO = true;
3190:                    transaction.lockDO(this );
3191:                    _lockDO = _ol;
3192:                }
3193:            }
3194:
3195:            /**
3196:             * Prepares and executes the statement used to lock this object
3197:             * in the database.
3198:             *
3199:             * @param conn The database connection
3200:             *
3201:             * @exception java.sql.SQLException if an error occurs.
3202:             */
3203:            public void executeLockingStatement(DBConnection conn)
3204:                    throws SQLException {
3205:                if (!_lockDO)
3206:                    return;
3207:                StringBuffer updateStmt = new StringBuffer();
3208:                PreparedStatement stmt = null;
3209:                if (isDeletedFromDatabase)
3210:                    throw new SQLException("person (" + get_OId()
3211:                            + ") is already deleted, " + "cannot lock it.");
3212:
3213:                param = new int[1];
3214:                param[0] = 1;
3215:                try {
3216:                    updateStmt.append("Update person set ");
3217:                    updateStmt.append(get_versionColumnName()).append(" = ? ");
3218:                    updateStmt.append(" where " + get_OIdColumnName()
3219:                            + " = ? and " + get_versionColumnName() + " = ?");
3220:
3221:                    stmt = conn.prepareStatement(updateStmt.toString());
3222:                    setPrepStmtParam_int(stmt, param, get_Version()
3223:                            + (incrementVersionToo ? 1 : 0));
3224:                    setPrepStmtParam_BigDecimal(stmt, param, get_OId()
3225:                            .toBigDecimal());
3226:                    setPrepStmtParam_int(stmt, param, get_Version());
3227:                    if (null != stmt) {
3228:                        conn.executeUpdate(stmt, "execute update");
3229:                        if (incrementVersionToo) {
3230:                            set_Version(get_Version() + 1);
3231:                        }
3232:                    }
3233:                } catch (Exception e) {
3234:                    e.printStackTrace();
3235:                    throw new SQLException("Data Object error: "
3236:                            + e.getMessage());
3237:                }
3238:            }
3239:
3240:            /**
3241:             * Prepares the statement used to update this object
3242:             * in the database.
3243:             *
3244:             * @param conn The database connection
3245:             *
3246:             * @return The update statement.
3247:             *
3248:             * @exception java.sql.SQLException if an error occurs.
3249:             */
3250:            public PreparedStatement getUpdateStatement(DBConnection conn)
3251:                    throws SQLException {
3252:                StringBuffer updateStmt = new StringBuffer();
3253:                PreparedStatement stmt;
3254:
3255:                if (isDeletedFromDatabase)
3256:                    throw new SQLException("Object " + get_OId()
3257:                            + " is already deleted");
3258:
3259:                data.set_Version(get_Version() + 1);
3260:                param = new int[1];
3261:                param[0] = 1;
3262:                try {
3263:                    updateStmt.append("Update person set ");
3264:                    updateStmt.append(get_versionColumnName()).append(" = ? ");
3265:
3266:                    if (changedFirstName)
3267:                        updateStmt.append(", FirstName = ? ");
3268:                    if (changedLastName)
3269:                        updateStmt.append(", LastName = ? ");
3270:                    if (changedPhoneNumber)
3271:                        updateStmt.append(", PhoneNumber = ? ");
3272:                    updateStmt.append(" where " + get_OIdColumnName()
3273:                            + " = ? and " + get_versionColumnName() + " = ?");
3274:
3275:                    stmt = conn.prepareStatement(updateStmt.toString());
3276:                    setPrepStmtParam_int(stmt, param, get_Version());
3277:
3278:                    if (changedFirstName) {
3279:                        setPrepStmtParam_String(stmt, param, getFirstName());
3280:                        changedFirstName = false;
3281:                    }
3282:                    if (changedLastName) {
3283:                        setPrepStmtParam_String(stmt, param, getLastName());
3284:                        changedLastName = false;
3285:                    }
3286:                    if (changedPhoneNumber) {
3287:                        setPrepStmtParam_String(stmt, param, getPhoneNumber());
3288:                        changedPhoneNumber = false;
3289:                    }
3290:                    setPrepStmtParam_BigDecimal(stmt, param, get_OId()
3291:                            .toBigDecimal());
3292:                    setPrepStmtParam_int(stmt, param, get_Version() - 1);
3293:                } catch (Exception e) {
3294:                    e.printStackTrace();
3295:                    throw new SQLException("Data Object error: "
3296:                            + e.getMessage());
3297:                }
3298:                statistics.incrementUpdateNum();
3299:                return stmt;
3300:            }
3301:
3302:            /**
3303:             * Prepares the statement used to delete this object
3304:             * from the database.
3305:             *
3306:             * @param conn The database connection
3307:             *
3308:             * @return The delete statement.
3309:             *
3310:             * @exception java.sql.SQLException if an error occurs.
3311:             */
3312:            public PreparedStatement getDeleteStatement(DBConnection conn)
3313:                    throws SQLException {
3314:                String sql = "";
3315:                if (isDeleteCheckVersion())
3316:                    sql = "delete from person \n" + "where "
3317:                            + get_OIdColumnName() + " = ? and "
3318:                            + get_versionColumnName() + " = ?";
3319:                else
3320:                    sql = "delete from person \n" + "where "
3321:                            + get_OIdColumnName() + " = ?";
3322:                PreparedStatement stmt = conn.prepareStatement(sql);
3323:                stmt.setBigDecimal(1, get_OId().toBigDecimal());
3324:                if (isDeleteCheckVersion()) {
3325:                    stmt.setInt(2, get_Version());
3326:                }
3327:                statistics.incrementDeleteNum();
3328:                isDeletedFromDatabase = true;
3329:                return stmt;
3330:            }
3331:
3332:            /*
3333:             * toString - for debugging
3334:             *
3335:             * @return String for debugging.
3336:             *
3337:             */
3338:            public String toString() {
3339:                return toString(1);
3340:            }
3341:
3342:            public String toString(int indentCount) {
3343:                String indent = "";
3344:                for (int i = 0; i < indentCount; i++) {
3345:                    indent += ". ";
3346:                }
3347:                StringBuffer sb = new StringBuffer();
3348:                sb.append(indent + "PersonDO:");
3349:
3350:                ObjectId oid = get_OId();
3351:                String id = "virgin";
3352:                if (null != oid)
3353:                    id = oid.toString();
3354:                sb.append(" OID=" + id + ",VERSION=" + get_Version());
3355:                if (isLoaded()) {
3356:                    sb.append("\n" + indent + "firstName="
3357:                            + get_DataStruct().getFirstName());
3358:
3359:                    sb.append("\n" + indent + "lastName="
3360:                            + get_DataStruct().getLastName());
3361:
3362:                    sb.append("\n" + indent + "phoneNumber="
3363:                            + get_DataStruct().getPhoneNumber());
3364:                    ;
3365:                    sb.append("\n" + indent + "SUPER="
3366:                            + super .toString(indentCount));
3367:                }
3368:                return sb.toString();
3369:            }
3370:
3371:            /**
3372:             * A stub method for implementing pre-commit assertions 
3373:             * for this PersonDO.
3374:             * Implement this stub to throw an RefAssertionException for cases
3375:             * where this object is not valid for writing to the database.
3376:             */
3377:            protected void okToCommit() throws RefAssertionException {
3378:            }
3379:
3380:            /**
3381:             * A stub method for implementing pre-delete assertions 
3382:             * for this PersonDO.
3383:             * Implement this stub to throw an RefAssertionException for cases
3384:             * where this object is not valid for deletion from the database.
3385:             */
3386:            protected void okToDelete() throws RefAssertionException {
3387:            }
3388:
3389:            /**
3390:             * Inserts/Updates the DO into its table.
3391:             *
3392:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3393:             * @exception RefAssertionException Thrown by okTo method.
3394:             * @exception java.sql.SQLException If any SQL errors occur.
3395:             *
3396:             * @deprecated Use save() instead.
3397:             */
3398:            public void commit() throws SQLException, DatabaseManagerException,
3399:                    DataObjectException, RefAssertionException,
3400:                    DBRowUpdateException, QueryException {
3401:                commit(null);
3402:            }
3403:
3404:            /**
3405:             * Inserts/Updates the DO into its table.
3406:             * The transaction is likely provided by the commit() method of another DO
3407:             * which references this DO.
3408:             * 
3409:             * @param dbt The transaction object used for this operation.
3410:             *
3411:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3412:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3413:             * @exception RefAssertionException Thrown by okTo method.
3414:             * @exception java.sql.SQLException If any SQL errors occur.
3415:             *
3416:             * @deprecated Use save() instead.
3417:             */
3418:            public void commit(DBTransaction dbt) throws SQLException,
3419:                    DatabaseManagerException, DataObjectException,
3420:                    RefAssertionException, DBRowUpdateException, QueryException {
3421:                if (cache.getTableConfiguration().isReadOnly())
3422:                    throw new AssertionDataObjectException(
3423:                            "PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3424:                // WebDocWf extension for generic store
3425:                try {
3426:                    DBTransaction dbtlocal = dbt;
3427:                    boolean needToCommit = false;
3428:                    if (dbtlocal == null) {
3429:                        if (get_transaction() == null) {
3430:                            dbtlocal = DODS.getDatabaseManager()
3431:                                    .createTransaction(get_OriginDatabase());
3432:                            dbtlocal.setDatabaseName(get_OriginDatabase());
3433:                            needToCommit = true;
3434:                        } else
3435:                            dbtlocal = transaction;
3436:                    } else {
3437:                        if (get_transaction() != null) {
3438:                            if (!get_transaction().equals(dbt))
3439:                                throw new DatabaseManagerException(
3440:                                        "DO doesn't belong this transaction.");
3441:                        }
3442:                    }
3443:                    modifyDO(dbtlocal, false);
3444:                    if (needToCommit) {
3445:                        dbtlocal.commit();
3446:                        dbtlocal.release();
3447:                    }
3448:                } catch (DataObjectException e) {
3449:                    modifyDO(dbt, false);
3450:                }
3451:                // end of WebDocWf extension for generic store
3452:            }
3453:
3454:            /**
3455:             * Inserts/Updates the DO into its table.
3456:             *
3457:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3458:             * @exception RefAssertionException Thrown by okTo method.
3459:             * @exception java.sql.SQLException If any SQL errors occur.
3460:             * 
3461:             * WebDocWf extension
3462:             */
3463:            public void save() throws SQLException, DatabaseManagerException,
3464:                    DataObjectException, RefAssertionException,
3465:                    DBRowUpdateException, QueryException {
3466:                save(null, true);
3467:            }
3468:
3469:            /**
3470:             * Inserts/Updates the DO into its table.
3471:             *
3472:             * @param references True if references should be saved with this DO.
3473:             *
3474:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3475:             * @exception RefAssertionException Thrown by okTo method.
3476:             * @exception java.sql.SQLException If any SQL errors occur.
3477:             * 
3478:             * WebDocWf extension
3479:             */
3480:            public void save(boolean references) throws SQLException,
3481:                    DatabaseManagerException, DataObjectException,
3482:                    RefAssertionException, DBRowUpdateException, QueryException {
3483:                save(null, references);
3484:            }
3485:
3486:            /**
3487:             * Inserts/Updates the DO into its table.
3488:             * The transaction is likely provided by the commit() method of another DO
3489:             * which references this DO.
3490:             * 
3491:             * @param dbt The transaction object used for this operation.
3492:             *
3493:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3494:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3495:             * @exception RefAssertionException Thrown by okTo method.
3496:             * @exception java.sql.SQLException If any SQL errors occur.
3497:             * 
3498:             * WebDocWf extension
3499:             */
3500:            public void save(DBTransaction dbt) throws SQLException,
3501:                    DatabaseManagerException, DataObjectException,
3502:                    RefAssertionException, DBRowUpdateException, QueryException {
3503:                save(dbt, true);
3504:            }
3505:
3506:            /**
3507:             * Inserts/Updates the DO into its table.
3508:             * The transaction is likely provided by the commit() method of another DO
3509:             * which references this DO.
3510:             * 
3511:             * @param dbt The transaction object used for this operation.
3512:             * @param references True if references of this DO should be saved.
3513:             *
3514:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3515:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3516:             * @exception RefAssertionException Thrown by okTo method.
3517:             * @exception java.sql.SQLException If any SQL errors occur.
3518:             * 
3519:             * WebDocWf extension
3520:             */
3521:            public void save(DBTransaction dbt, boolean references)
3522:                    throws SQLException, DatabaseManagerException,
3523:                    DataObjectException, RefAssertionException,
3524:                    DBRowUpdateException, QueryException {
3525:                if (cache.getTableConfiguration().isReadOnly()) {
3526:                    throw new AssertionDataObjectException(
3527:                            "PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3528:                }
3529:                // before: modifyDO( dbt, false );
3530:                // The following line has been inserted:
3531:                try {
3532:                    // WebDocWf extension for generic store
3533:                    // The following line has been inserted:
3534:                    DBTransaction dbtlocal = dbt;
3535:                    boolean needToCommit = false;
3536:
3537:                    if (dbtlocal == null) {
3538:                        if (get_transaction() == null) {
3539:                            dbtlocal = DODS.getDatabaseManager()
3540:                                    .createTransaction(get_OriginDatabase());
3541:                            dbtlocal.setDatabaseName(get_OriginDatabase());
3542:                            needToCommit = true;
3543:                        } else
3544:                            dbtlocal = transaction;
3545:                    } else {
3546:                        if (get_transaction() != null) {
3547:                            if (!get_transaction().equals(dbt))
3548:                                throw new DatabaseManagerException(
3549:                                        "DO doesn't belong this transaction.");
3550:                        }
3551:                    }
3552:
3553:                    // The following line has been changed:
3554:                    modifyDO(dbtlocal, false, references);
3555:                    if (needToCommit) {
3556:                        dbtlocal.commit();
3557:                        dbtlocal.release();
3558:                    }
3559:                } catch (DataObjectException e) {
3560:                    modifyDO(dbt, false);
3561:                }
3562:                // end of WebDocWf extension for generic store
3563:            }
3564:
3565:            /**
3566:             * Deletes the DO from its table.
3567:             *
3568:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3569:             * @exception RefAssertionException Thrown by okTo method.
3570:             * @exception java.sql.SQLException If any SQL errors occur.
3571:             */
3572:            public void delete() throws SQLException, DatabaseManagerException,
3573:                    DataObjectException, RefAssertionException,
3574:                    DBRowUpdateException, QueryException {
3575:                delete((DBTransaction) null);
3576:            }
3577:
3578:            /**
3579:             * UnDeletes the DO and inserts to the table.
3580:             *
3581:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3582:             * @exception RefAssertionException Thrown by okTo method.
3583:             * @exception java.sql.SQLException If any SQL errors occur.
3584:             */
3585:            public void unDelete() throws SQLException,
3586:                    DatabaseManagerException, DataObjectException,
3587:                    RefAssertionException, DBRowUpdateException, QueryException {
3588:                unDelete((DBTransaction) null);
3589:            }
3590:
3591:            /**
3592:             * Deletes the DO from its table.
3593:             * The transaction is likely provided by the delete() method of another DO
3594:             * which references this DO.
3595:             *
3596:             * @param dbt The transaction object used for this operation.
3597:             *
3598:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3599:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3600:             * @exception RefAssertionException Thrown by okTo method.
3601:             * @exception java.sql.SQLException If any SQL errors occur.
3602:             */
3603:            public void delete(DBTransaction dbt) throws SQLException,
3604:                    DatabaseManagerException, DataObjectException,
3605:                    RefAssertionException, DBRowUpdateException, QueryException {
3606:                if (cache.getTableConfiguration().isReadOnly())
3607:                    throw new AssertionDataObjectException(
3608:                            "PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3609:                // WebDocWf extension for generic store
3610:                // The following lines have been inserted:
3611:                try {
3612:                    DBTransaction dbtlocal = dbt;
3613:                    boolean needToCommit = false;
3614:                    if (dbtlocal == null) {
3615:                        if (get_transaction() == null) {
3616:                            dbtlocal = DODS.getDatabaseManager()
3617:                                    .createTransaction(get_OriginDatabase());
3618:                            dbtlocal.setDatabaseName(get_OriginDatabase());
3619:                            needToCommit = true;
3620:                        } else
3621:                            dbtlocal = transaction;
3622:                    } else {
3623:                        if (get_transaction() != null) {
3624:                            if (!get_transaction().equals(dbtlocal))
3625:                                throw new DatabaseManagerException(
3626:                                        "DO doesn't belong this transaction.");
3627:                        }
3628:                    }
3629:                    // The following line has been changed:
3630:                    modifyDO(dbtlocal, true);
3631:                    // end of WebDocWf extension for generic store
3632:                    if (needToCommit) {
3633:                        dbtlocal.commit();
3634:                        dbtlocal.release();
3635:                    }
3636:                } catch (DataObjectException e) {
3637:                    modifyDO(dbt, true);
3638:                }
3639:            }
3640:
3641:            /**
3642:             * UnDeletes the DO and inserts to the table.
3643:             *
3644:             * @param dbt The transaction object used for this operation.
3645:             *
3646:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3647:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3648:             * @exception RefAssertionException Thrown by okTo method.
3649:             * @exception java.sql.SQLException If any SQL errors occur.
3650:             */
3651:            public void unDelete(DBTransaction dbt) throws SQLException,
3652:                    DatabaseManagerException, DataObjectException,
3653:                    RefAssertionException, DBRowUpdateException, QueryException {
3654:
3655:                if (cache.getTableConfiguration().isReadOnly())
3656:                    throw new AssertionDataObjectException(
3657:                            "PersonDO's cache is read-only. Therefore, DML opertions are not allowed.");
3658:                // WebDocWf extension for generic store
3659:                // The following lines have been inserted:
3660:                try {
3661:                    DBTransaction dbtlocal = dbt;
3662:                    boolean needToCommit = false;
3663:                    if (dbtlocal == null) {
3664:                        if (get_transaction() == null) {
3665:                            dbtlocal = DODS.getDatabaseManager()
3666:                                    .createTransaction(get_OriginDatabase());
3667:                            dbtlocal.setDatabaseName(get_OriginDatabase());
3668:                            needToCommit = true;
3669:                        } else
3670:                            dbtlocal = transaction;
3671:                    } else {
3672:                        if (get_transaction() != null) {
3673:                            if (!get_transaction().equals(dbtlocal))
3674:                                throw new DatabaseManagerException(
3675:                                        "DO didn't belong this transaction.");
3676:                        }
3677:                    }
3678:                    setDeleted(false);
3679:                    isDeletedFromDatabase = false;
3680:                    persistent = false;
3681:                    modifyDO(dbtlocal, false);
3682:                    if (needToCommit) {
3683:                        dbtlocal.commit();
3684:                        dbtlocal.release();
3685:                    }
3686:                    isDeletedFromDatabase = false;
3687:                } catch (DataObjectException e) {
3688:                    persistent = true;
3689:                    setDeleted(true);
3690:                }
3691:            }
3692:
3693:            /**
3694:             * Modifies the DO within its table.
3695:             * Performs recursive commit/delete on referenced DOs;
3696:             * all operations occur within a single transaction
3697:             * to allow rollback in the event of error.
3698:             * Only the creator of the transaction releases it.
3699:             *
3700:             * @param dbt The transaction object used for this operation.
3701:             * @param delete True if doing a delete, otherwise false (for insert/update).
3702:             *
3703:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3704:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3705:             * @exception RefAssertionException Thrown by okTo method.
3706:             * @exception java.sql.SQLException If any SQL errors occur.
3707:             * 
3708:             * WebDocWf extension
3709:             */
3710:            protected void modifyDO(DBTransaction dbt, boolean delete)
3711:                    throws SQLException, DatabaseManagerException,
3712:                    DataObjectException, RefAssertionException,
3713:                    DBRowUpdateException, QueryException {
3714:                modifyDO(dbt, delete, true);
3715:            }
3716:
3717:            /**
3718:             * Modifies the DO within its table.
3719:             * Performs recursive commit/delete on referenced DOs;
3720:             * all operations occur within a single transaction
3721:             * to allow rollback in the event of error.
3722:             * Only the creator of the transaction releases it.
3723:             *
3724:             * @param dbt The transaction object used for this operation.
3725:             * @param delete True if doing a delete, otherwise false (for insert/update).
3726:             * @param references True if references should be saved
3727:             *
3728:             * @exception com.lutris.appserver.server.sql.DatabaseManagerException If a Transaction can not be created.
3729:             * @exception com.lutris.appserver.server.sql.DBRowUpdateException If a version error occurs.
3730:             * @exception RefAssertionException Thrown by okTo method.
3731:             * @exception java.sql.SQLException If any SQL errors occur.
3732:             * 
3733:             * WebDocWf extension
3734:             */
3735:            protected void modifyDO(DBTransaction dbt, boolean delete,
3736:                    boolean references) throws SQLException,
3737:                    DatabaseManagerException, DataObjectException,
3738:                    RefAssertionException, DBRowUpdateException, QueryException {
3739:                if (delete)
3740:                    okToDelete();
3741:                else
3742:                    okToCommit();
3743:                boolean ownTransaction = false;
3744:                try {
3745:                    if (null == dbt) {
3746:                        if (null == get_transaction()) {
3747:                            DatabaseManager dbm = DODS.getDatabaseManager();
3748:                            dbt = dbm.createTransaction(get_OriginDatabase()); // create a transaction
3749:                            dbt.setDatabaseName(get_OriginDatabase());
3750:                            ownTransaction = true;
3751:                        } else {
3752:                            dbt = transaction;
3753:                        }
3754:                    } else {
3755:
3756:                        if (get_transaction() != null) {
3757:                            if (!get_transaction().equals(dbt))
3758:                                throw new DatabaseManagerException(
3759:                                        "DO doesn't belong this transaction.");
3760:                        }
3761:                        // WebDocWf fix for circular references
3762:                        // The following lines have been inserted
3763:                        CoreDO foundDO = _tr_(dbt).getDO(this );
3764:                        if (foundDO != null)
3765:                            return;
3766:
3767:                    }
3768:                    // end of WebDocWf fix for circular references
3769:                    if (null == dbt)
3770:                        throw new DatabaseManagerException(
3771:                                "DatabaseManager.createTransaction returned null.");
3772:                    if (delete) {
3773:                        _tr_(dbt).addDeletedDO(this );
3774:                        // Code to perform cascading deletes is generated here
3775:                        // if cascading deletes are not supported by the database.      
3776:
3777:                        // The following line keeps the compiler happy 
3778:                        // when the CASCADING_DELETES tag is empty.
3779:                        if (false)
3780:                            throw new QueryException("XXX");
3781:                    } else {
3782:                        // WebDocWf extension for save without references
3783:                        // The following line has been inserted
3784:                        if (references) {
3785:                            // end of WebDocWf extension for save without references
3786:                            // commit referenced DOs.
3787:
3788:                            // WebDocWf extension for save without references
3789:                            // The following line has been inserted
3790:                        }
3791:                        // end of WebDocWf extension for save without references
3792:                    }
3793:                    if (false) {
3794:                        // This throw is here to keep the compiler happy
3795:                        // in the case of a DO that does not refer to other DOs.
3796:                        // In that case, the above delete/commit code blocks will be empty
3797:                        // and throw nothing.
3798:                        throw new DataObjectException("foo");
3799:                    }
3800:                    if (delete) {
3801:                        dbt.delete(this );
3802:                        setDeleted(true);
3803:                        _tr_(dbt).resetDeletedDOs();
3804:                    } else {
3805:                        if (isLoaded())
3806:                            dbt.insert(this ); // dbt.insert() handles insertions and updates
3807:                    }
3808:                    if (ownTransaction) {
3809:                        dbt.commit(); // commit the transaction
3810:                    }
3811:                } catch (SQLException sqle) {
3812:                    StringBuffer message = new StringBuffer(
3813:                            "Failed to insert/update DO: ");
3814:                    message.append(sqle.getMessage());
3815:                    // rollback, if necessary
3816:                    if (ownTransaction) {
3817:                        try {
3818:                            dbt.rollback();
3819:                        } catch (SQLException sqle2) {
3820:                            message.insert(0, "\n");
3821:                            message.insert(0, sqle2.getMessage());
3822:                            message.insert(0, "Rollback failed: ");
3823:                        }
3824:                    }
3825:                    throw new SQLException(message.toString());
3826:                } finally {
3827:                    // release the transaction, if any
3828:                    if (ownTransaction) {
3829:                        dbt.release();
3830:                    }
3831:                }
3832:            }
3833:
3834:            private void changedFlags_set(boolean value) {
3835:                changedFirstName = value;
3836:                changedLastName = value;
3837:                changedPhoneNumber = value;
3838:            }
3839:            /*    protected void finalize() throws Throwable {
3840:             System.err.println("("+get_OId().toString()+") refs size("+refs.size()+")");
3841:             }*/
3842:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.