Source Code Cross Referenced for BaseAttributeTypePeer.java in  » Issue-Tracking » scarab-0.21 » org » tigris » scarab » om » 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 » Issue Tracking » scarab 0.21 » org.tigris.scarab.om 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.tigris.scarab.om;
002:
003:        import java.math.BigDecimal;
004:        import java.sql.Connection;
005:        import java.sql.SQLException;
006:        import java.util.ArrayList;
007:        import java.util.Date;
008:        import java.util.Iterator;
009:        import java.util.LinkedList;
010:        import java.util.List;
011:
012:        import org.apache.torque.NoRowsException;
013:        import org.apache.torque.TooManyRowsException;
014:        import org.apache.torque.Torque;
015:        import org.apache.torque.TorqueException;
016:        import org.apache.torque.map.MapBuilder;
017:        import org.apache.torque.map.TableMap;
018:        import org.apache.torque.om.DateKey;
019:        import org.apache.torque.om.NumberKey;
020:        import org.apache.torque.om.StringKey;
021:        import org.apache.torque.om.ObjectKey;
022:        import org.apache.torque.om.SimpleKey;
023:        import org.apache.torque.util.BasePeer;
024:        import org.apache.torque.util.Criteria;
025:
026:        import com.workingdogs.village.DataSetException;
027:        import com.workingdogs.village.QueryDataSet;
028:        import com.workingdogs.village.Record;
029:
030:        // Local classes
031:        import org.tigris.scarab.om.map.*;
032:
033:        /**
034:         */
035:        public abstract class BaseAttributeTypePeer extends BasePeer {
036:
037:            /** the default database name for this class */
038:            public static final String DATABASE_NAME = "scarab";
039:
040:            /** the table name for this class */
041:            public static final String TABLE_NAME = "SCARAB_ATTRIBUTE_TYPE";
042:
043:            /**
044:             * @return the map builder for this peer
045:             * @throws TorqueException Any exceptions caught during processing will be
046:             *         rethrown wrapped into a TorqueException.
047:             */
048:            public static MapBuilder getMapBuilder() throws TorqueException {
049:                return getMapBuilder(AttributeTypeMapBuilder.CLASS_NAME);
050:            }
051:
052:            /** the column name for the ATTRIBUTE_TYPE_ID field */
053:            public static final String ATTRIBUTE_TYPE_ID;
054:            /** the column name for the ATTRIBUTE_CLASS_ID field */
055:            public static final String ATTRIBUTE_CLASS_ID;
056:            /** the column name for the ATTRIBUTE_TYPE_NAME field */
057:            public static final String ATTRIBUTE_TYPE_NAME;
058:            /** the column name for the JAVA_CLASS_NAME field */
059:            public static final String JAVA_CLASS_NAME;
060:            /** the column name for the VALIDATION_KEY field */
061:            public static final String VALIDATION_KEY;
062:
063:            static {
064:                ATTRIBUTE_TYPE_ID = "SCARAB_ATTRIBUTE_TYPE.ATTRIBUTE_TYPE_ID";
065:                ATTRIBUTE_CLASS_ID = "SCARAB_ATTRIBUTE_TYPE.ATTRIBUTE_CLASS_ID";
066:                ATTRIBUTE_TYPE_NAME = "SCARAB_ATTRIBUTE_TYPE.ATTRIBUTE_TYPE_NAME";
067:                JAVA_CLASS_NAME = "SCARAB_ATTRIBUTE_TYPE.JAVA_CLASS_NAME";
068:                VALIDATION_KEY = "SCARAB_ATTRIBUTE_TYPE.VALIDATION_KEY";
069:                if (Torque.isInit()) {
070:                    try {
071:                        getMapBuilder(AttributeTypeMapBuilder.CLASS_NAME);
072:                    } catch (Exception e) {
073:                        log.error("Could not initialize Peer", e);
074:                        throw new RuntimeException(e);
075:                    }
076:                } else {
077:                    Torque
078:                            .registerMapBuilder(AttributeTypeMapBuilder.CLASS_NAME);
079:                }
080:            }
081:
082:            /** number of columns for this peer */
083:            public static final int numColumns = 5;
084:
085:            /** A class that can be returned by this peer. */
086:            protected static final String CLASSNAME_DEFAULT = "org.tigris.scarab.om.AttributeType";
087:
088:            /** A class that can be returned by this peer. */
089:            protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
090:
091:            /**
092:             * Class object initialization method.
093:             *
094:             * @param className name of the class to initialize
095:             * @return the initialized class
096:             */
097:            private static Class initClass(String className) {
098:                Class c = null;
099:                try {
100:                    c = Class.forName(className);
101:                } catch (Throwable t) {
102:                    log
103:                            .error(
104:                                    "A FATAL ERROR has occurred which should not "
105:                                            + "have happened under any circumstance.  Please notify "
106:                                            + "the Torque developers <torque-dev@db.apache.org> "
107:                                            + "and give as many details as possible (including the error "
108:                                            + "stack trace).", t);
109:
110:                    // Error objects should always be propogated.
111:                    if (t instanceof  Error) {
112:                        throw (Error) t.fillInStackTrace();
113:                    }
114:                }
115:                return c;
116:            }
117:
118:            /**
119:             * Get the list of objects for a ResultSet.  Please not that your
120:             * resultset MUST return columns in the right order.  You can use
121:             * getFieldNames() in BaseObject to get the correct sequence.
122:             *
123:             * @param results the ResultSet
124:             * @return the list of objects
125:             * @throws TorqueException Any exceptions caught during processing will be
126:             *         rethrown wrapped into a TorqueException.
127:             */
128:            public static List resultSet2Objects(java.sql.ResultSet results)
129:                    throws TorqueException {
130:                try {
131:                    QueryDataSet qds = null;
132:                    List rows = null;
133:                    try {
134:                        qds = new QueryDataSet(results);
135:                        rows = getSelectResults(qds);
136:                    } finally {
137:                        if (qds != null) {
138:                            qds.close();
139:                        }
140:                    }
141:
142:                    return populateObjects(rows);
143:                } catch (SQLException e) {
144:                    throw new TorqueException(e);
145:                } catch (DataSetException e) {
146:                    throw new TorqueException(e);
147:                }
148:            }
149:
150:            /**
151:             * Method to do inserts.
152:             *
153:             * @param criteria object used to create the INSERT statement.
154:             * @throws TorqueException Any exceptions caught during processing will be
155:             *         rethrown wrapped into a TorqueException.
156:             */
157:            public static ObjectKey doInsert(Criteria criteria)
158:                    throws TorqueException {
159:                return BaseAttributeTypePeer.doInsert(criteria,
160:                        (Connection) null);
161:            }
162:
163:            /**
164:             * Method to do inserts.  This method is to be used during a transaction,
165:             * otherwise use the doInsert(Criteria) method.  It will take care of
166:             * the connection details internally.
167:             *
168:             * @param criteria object used to create the INSERT statement.
169:             * @param con the connection to use
170:             * @throws TorqueException Any exceptions caught during processing will be
171:             *         rethrown wrapped into a TorqueException.
172:             */
173:            public static ObjectKey doInsert(Criteria criteria, Connection con)
174:                    throws TorqueException {
175:                correctBooleans(criteria);
176:
177:                setDbName(criteria);
178:
179:                if (con == null) {
180:                    return BasePeer.doInsert(criteria);
181:                } else {
182:                    return BasePeer.doInsert(criteria, con);
183:                }
184:            }
185:
186:            /**
187:             * Add all the columns needed to create a new object.
188:             *
189:             * @param criteria object containing the columns to add.
190:             * @throws TorqueException Any exceptions caught during processing will be
191:             *         rethrown wrapped into a TorqueException.
192:             */
193:            public static void addSelectColumns(Criteria criteria)
194:                    throws TorqueException {
195:                criteria.addSelectColumn(ATTRIBUTE_TYPE_ID);
196:                criteria.addSelectColumn(ATTRIBUTE_CLASS_ID);
197:                criteria.addSelectColumn(ATTRIBUTE_TYPE_NAME);
198:                criteria.addSelectColumn(JAVA_CLASS_NAME);
199:                criteria.addSelectColumn(VALIDATION_KEY);
200:            }
201:
202:            /**
203:             * changes the boolean values in the criteria to the appropriate type,
204:             * whenever a booleanchar or booleanint column is involved.
205:             * This enables the user to create criteria using Boolean values
206:             * for booleanchar or booleanint columns
207:             * @param criteria the criteria in which the boolean values should be corrected
208:             */
209:            public static void correctBooleans(Criteria criteria) {
210:            }
211:
212:            /**
213:             * Create a new object of type cls from a resultset row starting
214:             * from a specified offset.  This is done so that you can select
215:             * other rows than just those needed for this object.  You may
216:             * for example want to create two objects from the same row.
217:             *
218:             * @throws TorqueException Any exceptions caught during processing will be
219:             *         rethrown wrapped into a TorqueException.
220:             */
221:            public static AttributeType row2Object(Record row, int offset,
222:                    Class cls) throws TorqueException {
223:                try {
224:                    AttributeType obj = (AttributeType) cls.newInstance();
225:                    AttributeTypePeer.populateObject(row, offset, obj);
226:                    obj.setModified(false);
227:                    obj.setNew(false);
228:
229:                    return obj;
230:                } catch (InstantiationException e) {
231:                    throw new TorqueException(e);
232:                } catch (IllegalAccessException e) {
233:                    throw new TorqueException(e);
234:                }
235:            }
236:
237:            /**
238:             * Populates an object from a resultset row starting
239:             * from a specified offset.  This is done so that you can select
240:             * other rows than just those needed for this object.  You may
241:             * for example want to create two objects from the same row.
242:             *
243:             * @throws TorqueException Any exceptions caught during processing will be
244:             *         rethrown wrapped into a TorqueException.
245:             */
246:            public static void populateObject(Record row, int offset,
247:                    AttributeType obj) throws TorqueException {
248:                try {
249:                    obj.setAttributeTypeId(row.getValue(offset + 0)
250:                            .asIntegerObj());
251:                    obj.setClassId(row.getValue(offset + 1).asIntegerObj());
252:                    obj.setName(row.getValue(offset + 2).asString());
253:                    obj.setJavaClassName(row.getValue(offset + 3).asString());
254:                    obj.setValidationKey(row.getValue(offset + 4).asString());
255:                } catch (DataSetException e) {
256:                    throw new TorqueException(e);
257:                }
258:            }
259:
260:            /**
261:             * Method to do selects.
262:             *
263:             * @param criteria object used to create the SELECT statement.
264:             * @return List of selected Objects
265:             * @throws TorqueException Any exceptions caught during processing will be
266:             *         rethrown wrapped into a TorqueException.
267:             */
268:            public static List doSelect(Criteria criteria)
269:                    throws TorqueException {
270:                return populateObjects(doSelectVillageRecords(criteria));
271:            }
272:
273:            /**
274:             * Method to do selects within a transaction.
275:             *
276:             * @param criteria object used to create the SELECT statement.
277:             * @param con the connection to use
278:             * @return List of selected Objects
279:             * @throws TorqueException Any exceptions caught during processing will be
280:             *         rethrown wrapped into a TorqueException.
281:             */
282:            public static List doSelect(Criteria criteria, Connection con)
283:                    throws TorqueException {
284:                return populateObjects(doSelectVillageRecords(criteria, con));
285:            }
286:
287:            /**
288:             * Grabs the raw Village records to be formed into objects.
289:             * This method handles connections internally.  The Record objects
290:             * returned by this method should be considered readonly.  Do not
291:             * alter the data and call save(), your results may vary, but are
292:             * certainly likely to result in hard to track MT bugs.
293:             *
294:             * @throws TorqueException Any exceptions caught during processing will be
295:             *         rethrown wrapped into a TorqueException.
296:             */
297:            public static List doSelectVillageRecords(Criteria criteria)
298:                    throws TorqueException {
299:                return BaseAttributeTypePeer.doSelectVillageRecords(criteria,
300:                        (Connection) null);
301:            }
302:
303:            /**
304:             * Grabs the raw Village records to be formed into objects.
305:             * This method should be used for transactions
306:             *
307:             * @param criteria object used to create the SELECT statement.
308:             * @param con the connection to use
309:             * @throws TorqueException Any exceptions caught during processing will be
310:             *         rethrown wrapped into a TorqueException.
311:             */
312:            public static List doSelectVillageRecords(Criteria criteria,
313:                    Connection con) throws TorqueException {
314:                if (criteria.getSelectColumns().size() == 0) {
315:                    addSelectColumns(criteria);
316:                }
317:                correctBooleans(criteria);
318:
319:                setDbName(criteria);
320:
321:                // BasePeer returns a List of Value (Village) arrays.  The array
322:                // order follows the order columns were placed in the Select clause.
323:                if (con == null) {
324:                    return BasePeer.doSelect(criteria);
325:                } else {
326:                    return BasePeer.doSelect(criteria, con);
327:                }
328:            }
329:
330:            /**
331:             * The returned List will contain objects of the default type or
332:             * objects that inherit from the default.
333:             *
334:             * @throws TorqueException Any exceptions caught during processing will be
335:             *         rethrown wrapped into a TorqueException.
336:             */
337:            public static List populateObjects(List records)
338:                    throws TorqueException {
339:                List results = new ArrayList(records.size());
340:
341:                // populate the object(s)
342:                for (int i = 0; i < records.size(); i++) {
343:                    Record row = (Record) records.get(i);
344:                    results.add(AttributeTypePeer.row2Object(row, 1,
345:                            AttributeTypePeer.getOMClass()));
346:                }
347:                return results;
348:            }
349:
350:            /**
351:             * The class that the Peer will make instances of.
352:             * If the BO is abstract then you must implement this method
353:             * in the BO.
354:             *
355:             * @throws TorqueException Any exceptions caught during processing will be
356:             *         rethrown wrapped into a TorqueException.
357:             */
358:            public static Class getOMClass() throws TorqueException {
359:                return CLASS_DEFAULT;
360:            }
361:
362:            /**
363:             * Method to do updates.
364:             *
365:             * @param criteria object containing data that is used to create the UPDATE
366:             *        statement.
367:             * @throws TorqueException Any exceptions caught during processing will be
368:             *         rethrown wrapped into a TorqueException.
369:             */
370:            public static void doUpdate(Criteria criteria)
371:                    throws TorqueException {
372:                BaseAttributeTypePeer.doUpdate(criteria, (Connection) null);
373:            }
374:
375:            /**
376:             * Method to do updates.  This method is to be used during a transaction,
377:             * otherwise use the doUpdate(Criteria) method.  It will take care of
378:             * the connection details internally.
379:             *
380:             * @param criteria object containing data that is used to create the UPDATE
381:             *        statement.
382:             * @param con the connection to use
383:             * @throws TorqueException Any exceptions caught during processing will be
384:             *         rethrown wrapped into a TorqueException.
385:             */
386:            public static void doUpdate(Criteria criteria, Connection con)
387:                    throws TorqueException {
388:                Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
389:                correctBooleans(criteria);
390:
391:                selectCriteria.put(ATTRIBUTE_TYPE_ID, criteria
392:                        .remove(ATTRIBUTE_TYPE_ID));
393:
394:                setDbName(criteria);
395:
396:                if (con == null) {
397:                    BasePeer.doUpdate(selectCriteria, criteria);
398:                } else {
399:                    BasePeer.doUpdate(selectCriteria, criteria, con);
400:                }
401:            }
402:
403:            /**
404:             * Method to do deletes.
405:             *
406:             * @param criteria object containing data that is used DELETE from database.
407:             * @throws TorqueException Any exceptions caught during processing will be
408:             *         rethrown wrapped into a TorqueException.
409:             */
410:            public static void doDelete(Criteria criteria)
411:                    throws TorqueException {
412:                AttributeTypePeer.doDelete(criteria, (Connection) null);
413:            }
414:
415:            /**
416:             * Method to do deletes.  This method is to be used during a transaction,
417:             * otherwise use the doDelete(Criteria) method.  It will take care of
418:             * the connection details internally.
419:             *
420:             * @param criteria object containing data that is used DELETE from database.
421:             * @param con the connection to use
422:             * @throws TorqueException Any exceptions caught during processing will be
423:             *         rethrown wrapped into a TorqueException.
424:             */
425:            public static void doDelete(Criteria criteria, Connection con)
426:                    throws TorqueException {
427:                correctBooleans(criteria);
428:
429:                setDbName(criteria);
430:
431:                if (con == null) {
432:                    BasePeer.doDelete(criteria);
433:                } else {
434:                    BasePeer.doDelete(criteria, con);
435:                }
436:            }
437:
438:            /**
439:             * Method to do selects
440:             *
441:             * @throws TorqueException Any exceptions caught during processing will be
442:             *         rethrown wrapped into a TorqueException.
443:             */
444:            public static List doSelect(AttributeType obj)
445:                    throws TorqueException {
446:                return doSelect(buildSelectCriteria(obj));
447:            }
448:
449:            /**
450:             * Method to do inserts
451:             *
452:             * @throws TorqueException Any exceptions caught during processing will be
453:             *         rethrown wrapped into a TorqueException.
454:             */
455:            public static void doInsert(AttributeType obj)
456:                    throws TorqueException {
457:                obj.setPrimaryKey(doInsert(buildCriteria(obj)));
458:                obj.setNew(false);
459:                obj.setModified(false);
460:            }
461:
462:            /**
463:             * @param obj the data object to update in the database.
464:             * @throws TorqueException Any exceptions caught during processing will be
465:             *         rethrown wrapped into a TorqueException.
466:             */
467:            public static void doUpdate(AttributeType obj)
468:                    throws TorqueException {
469:                doUpdate(buildCriteria(obj));
470:                obj.setModified(false);
471:            }
472:
473:            /**
474:             * @param obj the data object to delete in the database.
475:             * @throws TorqueException Any exceptions caught during processing will be
476:             *         rethrown wrapped into a TorqueException.
477:             */
478:            public static void doDelete(AttributeType obj)
479:                    throws TorqueException {
480:                doDelete(buildSelectCriteria(obj));
481:            }
482:
483:            /**
484:             * Method to do inserts.  This method is to be used during a transaction,
485:             * otherwise use the doInsert(AttributeType) method.  It will take
486:             * care of the connection details internally.
487:             *
488:             * @param obj the data object to insert into the database.
489:             * @param con the connection to use
490:             * @throws TorqueException Any exceptions caught during processing will be
491:             *         rethrown wrapped into a TorqueException.
492:             */
493:            public static void doInsert(AttributeType obj, Connection con)
494:                    throws TorqueException {
495:                obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
496:                obj.setNew(false);
497:                obj.setModified(false);
498:            }
499:
500:            /**
501:             * Method to do update.  This method is to be used during a transaction,
502:             * otherwise use the doUpdate(AttributeType) method.  It will take
503:             * care of the connection details internally.
504:             *
505:             * @param obj the data object to update in the database.
506:             * @param con the connection to use
507:             * @throws TorqueException Any exceptions caught during processing will be
508:             *         rethrown wrapped into a TorqueException.
509:             */
510:            public static void doUpdate(AttributeType obj, Connection con)
511:                    throws TorqueException {
512:                doUpdate(buildCriteria(obj), con);
513:                obj.setModified(false);
514:            }
515:
516:            /**
517:             * Method to delete.  This method is to be used during a transaction,
518:             * otherwise use the doDelete(AttributeType) method.  It will take
519:             * care of the connection details internally.
520:             *
521:             * @param obj the data object to delete in the database.
522:             * @param con the connection to use
523:             * @throws TorqueException Any exceptions caught during processing will be
524:             *         rethrown wrapped into a TorqueException.
525:             */
526:            public static void doDelete(AttributeType obj, Connection con)
527:                    throws TorqueException {
528:                doDelete(buildSelectCriteria(obj), con);
529:            }
530:
531:            /**
532:             * Method to do deletes.
533:             *
534:             * @param pk ObjectKey that is used DELETE from database.
535:             * @throws TorqueException Any exceptions caught during processing will be
536:             *         rethrown wrapped into a TorqueException.
537:             */
538:            public static void doDelete(ObjectKey pk) throws TorqueException {
539:                BaseAttributeTypePeer.doDelete(pk, (Connection) null);
540:            }
541:
542:            /**
543:             * Method to delete.  This method is to be used during a transaction,
544:             * otherwise use the doDelete(ObjectKey) method.  It will take
545:             * care of the connection details internally.
546:             *
547:             * @param pk the primary key for the object to delete in the database.
548:             * @param con the connection to use
549:             * @throws TorqueException Any exceptions caught during processing will be
550:             *         rethrown wrapped into a TorqueException.
551:             */
552:            public static void doDelete(ObjectKey pk, Connection con)
553:                    throws TorqueException {
554:                doDelete(buildCriteria(pk), con);
555:            }
556:
557:            /** Build a Criteria object from an ObjectKey */
558:            public static Criteria buildCriteria(ObjectKey pk) {
559:                Criteria criteria = new Criteria();
560:                criteria.add(ATTRIBUTE_TYPE_ID, pk);
561:                return criteria;
562:            }
563:
564:            /** Build a Criteria object from the data object for this peer */
565:            public static Criteria buildCriteria(AttributeType obj) {
566:                Criteria criteria = new Criteria(DATABASE_NAME);
567:                if (!obj.isNew())
568:                    criteria.add(ATTRIBUTE_TYPE_ID, obj.getAttributeTypeId());
569:                criteria.add(ATTRIBUTE_CLASS_ID, obj.getClassId());
570:                criteria.add(ATTRIBUTE_TYPE_NAME, obj.getName());
571:                criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
572:                criteria.add(VALIDATION_KEY, obj.getValidationKey());
573:                return criteria;
574:            }
575:
576:            /** Build a Criteria object from the data object for this peer, skipping all binary columns */
577:            public static Criteria buildSelectCriteria(AttributeType obj) {
578:                Criteria criteria = new Criteria(DATABASE_NAME);
579:                if (!obj.isNew()) {
580:                    criteria.add(ATTRIBUTE_TYPE_ID, obj.getAttributeTypeId());
581:                }
582:                criteria.add(ATTRIBUTE_CLASS_ID, obj.getClassId());
583:                criteria.add(ATTRIBUTE_TYPE_NAME, obj.getName());
584:                criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
585:                criteria.add(VALIDATION_KEY, obj.getValidationKey());
586:                return criteria;
587:            }
588:
589:            /**
590:             * Retrieve a single object by pk
591:             *
592:             * @param pk the primary key
593:             * @throws TorqueException Any exceptions caught during processing will be
594:             *         rethrown wrapped into a TorqueException.
595:             * @throws NoRowsException Primary key was not found in database.
596:             * @throws TooManyRowsException Primary key was not found in database.
597:             */
598:            public static AttributeType retrieveByPK(Integer pk)
599:                    throws TorqueException, NoRowsException,
600:                    TooManyRowsException {
601:                return retrieveByPK(SimpleKey.keyFor(pk));
602:            }
603:
604:            /**
605:             * Retrieve a single object by pk
606:             *
607:             * @param pk the primary key
608:             * @param con the connection to use
609:             * @throws TorqueException Any exceptions caught during processing will be
610:             *         rethrown wrapped into a TorqueException.
611:             * @throws NoRowsException Primary key was not found in database.
612:             * @throws TooManyRowsException Primary key was not found in database.
613:             */
614:            public static AttributeType retrieveByPK(Integer pk, Connection con)
615:                    throws TorqueException, NoRowsException,
616:                    TooManyRowsException {
617:                return retrieveByPK(SimpleKey.keyFor(pk), con);
618:            }
619:
620:            /**
621:             * Retrieve a single object by pk
622:             *
623:             * @param pk the primary key
624:             * @throws TorqueException Any exceptions caught during processing will be
625:             *         rethrown wrapped into a TorqueException.
626:             * @throws NoRowsException Primary key was not found in database.
627:             * @throws TooManyRowsException Primary key was not found in database.
628:             */
629:            public static AttributeType retrieveByPK(ObjectKey pk)
630:                    throws TorqueException, NoRowsException,
631:                    TooManyRowsException {
632:                Connection db = null;
633:                AttributeType retVal = null;
634:                try {
635:                    db = Torque.getConnection(DATABASE_NAME);
636:                    retVal = retrieveByPK(pk, db);
637:                } finally {
638:                    Torque.closeConnection(db);
639:                }
640:                return retVal;
641:            }
642:
643:            /**
644:             * Retrieve a single object by pk
645:             *
646:             * @param pk the primary key
647:             * @param con the connection to use
648:             * @throws TorqueException Any exceptions caught during processing will be
649:             *         rethrown wrapped into a TorqueException.
650:             * @throws NoRowsException Primary key was not found in database.
651:             * @throws TooManyRowsException Primary key was not found in database.
652:             */
653:            public static AttributeType retrieveByPK(ObjectKey pk,
654:                    Connection con) throws TorqueException, NoRowsException,
655:                    TooManyRowsException {
656:                Criteria criteria = buildCriteria(pk);
657:                List v = doSelect(criteria, con);
658:                if (v.size() == 0) {
659:                    throw new NoRowsException("Failed to select a row.");
660:                } else if (v.size() > 1) {
661:                    throw new TooManyRowsException(
662:                            "Failed to select only one row.");
663:                } else {
664:                    return (AttributeType) v.get(0);
665:                }
666:            }
667:
668:            /**
669:             * Retrieve a multiple objects by pk
670:             *
671:             * @param pks List of primary keys
672:             * @throws TorqueException Any exceptions caught during processing will be
673:             *         rethrown wrapped into a TorqueException.
674:             */
675:            public static List retrieveByPKs(List pks) throws TorqueException {
676:                Connection db = null;
677:                List retVal = null;
678:                try {
679:                    db = Torque.getConnection(DATABASE_NAME);
680:                    retVal = retrieveByPKs(pks, db);
681:                } finally {
682:                    Torque.closeConnection(db);
683:                }
684:                return retVal;
685:            }
686:
687:            /**
688:             * Retrieve a multiple objects by pk
689:             *
690:             * @param pks List of primary keys
691:             * @param dbcon the connection to use
692:             * @throws TorqueException Any exceptions caught during processing will be
693:             *         rethrown wrapped into a TorqueException.
694:             */
695:            public static List retrieveByPKs(List pks, Connection dbcon)
696:                    throws TorqueException {
697:                List objs = null;
698:                if (pks == null || pks.size() == 0) {
699:                    objs = new LinkedList();
700:                } else {
701:                    Criteria criteria = new Criteria();
702:                    criteria.addIn(ATTRIBUTE_TYPE_ID, pks);
703:                    objs = doSelect(criteria, dbcon);
704:                }
705:                return objs;
706:            }
707:
708:            /**
709:             * selects a collection of AttributeType objects pre-filled with their
710:             * AttributeClass objects.
711:             *
712:             * This method is protected by default in order to keep the public
713:             * api reasonable.  You can provide public methods for those you
714:             * actually need in AttributeTypePeer.
715:             *
716:             * @throws TorqueException Any exceptions caught during processing will be
717:             *         rethrown wrapped into a TorqueException.
718:             */
719:            protected static List doSelectJoinAttributeClass(Criteria criteria)
720:                    throws TorqueException {
721:                return doSelectJoinAttributeClass(criteria, null);
722:            }
723:
724:            /**
725:             * selects a collection of AttributeType objects pre-filled with their
726:             * AttributeClass objects.
727:             *
728:             * This method is protected by default in order to keep the public
729:             * api reasonable.  You can provide public methods for those you
730:             * actually need in AttributeTypePeer.
731:             *
732:             * @throws TorqueException Any exceptions caught during processing will be
733:             *         rethrown wrapped into a TorqueException.
734:             */
735:            protected static List doSelectJoinAttributeClass(Criteria criteria,
736:                    Connection conn) throws TorqueException {
737:                setDbName(criteria);
738:
739:                AttributeTypePeer.addSelectColumns(criteria);
740:                int offset = numColumns + 1;
741:                AttributeClassPeer.addSelectColumns(criteria);
742:
743:                criteria.addJoin(AttributeTypePeer.ATTRIBUTE_CLASS_ID,
744:                        AttributeClassPeer.ATTRIBUTE_CLASS_ID);
745:
746:                correctBooleans(criteria);
747:
748:                List rows;
749:                if (conn == null) {
750:                    rows = BasePeer.doSelect(criteria);
751:                } else {
752:                    rows = BasePeer.doSelect(criteria, conn);
753:                }
754:
755:                List results = new ArrayList();
756:
757:                for (int i = 0; i < rows.size(); i++) {
758:                    Record row = (Record) rows.get(i);
759:
760:                    Class omClass = AttributeTypePeer.getOMClass();
761:                    AttributeType obj1 = (AttributeType) AttributeTypePeer
762:                            .row2Object(row, 1, omClass);
763:                    omClass = AttributeClassPeer.getOMClass();
764:                    AttributeClass obj2 = (AttributeClass) AttributeClassPeer
765:                            .row2Object(row, offset, omClass);
766:
767:                    boolean newObject = true;
768:                    for (int j = 0; j < results.size(); j++) {
769:                        AttributeType temp_obj1 = (AttributeType) results
770:                                .get(j);
771:                        AttributeClass temp_obj2 = (AttributeClass) temp_obj1
772:                                .getAttributeClass();
773:                        if (temp_obj2.getPrimaryKey().equals(
774:                                obj2.getPrimaryKey())) {
775:                            newObject = false;
776:                            temp_obj2.addAttributeType(obj1);
777:                            break;
778:                        }
779:                    }
780:                    if (newObject) {
781:                        obj2.initAttributeTypes();
782:                        obj2.addAttributeType(obj1);
783:                    }
784:                    results.add(obj1);
785:                }
786:                return results;
787:            }
788:
789:            /**
790:             * Returns the TableMap related to this peer.  This method is not
791:             * needed for general use but a specific application could have a need.
792:             *
793:             * @throws TorqueException Any exceptions caught during processing will be
794:             *         rethrown wrapped into a TorqueException.
795:             */
796:            protected static TableMap getTableMap() throws TorqueException {
797:                return Torque.getDatabaseMap(DATABASE_NAME)
798:                        .getTable(TABLE_NAME);
799:            }
800:
801:            private static void setDbName(Criteria crit) {
802:                // Set the correct dbName if it has not been overridden
803:                // crit.getDbName will return the same object if not set to
804:                // another value so == check is okay and faster
805:                if (crit.getDbName() == Torque.getDefaultDB()) {
806:                    crit.setDbName(DATABASE_NAME);
807:                }
808:            }
809:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.