Source Code Cross Referenced for BaseAttributeClassPeer.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 BaseAttributeClassPeer 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_ATTRIBUTE_CLASS";
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(AttributeClassMapBuilder.CLASS_NAME);
050:            }
051:
052:            /** the column name for the ATTRIBUTE_CLASS_ID field */
053:            public static final String ATTRIBUTE_CLASS_ID;
054:            /** the column name for the ATTRIBUTE_CLASS_NAME field */
055:            public static final String ATTRIBUTE_CLASS_NAME;
056:            /** the column name for the ATTRIBUTE_CLASS_DESC field */
057:            public static final String ATTRIBUTE_CLASS_DESC;
058:            /** the column name for the JAVA_CLASS_NAME field */
059:            public static final String JAVA_CLASS_NAME;
060:
061:            static {
062:                ATTRIBUTE_CLASS_ID = "SCARAB_ATTRIBUTE_CLASS.ATTRIBUTE_CLASS_ID";
063:                ATTRIBUTE_CLASS_NAME = "SCARAB_ATTRIBUTE_CLASS.ATTRIBUTE_CLASS_NAME";
064:                ATTRIBUTE_CLASS_DESC = "SCARAB_ATTRIBUTE_CLASS.ATTRIBUTE_CLASS_DESC";
065:                JAVA_CLASS_NAME = "SCARAB_ATTRIBUTE_CLASS.JAVA_CLASS_NAME";
066:                if (Torque.isInit()) {
067:                    try {
068:                        getMapBuilder(AttributeClassMapBuilder.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(AttributeClassMapBuilder.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.AttributeClass";
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 BaseAttributeClassPeer.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(ATTRIBUTE_CLASS_ID);
193:                criteria.addSelectColumn(ATTRIBUTE_CLASS_NAME);
194:                criteria.addSelectColumn(ATTRIBUTE_CLASS_DESC);
195:                criteria.addSelectColumn(JAVA_CLASS_NAME);
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 AttributeClass row2Object(Record row, int offset,
218:                    Class cls) throws TorqueException {
219:                try {
220:                    AttributeClass obj = (AttributeClass) cls.newInstance();
221:                    AttributeClassPeer.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:                    AttributeClass obj) throws TorqueException {
244:                try {
245:                    obj.setAttributeClassId(row.getValue(offset + 0)
246:                            .asIntegerObj());
247:                    obj.setName(row.getValue(offset + 1).asString());
248:                    obj.setDesc(row.getValue(offset + 2).asString());
249:                    obj.setJavaClassName(row.getValue(offset + 3).asString());
250:                } catch (DataSetException e) {
251:                    throw new TorqueException(e);
252:                }
253:            }
254:
255:            /**
256:             * Method to do selects.
257:             *
258:             * @param criteria object used to create the SELECT statement.
259:             * @return List of selected Objects
260:             * @throws TorqueException Any exceptions caught during processing will be
261:             *         rethrown wrapped into a TorqueException.
262:             */
263:            public static List doSelect(Criteria criteria)
264:                    throws TorqueException {
265:                return populateObjects(doSelectVillageRecords(criteria));
266:            }
267:
268:            /**
269:             * Method to do selects within a transaction.
270:             *
271:             * @param criteria object used to create the SELECT statement.
272:             * @param con the connection to use
273:             * @return List of selected Objects
274:             * @throws TorqueException Any exceptions caught during processing will be
275:             *         rethrown wrapped into a TorqueException.
276:             */
277:            public static List doSelect(Criteria criteria, Connection con)
278:                    throws TorqueException {
279:                return populateObjects(doSelectVillageRecords(criteria, con));
280:            }
281:
282:            /**
283:             * Grabs the raw Village records to be formed into objects.
284:             * This method handles connections internally.  The Record objects
285:             * returned by this method should be considered readonly.  Do not
286:             * alter the data and call save(), your results may vary, but are
287:             * certainly likely to result in hard to track MT bugs.
288:             *
289:             * @throws TorqueException Any exceptions caught during processing will be
290:             *         rethrown wrapped into a TorqueException.
291:             */
292:            public static List doSelectVillageRecords(Criteria criteria)
293:                    throws TorqueException {
294:                return BaseAttributeClassPeer.doSelectVillageRecords(criteria,
295:                        (Connection) null);
296:            }
297:
298:            /**
299:             * Grabs the raw Village records to be formed into objects.
300:             * This method should be used for transactions
301:             *
302:             * @param criteria object used to create the SELECT statement.
303:             * @param con the connection to use
304:             * @throws TorqueException Any exceptions caught during processing will be
305:             *         rethrown wrapped into a TorqueException.
306:             */
307:            public static List doSelectVillageRecords(Criteria criteria,
308:                    Connection con) throws TorqueException {
309:                if (criteria.getSelectColumns().size() == 0) {
310:                    addSelectColumns(criteria);
311:                }
312:                correctBooleans(criteria);
313:
314:                setDbName(criteria);
315:
316:                // BasePeer returns a List of Value (Village) arrays.  The array
317:                // order follows the order columns were placed in the Select clause.
318:                if (con == null) {
319:                    return BasePeer.doSelect(criteria);
320:                } else {
321:                    return BasePeer.doSelect(criteria, con);
322:                }
323:            }
324:
325:            /**
326:             * The returned List will contain objects of the default type or
327:             * objects that inherit from the default.
328:             *
329:             * @throws TorqueException Any exceptions caught during processing will be
330:             *         rethrown wrapped into a TorqueException.
331:             */
332:            public static List populateObjects(List records)
333:                    throws TorqueException {
334:                List results = new ArrayList(records.size());
335:
336:                // populate the object(s)
337:                for (int i = 0; i < records.size(); i++) {
338:                    Record row = (Record) records.get(i);
339:                    results.add(AttributeClassPeer.row2Object(row, 1,
340:                            AttributeClassPeer.getOMClass()));
341:                }
342:                return results;
343:            }
344:
345:            /**
346:             * The class that the Peer will make instances of.
347:             * If the BO is abstract then you must implement this method
348:             * in the BO.
349:             *
350:             * @throws TorqueException Any exceptions caught during processing will be
351:             *         rethrown wrapped into a TorqueException.
352:             */
353:            public static Class getOMClass() throws TorqueException {
354:                return CLASS_DEFAULT;
355:            }
356:
357:            /**
358:             * Method to do updates.
359:             *
360:             * @param criteria object containing data that is used to create the UPDATE
361:             *        statement.
362:             * @throws TorqueException Any exceptions caught during processing will be
363:             *         rethrown wrapped into a TorqueException.
364:             */
365:            public static void doUpdate(Criteria criteria)
366:                    throws TorqueException {
367:                BaseAttributeClassPeer.doUpdate(criteria, (Connection) null);
368:            }
369:
370:            /**
371:             * Method to do updates.  This method is to be used during a transaction,
372:             * otherwise use the doUpdate(Criteria) method.  It will take care of
373:             * the connection details internally.
374:             *
375:             * @param criteria object containing data that is used to create the UPDATE
376:             *        statement.
377:             * @param con the connection to use
378:             * @throws TorqueException Any exceptions caught during processing will be
379:             *         rethrown wrapped into a TorqueException.
380:             */
381:            public static void doUpdate(Criteria criteria, Connection con)
382:                    throws TorqueException {
383:                Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
384:                correctBooleans(criteria);
385:
386:                selectCriteria.put(ATTRIBUTE_CLASS_ID, criteria
387:                        .remove(ATTRIBUTE_CLASS_ID));
388:
389:                setDbName(criteria);
390:
391:                if (con == null) {
392:                    BasePeer.doUpdate(selectCriteria, criteria);
393:                } else {
394:                    BasePeer.doUpdate(selectCriteria, criteria, con);
395:                }
396:            }
397:
398:            /**
399:             * Method to do deletes.
400:             *
401:             * @param criteria object containing data that is used DELETE from database.
402:             * @throws TorqueException Any exceptions caught during processing will be
403:             *         rethrown wrapped into a TorqueException.
404:             */
405:            public static void doDelete(Criteria criteria)
406:                    throws TorqueException {
407:                AttributeClassPeer.doDelete(criteria, (Connection) null);
408:            }
409:
410:            /**
411:             * Method to do deletes.  This method is to be used during a transaction,
412:             * otherwise use the doDelete(Criteria) method.  It will take care of
413:             * the connection details internally.
414:             *
415:             * @param criteria object containing data that is used DELETE from database.
416:             * @param con the connection to use
417:             * @throws TorqueException Any exceptions caught during processing will be
418:             *         rethrown wrapped into a TorqueException.
419:             */
420:            public static void doDelete(Criteria criteria, Connection con)
421:                    throws TorqueException {
422:                correctBooleans(criteria);
423:
424:                setDbName(criteria);
425:
426:                if (con == null) {
427:                    BasePeer.doDelete(criteria);
428:                } else {
429:                    BasePeer.doDelete(criteria, con);
430:                }
431:            }
432:
433:            /**
434:             * Method to do selects
435:             *
436:             * @throws TorqueException Any exceptions caught during processing will be
437:             *         rethrown wrapped into a TorqueException.
438:             */
439:            public static List doSelect(AttributeClass obj)
440:                    throws TorqueException {
441:                return doSelect(buildSelectCriteria(obj));
442:            }
443:
444:            /**
445:             * Method to do inserts
446:             *
447:             * @throws TorqueException Any exceptions caught during processing will be
448:             *         rethrown wrapped into a TorqueException.
449:             */
450:            public static void doInsert(AttributeClass obj)
451:                    throws TorqueException {
452:                obj.setPrimaryKey(doInsert(buildCriteria(obj)));
453:                obj.setNew(false);
454:                obj.setModified(false);
455:            }
456:
457:            /**
458:             * @param obj the data object to update in the database.
459:             * @throws TorqueException Any exceptions caught during processing will be
460:             *         rethrown wrapped into a TorqueException.
461:             */
462:            public static void doUpdate(AttributeClass obj)
463:                    throws TorqueException {
464:                doUpdate(buildCriteria(obj));
465:                obj.setModified(false);
466:            }
467:
468:            /**
469:             * @param obj the data object to delete in the database.
470:             * @throws TorqueException Any exceptions caught during processing will be
471:             *         rethrown wrapped into a TorqueException.
472:             */
473:            public static void doDelete(AttributeClass obj)
474:                    throws TorqueException {
475:                doDelete(buildSelectCriteria(obj));
476:            }
477:
478:            /**
479:             * Method to do inserts.  This method is to be used during a transaction,
480:             * otherwise use the doInsert(AttributeClass) method.  It will take
481:             * care of the connection details internally.
482:             *
483:             * @param obj the data object to insert into the database.
484:             * @param con the connection to use
485:             * @throws TorqueException Any exceptions caught during processing will be
486:             *         rethrown wrapped into a TorqueException.
487:             */
488:            public static void doInsert(AttributeClass obj, Connection con)
489:                    throws TorqueException {
490:                obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
491:                obj.setNew(false);
492:                obj.setModified(false);
493:            }
494:
495:            /**
496:             * Method to do update.  This method is to be used during a transaction,
497:             * otherwise use the doUpdate(AttributeClass) method.  It will take
498:             * care of the connection details internally.
499:             *
500:             * @param obj the data object to update in the database.
501:             * @param con the connection to use
502:             * @throws TorqueException Any exceptions caught during processing will be
503:             *         rethrown wrapped into a TorqueException.
504:             */
505:            public static void doUpdate(AttributeClass obj, Connection con)
506:                    throws TorqueException {
507:                doUpdate(buildCriteria(obj), con);
508:                obj.setModified(false);
509:            }
510:
511:            /**
512:             * Method to delete.  This method is to be used during a transaction,
513:             * otherwise use the doDelete(AttributeClass) method.  It will take
514:             * care of the connection details internally.
515:             *
516:             * @param obj the data object to delete in the database.
517:             * @param con the connection to use
518:             * @throws TorqueException Any exceptions caught during processing will be
519:             *         rethrown wrapped into a TorqueException.
520:             */
521:            public static void doDelete(AttributeClass obj, Connection con)
522:                    throws TorqueException {
523:                doDelete(buildSelectCriteria(obj), con);
524:            }
525:
526:            /**
527:             * Method to do deletes.
528:             *
529:             * @param pk ObjectKey that is used DELETE from database.
530:             * @throws TorqueException Any exceptions caught during processing will be
531:             *         rethrown wrapped into a TorqueException.
532:             */
533:            public static void doDelete(ObjectKey pk) throws TorqueException {
534:                BaseAttributeClassPeer.doDelete(pk, (Connection) null);
535:            }
536:
537:            /**
538:             * Method to delete.  This method is to be used during a transaction,
539:             * otherwise use the doDelete(ObjectKey) method.  It will take
540:             * care of the connection details internally.
541:             *
542:             * @param pk the primary key for the object to delete in the database.
543:             * @param con the connection to use
544:             * @throws TorqueException Any exceptions caught during processing will be
545:             *         rethrown wrapped into a TorqueException.
546:             */
547:            public static void doDelete(ObjectKey pk, Connection con)
548:                    throws TorqueException {
549:                doDelete(buildCriteria(pk), con);
550:            }
551:
552:            /** Build a Criteria object from an ObjectKey */
553:            public static Criteria buildCriteria(ObjectKey pk) {
554:                Criteria criteria = new Criteria();
555:                criteria.add(ATTRIBUTE_CLASS_ID, pk);
556:                return criteria;
557:            }
558:
559:            /** Build a Criteria object from the data object for this peer */
560:            public static Criteria buildCriteria(AttributeClass obj) {
561:                Criteria criteria = new Criteria(DATABASE_NAME);
562:                if (!obj.isNew())
563:                    criteria.add(ATTRIBUTE_CLASS_ID, obj.getAttributeClassId());
564:                criteria.add(ATTRIBUTE_CLASS_NAME, obj.getName());
565:                criteria.add(ATTRIBUTE_CLASS_DESC, obj.getDesc());
566:                criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
567:                return criteria;
568:            }
569:
570:            /** Build a Criteria object from the data object for this peer, skipping all binary columns */
571:            public static Criteria buildSelectCriteria(AttributeClass obj) {
572:                Criteria criteria = new Criteria(DATABASE_NAME);
573:                if (!obj.isNew()) {
574:                    criteria.add(ATTRIBUTE_CLASS_ID, obj.getAttributeClassId());
575:                }
576:                criteria.add(ATTRIBUTE_CLASS_NAME, obj.getName());
577:                criteria.add(ATTRIBUTE_CLASS_DESC, obj.getDesc());
578:                criteria.add(JAVA_CLASS_NAME, obj.getJavaClassName());
579:                return criteria;
580:            }
581:
582:            /**
583:             * Retrieve a single object by pk
584:             *
585:             * @param pk the primary key
586:             * @throws TorqueException Any exceptions caught during processing will be
587:             *         rethrown wrapped into a TorqueException.
588:             * @throws NoRowsException Primary key was not found in database.
589:             * @throws TooManyRowsException Primary key was not found in database.
590:             */
591:            public static AttributeClass retrieveByPK(Integer pk)
592:                    throws TorqueException, NoRowsException,
593:                    TooManyRowsException {
594:                return retrieveByPK(SimpleKey.keyFor(pk));
595:            }
596:
597:            /**
598:             * Retrieve a single object by pk
599:             *
600:             * @param pk the primary key
601:             * @param con the connection to use
602:             * @throws TorqueException Any exceptions caught during processing will be
603:             *         rethrown wrapped into a TorqueException.
604:             * @throws NoRowsException Primary key was not found in database.
605:             * @throws TooManyRowsException Primary key was not found in database.
606:             */
607:            public static AttributeClass retrieveByPK(Integer pk, Connection con)
608:                    throws TorqueException, NoRowsException,
609:                    TooManyRowsException {
610:                return retrieveByPK(SimpleKey.keyFor(pk), con);
611:            }
612:
613:            /**
614:             * Retrieve a single object by pk
615:             *
616:             * @param pk the primary key
617:             * @throws TorqueException Any exceptions caught during processing will be
618:             *         rethrown wrapped into a TorqueException.
619:             * @throws NoRowsException Primary key was not found in database.
620:             * @throws TooManyRowsException Primary key was not found in database.
621:             */
622:            public static AttributeClass retrieveByPK(ObjectKey pk)
623:                    throws TorqueException, NoRowsException,
624:                    TooManyRowsException {
625:                Connection db = null;
626:                AttributeClass retVal = null;
627:                try {
628:                    db = Torque.getConnection(DATABASE_NAME);
629:                    retVal = retrieveByPK(pk, db);
630:                } finally {
631:                    Torque.closeConnection(db);
632:                }
633:                return retVal;
634:            }
635:
636:            /**
637:             * Retrieve a single object by pk
638:             *
639:             * @param pk the primary key
640:             * @param con the connection to use
641:             * @throws TorqueException Any exceptions caught during processing will be
642:             *         rethrown wrapped into a TorqueException.
643:             * @throws NoRowsException Primary key was not found in database.
644:             * @throws TooManyRowsException Primary key was not found in database.
645:             */
646:            public static AttributeClass retrieveByPK(ObjectKey pk,
647:                    Connection con) throws TorqueException, NoRowsException,
648:                    TooManyRowsException {
649:                Criteria criteria = buildCriteria(pk);
650:                List v = doSelect(criteria, con);
651:                if (v.size() == 0) {
652:                    throw new NoRowsException("Failed to select a row.");
653:                } else if (v.size() > 1) {
654:                    throw new TooManyRowsException(
655:                            "Failed to select only one row.");
656:                } else {
657:                    return (AttributeClass) v.get(0);
658:                }
659:            }
660:
661:            /**
662:             * Retrieve a multiple objects by pk
663:             *
664:             * @param pks List of primary keys
665:             * @throws TorqueException Any exceptions caught during processing will be
666:             *         rethrown wrapped into a TorqueException.
667:             */
668:            public static List retrieveByPKs(List pks) throws TorqueException {
669:                Connection db = null;
670:                List retVal = null;
671:                try {
672:                    db = Torque.getConnection(DATABASE_NAME);
673:                    retVal = retrieveByPKs(pks, db);
674:                } finally {
675:                    Torque.closeConnection(db);
676:                }
677:                return retVal;
678:            }
679:
680:            /**
681:             * Retrieve a multiple objects by pk
682:             *
683:             * @param pks List of primary keys
684:             * @param dbcon the connection to use
685:             * @throws TorqueException Any exceptions caught during processing will be
686:             *         rethrown wrapped into a TorqueException.
687:             */
688:            public static List retrieveByPKs(List pks, Connection dbcon)
689:                    throws TorqueException {
690:                List objs = null;
691:                if (pks == null || pks.size() == 0) {
692:                    objs = new LinkedList();
693:                } else {
694:                    Criteria criteria = new Criteria();
695:                    criteria.addIn(ATTRIBUTE_CLASS_ID, pks);
696:                    objs = doSelect(criteria, dbcon);
697:                }
698:                return objs;
699:            }
700:
701:            /**
702:             * Returns the TableMap related to this peer.  This method is not
703:             * needed for general use but a specific application could have a need.
704:             *
705:             * @throws TorqueException Any exceptions caught during processing will be
706:             *         rethrown wrapped into a TorqueException.
707:             */
708:            protected static TableMap getTableMap() throws TorqueException {
709:                return Torque.getDatabaseMap(DATABASE_NAME)
710:                        .getTable(TABLE_NAME);
711:            }
712:
713:            private static void setDbName(Criteria crit) {
714:                // Set the correct dbName if it has not been overridden
715:                // crit.getDbName will return the same object if not set to
716:                // another value so == check is okay and faster
717:                if (crit.getDbName() == Torque.getDefaultDB()) {
718:                    crit.setDbName(DATABASE_NAME);
719:                }
720:            }
721:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.