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