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