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