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