Source Code Cross Referenced for BaseAttributeOptionPeer.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 BaseAttributeOptionPeer 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_OPTION";
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(AttributeOptionMapBuilder.CLASS_NAME);
050:            }
051:
052:            /** the column name for the OPTION_ID field */
053:            public static final String OPTION_ID;
054:            /** the column name for the ATTRIBUTE_ID field */
055:            public static final String ATTRIBUTE_ID;
056:            /** the column name for the OPTION_NAME field */
057:            public static final String OPTION_NAME;
058:            /** the column name for the DELETED field */
059:            public static final String DELETED;
060:
061:            static {
062:                OPTION_ID = "SCARAB_ATTRIBUTE_OPTION.OPTION_ID";
063:                ATTRIBUTE_ID = "SCARAB_ATTRIBUTE_OPTION.ATTRIBUTE_ID";
064:                OPTION_NAME = "SCARAB_ATTRIBUTE_OPTION.OPTION_NAME";
065:                DELETED = "SCARAB_ATTRIBUTE_OPTION.DELETED";
066:                if (Torque.isInit()) {
067:                    try {
068:                        getMapBuilder(AttributeOptionMapBuilder.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(AttributeOptionMapBuilder.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.AttributeOption";
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 BaseAttributeOptionPeer.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(OPTION_ID);
193:                criteria.addSelectColumn(ATTRIBUTE_ID);
194:                criteria.addSelectColumn(OPTION_NAME);
195:                criteria.addSelectColumn(DELETED);
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:                // check for conversion from boolean to int
207:                if (criteria.containsKey(DELETED)) {
208:                    Object possibleBoolean = criteria.get(DELETED);
209:                    if (possibleBoolean instanceof  Boolean) {
210:                        criteria.add(DELETED, ((Boolean) possibleBoolean)
211:                                .booleanValue() ? 1 : 0);
212:                    }
213:                }
214:            }
215:
216:            /**
217:             * Create a new object of type cls from a resultset row starting
218:             * from a specified offset.  This is done so that you can select
219:             * other rows than just those needed for this object.  You may
220:             * for example want to create two objects from the same row.
221:             *
222:             * @throws TorqueException Any exceptions caught during processing will be
223:             *         rethrown wrapped into a TorqueException.
224:             */
225:            public static AttributeOption row2Object(Record row, int offset,
226:                    Class cls) throws TorqueException {
227:                try {
228:                    AttributeOption obj = (AttributeOption) cls.newInstance();
229:                    AttributeOptionPeer.populateObject(row, offset, obj);
230:                    obj.setModified(false);
231:                    obj.setNew(false);
232:
233:                    return obj;
234:                } catch (InstantiationException e) {
235:                    throw new TorqueException(e);
236:                } catch (IllegalAccessException e) {
237:                    throw new TorqueException(e);
238:                }
239:            }
240:
241:            /**
242:             * Populates an object from a resultset row starting
243:             * from a specified offset.  This is done so that you can select
244:             * other rows than just those needed for this object.  You may
245:             * for example want to create two objects from the same row.
246:             *
247:             * @throws TorqueException Any exceptions caught during processing will be
248:             *         rethrown wrapped into a TorqueException.
249:             */
250:            public static void populateObject(Record row, int offset,
251:                    AttributeOption obj) throws TorqueException {
252:                try {
253:                    obj.setOptionId(row.getValue(offset + 0).asIntegerObj());
254:                    obj.setAttributeId(row.getValue(offset + 1).asIntegerObj());
255:                    obj.setName(row.getValue(offset + 2).asString());
256:                    obj.setDeleted(row.getValue(offset + 3).asBoolean());
257:                } catch (DataSetException e) {
258:                    throw new TorqueException(e);
259:                }
260:            }
261:
262:            /**
263:             * Method to do selects.
264:             *
265:             * @param criteria object used to create the SELECT statement.
266:             * @return List of selected Objects
267:             * @throws TorqueException Any exceptions caught during processing will be
268:             *         rethrown wrapped into a TorqueException.
269:             */
270:            public static List doSelect(Criteria criteria)
271:                    throws TorqueException {
272:                return populateObjects(doSelectVillageRecords(criteria));
273:            }
274:
275:            /**
276:             * Method to do selects within a transaction.
277:             *
278:             * @param criteria object used to create the SELECT statement.
279:             * @param con the connection to use
280:             * @return List of selected Objects
281:             * @throws TorqueException Any exceptions caught during processing will be
282:             *         rethrown wrapped into a TorqueException.
283:             */
284:            public static List doSelect(Criteria criteria, Connection con)
285:                    throws TorqueException {
286:                return populateObjects(doSelectVillageRecords(criteria, con));
287:            }
288:
289:            /**
290:             * Grabs the raw Village records to be formed into objects.
291:             * This method handles connections internally.  The Record objects
292:             * returned by this method should be considered readonly.  Do not
293:             * alter the data and call save(), your results may vary, but are
294:             * certainly likely to result in hard to track MT bugs.
295:             *
296:             * @throws TorqueException Any exceptions caught during processing will be
297:             *         rethrown wrapped into a TorqueException.
298:             */
299:            public static List doSelectVillageRecords(Criteria criteria)
300:                    throws TorqueException {
301:                return BaseAttributeOptionPeer.doSelectVillageRecords(criteria,
302:                        (Connection) null);
303:            }
304:
305:            /**
306:             * Grabs the raw Village records to be formed into objects.
307:             * This method should be used for transactions
308:             *
309:             * @param criteria object used to create the SELECT statement.
310:             * @param con the connection to use
311:             * @throws TorqueException Any exceptions caught during processing will be
312:             *         rethrown wrapped into a TorqueException.
313:             */
314:            public static List doSelectVillageRecords(Criteria criteria,
315:                    Connection con) throws TorqueException {
316:                if (criteria.getSelectColumns().size() == 0) {
317:                    addSelectColumns(criteria);
318:                }
319:                correctBooleans(criteria);
320:
321:                setDbName(criteria);
322:
323:                // BasePeer returns a List of Value (Village) arrays.  The array
324:                // order follows the order columns were placed in the Select clause.
325:                if (con == null) {
326:                    return BasePeer.doSelect(criteria);
327:                } else {
328:                    return BasePeer.doSelect(criteria, con);
329:                }
330:            }
331:
332:            /**
333:             * The returned List will contain objects of the default type or
334:             * objects that inherit from the default.
335:             *
336:             * @throws TorqueException Any exceptions caught during processing will be
337:             *         rethrown wrapped into a TorqueException.
338:             */
339:            public static List populateObjects(List records)
340:                    throws TorqueException {
341:                List results = new ArrayList(records.size());
342:
343:                // populate the object(s)
344:                for (int i = 0; i < records.size(); i++) {
345:                    Record row = (Record) records.get(i);
346:                    results.add(AttributeOptionPeer.row2Object(row, 1,
347:                            AttributeOptionPeer.getOMClass()));
348:                }
349:                return results;
350:            }
351:
352:            /**
353:             * The class that the Peer will make instances of.
354:             * If the BO is abstract then you must implement this method
355:             * in the BO.
356:             *
357:             * @throws TorqueException Any exceptions caught during processing will be
358:             *         rethrown wrapped into a TorqueException.
359:             */
360:            public static Class getOMClass() throws TorqueException {
361:                return CLASS_DEFAULT;
362:            }
363:
364:            /**
365:             * Method to do updates.
366:             *
367:             * @param criteria object containing data that is used to create the UPDATE
368:             *        statement.
369:             * @throws TorqueException Any exceptions caught during processing will be
370:             *         rethrown wrapped into a TorqueException.
371:             */
372:            public static void doUpdate(Criteria criteria)
373:                    throws TorqueException {
374:                BaseAttributeOptionPeer.doUpdate(criteria, (Connection) null);
375:            }
376:
377:            /**
378:             * Method to do updates.  This method is to be used during a transaction,
379:             * otherwise use the doUpdate(Criteria) method.  It will take care of
380:             * the connection details internally.
381:             *
382:             * @param criteria object containing data that is used to create the UPDATE
383:             *        statement.
384:             * @param con the connection to use
385:             * @throws TorqueException Any exceptions caught during processing will be
386:             *         rethrown wrapped into a TorqueException.
387:             */
388:            public static void doUpdate(Criteria criteria, Connection con)
389:                    throws TorqueException {
390:                Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
391:                correctBooleans(criteria);
392:
393:                selectCriteria.put(OPTION_ID, criteria.remove(OPTION_ID));
394:
395:                setDbName(criteria);
396:
397:                if (con == null) {
398:                    BasePeer.doUpdate(selectCriteria, criteria);
399:                } else {
400:                    BasePeer.doUpdate(selectCriteria, criteria, con);
401:                }
402:            }
403:
404:            /**
405:             * Method to do deletes.
406:             *
407:             * @param criteria object containing data that is used DELETE from database.
408:             * @throws TorqueException Any exceptions caught during processing will be
409:             *         rethrown wrapped into a TorqueException.
410:             */
411:            public static void doDelete(Criteria criteria)
412:                    throws TorqueException {
413:                AttributeOptionPeer.doDelete(criteria, (Connection) null);
414:            }
415:
416:            /**
417:             * Method to do deletes.  This method is to be used during a transaction,
418:             * otherwise use the doDelete(Criteria) method.  It will take care of
419:             * the connection details internally.
420:             *
421:             * @param criteria object containing data that is used DELETE from database.
422:             * @param con the connection to use
423:             * @throws TorqueException Any exceptions caught during processing will be
424:             *         rethrown wrapped into a TorqueException.
425:             */
426:            public static void doDelete(Criteria criteria, Connection con)
427:                    throws TorqueException {
428:                correctBooleans(criteria);
429:
430:                setDbName(criteria);
431:
432:                if (con == null) {
433:                    BasePeer.doDelete(criteria);
434:                } else {
435:                    BasePeer.doDelete(criteria, con);
436:                }
437:            }
438:
439:            /**
440:             * Method to do selects
441:             *
442:             * @throws TorqueException Any exceptions caught during processing will be
443:             *         rethrown wrapped into a TorqueException.
444:             */
445:            public static List doSelect(AttributeOption obj)
446:                    throws TorqueException {
447:                return doSelect(buildSelectCriteria(obj));
448:            }
449:
450:            /**
451:             * Method to do inserts
452:             *
453:             * @throws TorqueException Any exceptions caught during processing will be
454:             *         rethrown wrapped into a TorqueException.
455:             */
456:            public static void doInsert(AttributeOption obj)
457:                    throws TorqueException {
458:                obj.setPrimaryKey(doInsert(buildCriteria(obj)));
459:                obj.setNew(false);
460:                obj.setModified(false);
461:            }
462:
463:            /**
464:             * @param obj the data object to update in the database.
465:             * @throws TorqueException Any exceptions caught during processing will be
466:             *         rethrown wrapped into a TorqueException.
467:             */
468:            public static void doUpdate(AttributeOption obj)
469:                    throws TorqueException {
470:                doUpdate(buildCriteria(obj));
471:                obj.setModified(false);
472:            }
473:
474:            /**
475:             * @param obj the data object to delete in the database.
476:             * @throws TorqueException Any exceptions caught during processing will be
477:             *         rethrown wrapped into a TorqueException.
478:             */
479:            public static void doDelete(AttributeOption obj)
480:                    throws TorqueException {
481:                doDelete(buildSelectCriteria(obj));
482:            }
483:
484:            /**
485:             * Method to do inserts.  This method is to be used during a transaction,
486:             * otherwise use the doInsert(AttributeOption) method.  It will take
487:             * care of the connection details internally.
488:             *
489:             * @param obj the data object to insert into the database.
490:             * @param con the connection to use
491:             * @throws TorqueException Any exceptions caught during processing will be
492:             *         rethrown wrapped into a TorqueException.
493:             */
494:            public static void doInsert(AttributeOption obj, Connection con)
495:                    throws TorqueException {
496:                obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
497:                obj.setNew(false);
498:                obj.setModified(false);
499:            }
500:
501:            /**
502:             * Method to do update.  This method is to be used during a transaction,
503:             * otherwise use the doUpdate(AttributeOption) method.  It will take
504:             * care of the connection details internally.
505:             *
506:             * @param obj the data object to update in the database.
507:             * @param con the connection to use
508:             * @throws TorqueException Any exceptions caught during processing will be
509:             *         rethrown wrapped into a TorqueException.
510:             */
511:            public static void doUpdate(AttributeOption obj, Connection con)
512:                    throws TorqueException {
513:                doUpdate(buildCriteria(obj), con);
514:                obj.setModified(false);
515:            }
516:
517:            /**
518:             * Method to delete.  This method is to be used during a transaction,
519:             * otherwise use the doDelete(AttributeOption) method.  It will take
520:             * care of the connection details internally.
521:             *
522:             * @param obj the data object to delete in the database.
523:             * @param con the connection to use
524:             * @throws TorqueException Any exceptions caught during processing will be
525:             *         rethrown wrapped into a TorqueException.
526:             */
527:            public static void doDelete(AttributeOption obj, Connection con)
528:                    throws TorqueException {
529:                doDelete(buildSelectCriteria(obj), con);
530:            }
531:
532:            /**
533:             * Method to do deletes.
534:             *
535:             * @param pk ObjectKey that is used DELETE from database.
536:             * @throws TorqueException Any exceptions caught during processing will be
537:             *         rethrown wrapped into a TorqueException.
538:             */
539:            public static void doDelete(ObjectKey pk) throws TorqueException {
540:                BaseAttributeOptionPeer.doDelete(pk, (Connection) null);
541:            }
542:
543:            /**
544:             * Method to delete.  This method is to be used during a transaction,
545:             * otherwise use the doDelete(ObjectKey) method.  It will take
546:             * care of the connection details internally.
547:             *
548:             * @param pk the primary key for the object to delete in the database.
549:             * @param con the connection to use
550:             * @throws TorqueException Any exceptions caught during processing will be
551:             *         rethrown wrapped into a TorqueException.
552:             */
553:            public static void doDelete(ObjectKey pk, Connection con)
554:                    throws TorqueException {
555:                doDelete(buildCriteria(pk), con);
556:            }
557:
558:            /** Build a Criteria object from an ObjectKey */
559:            public static Criteria buildCriteria(ObjectKey pk) {
560:                Criteria criteria = new Criteria();
561:                criteria.add(OPTION_ID, pk);
562:                return criteria;
563:            }
564:
565:            /** Build a Criteria object from the data object for this peer */
566:            public static Criteria buildCriteria(AttributeOption obj) {
567:                Criteria criteria = new Criteria(DATABASE_NAME);
568:                if (!obj.isNew())
569:                    criteria.add(OPTION_ID, obj.getOptionId());
570:                criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
571:                criteria.add(OPTION_NAME, obj.getName());
572:                criteria.add(DELETED, obj.getDeleted());
573:                return criteria;
574:            }
575:
576:            /** Build a Criteria object from the data object for this peer, skipping all binary columns */
577:            public static Criteria buildSelectCriteria(AttributeOption obj) {
578:                Criteria criteria = new Criteria(DATABASE_NAME);
579:                if (!obj.isNew()) {
580:                    criteria.add(OPTION_ID, obj.getOptionId());
581:                }
582:                criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
583:                criteria.add(OPTION_NAME, obj.getName());
584:                criteria.add(DELETED, obj.getDeleted());
585:                return criteria;
586:            }
587:
588:            /**
589:             * Retrieve a single object by pk
590:             *
591:             * @param pk the primary key
592:             * @throws TorqueException Any exceptions caught during processing will be
593:             *         rethrown wrapped into a TorqueException.
594:             * @throws NoRowsException Primary key was not found in database.
595:             * @throws TooManyRowsException Primary key was not found in database.
596:             */
597:            public static AttributeOption retrieveByPK(Integer pk)
598:                    throws TorqueException, NoRowsException,
599:                    TooManyRowsException {
600:                return retrieveByPK(SimpleKey.keyFor(pk));
601:            }
602:
603:            /**
604:             * Retrieve a single object by pk
605:             *
606:             * @param pk the primary key
607:             * @param con the connection to use
608:             * @throws TorqueException Any exceptions caught during processing will be
609:             *         rethrown wrapped into a TorqueException.
610:             * @throws NoRowsException Primary key was not found in database.
611:             * @throws TooManyRowsException Primary key was not found in database.
612:             */
613:            public static AttributeOption retrieveByPK(Integer pk,
614:                    Connection con) throws TorqueException, NoRowsException,
615:                    TooManyRowsException {
616:                return retrieveByPK(SimpleKey.keyFor(pk), con);
617:            }
618:
619:            /**
620:             * Retrieve a single object by pk
621:             *
622:             * @param pk the primary key
623:             * @throws TorqueException Any exceptions caught during processing will be
624:             *         rethrown wrapped into a TorqueException.
625:             * @throws NoRowsException Primary key was not found in database.
626:             * @throws TooManyRowsException Primary key was not found in database.
627:             */
628:            public static AttributeOption retrieveByPK(ObjectKey pk)
629:                    throws TorqueException, NoRowsException,
630:                    TooManyRowsException {
631:                Connection db = null;
632:                AttributeOption retVal = null;
633:                try {
634:                    db = Torque.getConnection(DATABASE_NAME);
635:                    retVal = retrieveByPK(pk, db);
636:                } finally {
637:                    Torque.closeConnection(db);
638:                }
639:                return retVal;
640:            }
641:
642:            /**
643:             * Retrieve a single object by pk
644:             *
645:             * @param pk the primary key
646:             * @param con the connection to use
647:             * @throws TorqueException Any exceptions caught during processing will be
648:             *         rethrown wrapped into a TorqueException.
649:             * @throws NoRowsException Primary key was not found in database.
650:             * @throws TooManyRowsException Primary key was not found in database.
651:             */
652:            public static AttributeOption retrieveByPK(ObjectKey pk,
653:                    Connection con) throws TorqueException, NoRowsException,
654:                    TooManyRowsException {
655:                Criteria criteria = buildCriteria(pk);
656:                List v = doSelect(criteria, con);
657:                if (v.size() == 0) {
658:                    throw new NoRowsException("Failed to select a row.");
659:                } else if (v.size() > 1) {
660:                    throw new TooManyRowsException(
661:                            "Failed to select only one row.");
662:                } else {
663:                    return (AttributeOption) v.get(0);
664:                }
665:            }
666:
667:            /**
668:             * Retrieve a multiple objects by pk
669:             *
670:             * @param pks List of primary keys
671:             * @throws TorqueException Any exceptions caught during processing will be
672:             *         rethrown wrapped into a TorqueException.
673:             */
674:            public static List retrieveByPKs(List pks) throws TorqueException {
675:                Connection db = null;
676:                List retVal = null;
677:                try {
678:                    db = Torque.getConnection(DATABASE_NAME);
679:                    retVal = retrieveByPKs(pks, db);
680:                } finally {
681:                    Torque.closeConnection(db);
682:                }
683:                return retVal;
684:            }
685:
686:            /**
687:             * Retrieve a multiple objects by pk
688:             *
689:             * @param pks List of primary keys
690:             * @param dbcon the connection to use
691:             * @throws TorqueException Any exceptions caught during processing will be
692:             *         rethrown wrapped into a TorqueException.
693:             */
694:            public static List retrieveByPKs(List pks, Connection dbcon)
695:                    throws TorqueException {
696:                List objs = null;
697:                if (pks == null || pks.size() == 0) {
698:                    objs = new LinkedList();
699:                } else {
700:                    Criteria criteria = new Criteria();
701:                    criteria.addIn(OPTION_ID, pks);
702:                    objs = doSelect(criteria, dbcon);
703:                }
704:                return objs;
705:            }
706:
707:            /**
708:             * selects a collection of AttributeOption objects pre-filled with their
709:             * Attribute objects.
710:             *
711:             * This method is protected by default in order to keep the public
712:             * api reasonable.  You can provide public methods for those you
713:             * actually need in AttributeOptionPeer.
714:             *
715:             * @throws TorqueException Any exceptions caught during processing will be
716:             *         rethrown wrapped into a TorqueException.
717:             */
718:            protected static List doSelectJoinAttribute(Criteria criteria)
719:                    throws TorqueException {
720:                return doSelectJoinAttribute(criteria, null);
721:            }
722:
723:            /**
724:             * selects a collection of AttributeOption objects pre-filled with their
725:             * Attribute objects.
726:             *
727:             * This method is protected by default in order to keep the public
728:             * api reasonable.  You can provide public methods for those you
729:             * actually need in AttributeOptionPeer.
730:             *
731:             * @throws TorqueException Any exceptions caught during processing will be
732:             *         rethrown wrapped into a TorqueException.
733:             */
734:            protected static List doSelectJoinAttribute(Criteria criteria,
735:                    Connection conn) throws TorqueException {
736:                setDbName(criteria);
737:
738:                AttributeOptionPeer.addSelectColumns(criteria);
739:                int offset = numColumns + 1;
740:                AttributePeer.addSelectColumns(criteria);
741:
742:                criteria.addJoin(AttributeOptionPeer.ATTRIBUTE_ID,
743:                        AttributePeer.ATTRIBUTE_ID);
744:
745:                correctBooleans(criteria);
746:
747:                List rows;
748:                if (conn == null) {
749:                    rows = BasePeer.doSelect(criteria);
750:                } else {
751:                    rows = BasePeer.doSelect(criteria, conn);
752:                }
753:
754:                List results = new ArrayList();
755:
756:                for (int i = 0; i < rows.size(); i++) {
757:                    Record row = (Record) rows.get(i);
758:
759:                    Class omClass = AttributeOptionPeer.getOMClass();
760:                    AttributeOption obj1 = (AttributeOption) AttributeOptionPeer
761:                            .row2Object(row, 1, omClass);
762:                    omClass = AttributePeer.getOMClass();
763:                    Attribute obj2 = (Attribute) AttributePeer.row2Object(row,
764:                            offset, omClass);
765:
766:                    boolean newObject = true;
767:                    for (int j = 0; j < results.size(); j++) {
768:                        AttributeOption temp_obj1 = (AttributeOption) results
769:                                .get(j);
770:                        Attribute temp_obj2 = (Attribute) temp_obj1
771:                                .getAttribute();
772:                        if (temp_obj2.getPrimaryKey().equals(
773:                                obj2.getPrimaryKey())) {
774:                            newObject = false;
775:                            temp_obj2.addAttributeOption(obj1);
776:                            break;
777:                        }
778:                    }
779:                    if (newObject) {
780:                        obj2.initAttributeOptions();
781:                        obj2.addAttributeOption(obj1);
782:                    }
783:                    results.add(obj1);
784:                }
785:                return results;
786:            }
787:
788:            /**
789:             * Returns the TableMap related to this peer.  This method is not
790:             * needed for general use but a specific application could have a need.
791:             *
792:             * @throws TorqueException Any exceptions caught during processing will be
793:             *         rethrown wrapped into a TorqueException.
794:             */
795:            protected static TableMap getTableMap() throws TorqueException {
796:                return Torque.getDatabaseMap(DATABASE_NAME)
797:                        .getTable(TABLE_NAME);
798:            }
799:
800:            private static void setDbName(Criteria crit) {
801:                // Set the correct dbName if it has not been overridden
802:                // crit.getDbName will return the same object if not set to
803:                // another value so == check is okay and faster
804:                if (crit.getDbName() == Torque.getDefaultDB()) {
805:                    crit.setDbName(DATABASE_NAME);
806:                }
807:            }
808:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.