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