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