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