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