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