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