KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseAttributeGroupPeer


1 package org.tigris.scarab.om;
2
3 import java.math.BigDecimal JavaDoc;
4 import java.sql.Connection JavaDoc;
5 import java.sql.SQLException JavaDoc;
6 import java.util.ArrayList JavaDoc;
7 import java.util.Date JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.LinkedList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.apache.torque.NoRowsException;
13 import org.apache.torque.TooManyRowsException;
14 import org.apache.torque.Torque;
15 import org.apache.torque.TorqueException;
16 import org.apache.torque.map.MapBuilder;
17 import org.apache.torque.map.TableMap;
18 import org.apache.torque.om.DateKey;
19 import org.apache.torque.om.NumberKey;
20 import org.apache.torque.om.StringKey;
21 import org.apache.torque.om.ObjectKey;
22 import org.apache.torque.om.SimpleKey;
23 import org.apache.torque.util.BasePeer;
24 import org.apache.torque.util.Criteria;
25
26 import com.workingdogs.village.DataSetException;
27 import com.workingdogs.village.QueryDataSet;
28 import com.workingdogs.village.Record;
29
30 // Local classes
31
import org.tigris.scarab.om.map.*;
32
33
34   
35   
36 /**
37  */

38 public abstract class BaseAttributeGroupPeer
39     extends BasePeer
40 {
41
42     /** the default database name for this class */
43     public static final String JavaDoc DATABASE_NAME = "scarab";
44
45      /** the table name for this class */
46     public static final String JavaDoc TABLE_NAME = "SCARAB_ATTRIBUTE_GROUP";
47
48     /**
49      * @return the map builder for this peer
50      * @throws TorqueException Any exceptions caught during processing will be
51      * rethrown wrapped into a TorqueException.
52      */

53     public static MapBuilder getMapBuilder()
54         throws TorqueException
55     {
56         return getMapBuilder(AttributeGroupMapBuilder.CLASS_NAME);
57     }
58
59       /** the column name for the ATTRIBUTE_GROUP_ID field */
60     public static final String JavaDoc ATTRIBUTE_GROUP_ID;
61       /** the column name for the NAME field */
62     public static final String JavaDoc NAME;
63       /** the column name for the DESCRIPTION field */
64     public static final String JavaDoc DESCRIPTION;
65       /** the column name for the MODULE_ID field */
66     public static final String JavaDoc MODULE_ID;
67       /** the column name for the ISSUE_TYPE_ID field */
68     public static final String JavaDoc ISSUE_TYPE_ID;
69       /** the column name for the ACTIVE field */
70     public static final String JavaDoc ACTIVE;
71       /** the column name for the DEDUPE field */
72     public static final String JavaDoc DEDUPE;
73       /** the column name for the PREFERRED_ORDER field */
74     public static final String JavaDoc PREFERRED_ORDER;
75   
76     static
77     {
78           ATTRIBUTE_GROUP_ID = "SCARAB_ATTRIBUTE_GROUP.ATTRIBUTE_GROUP_ID";
79           NAME = "SCARAB_ATTRIBUTE_GROUP.NAME";
80           DESCRIPTION = "SCARAB_ATTRIBUTE_GROUP.DESCRIPTION";
81           MODULE_ID = "SCARAB_ATTRIBUTE_GROUP.MODULE_ID";
82           ISSUE_TYPE_ID = "SCARAB_ATTRIBUTE_GROUP.ISSUE_TYPE_ID";
83           ACTIVE = "SCARAB_ATTRIBUTE_GROUP.ACTIVE";
84           DEDUPE = "SCARAB_ATTRIBUTE_GROUP.DEDUPE";
85           PREFERRED_ORDER = "SCARAB_ATTRIBUTE_GROUP.PREFERRED_ORDER";
86           if (Torque.isInit())
87         {
88             try
89             {
90                 getMapBuilder(AttributeGroupMapBuilder.CLASS_NAME);
91             }
92             catch (Exception JavaDoc e)
93             {
94                 log.error("Could not initialize Peer", e);
95             }
96         }
97         else
98         {
99             Torque.registerMapBuilder(AttributeGroupMapBuilder.CLASS_NAME);
100         }
101     }
102  
103     /** number of columns for this peer */
104     public static final int numColumns = 8;
105
106     /** A class that can be returned by this peer. */
107     protected static final String JavaDoc CLASSNAME_DEFAULT =
108         "org.tigris.scarab.om.AttributeGroup";
109
110     /** A class that can be returned by this peer. */
111     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
112
113     /**
114      * Class object initialization method.
115      *
116      * @param className name of the class to initialize
117      * @return the initialized class
118      */

119     private static Class JavaDoc initClass(String JavaDoc className)
120     {
121         Class JavaDoc c = null;
122         try
123         {
124             c = Class.forName(className);
125         }
126         catch (Throwable JavaDoc t)
127         {
128             log.error("A FATAL ERROR has occurred which should not "
129                 + "have happened under any circumstance. Please notify "
130                 + "the Torque developers <torque-dev@db.apache.org> "
131                 + "and give as many details as possible (including the error "
132                 + "stack trace).", t);
133
134             // Error objects should always be propogated.
135
if (t instanceof Error JavaDoc)
136             {
137                 throw (Error JavaDoc) t.fillInStackTrace();
138             }
139         }
140         return c;
141     }
142
143     /**
144      * Get the list of objects for a ResultSet. Please not that your
145      * resultset MUST return columns in the right order. You can use
146      * getFieldNames() in BaseObject to get the correct sequence.
147      *
148      * @param results the ResultSet
149      * @return the list of objects
150      * @throws TorqueException Any exceptions caught during processing will be
151      * rethrown wrapped into a TorqueException.
152      */

153     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
154             throws TorqueException
155     {
156         try
157         {
158             QueryDataSet qds = null;
159             List JavaDoc rows = null;
160             try
161             {
162                 qds = new QueryDataSet(results);
163                 rows = getSelectResults(qds);
164             }
165             finally
166             {
167                 if (qds != null)
168                 {
169                     qds.close();
170                 }
171             }
172
173             return populateObjects(rows);
174         }
175         catch (SQLException JavaDoc e)
176         {
177             throw new TorqueException(e);
178         }
179         catch (DataSetException e)
180         {
181             throw new TorqueException(e);
182         }
183     }
184
185
186   
187     /**
188      * Method to do inserts.
189      *
190      * @param criteria object used to create the INSERT statement.
191      * @throws TorqueException Any exceptions caught during processing will be
192      * rethrown wrapped into a TorqueException.
193      */

194     public static ObjectKey doInsert(Criteria criteria)
195         throws TorqueException
196     {
197         return BaseAttributeGroupPeer
198             .doInsert(criteria, (Connection JavaDoc) null);
199     }
200
201     /**
202      * Method to do inserts. This method is to be used during a transaction,
203      * otherwise use the doInsert(Criteria) method. It will take care of
204      * the connection details internally.
205      *
206      * @param criteria object used to create the INSERT statement.
207      * @param con the connection to use
208      * @throws TorqueException Any exceptions caught during processing will be
209      * rethrown wrapped into a TorqueException.
210      */

211     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
212         throws TorqueException
213     {
214                                             // check for conversion from boolean to int
215
if (criteria.containsKey(ACTIVE))
216         {
217             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
218             if (possibleBoolean instanceof Boolean JavaDoc)
219             {
220                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
221             }
222          }
223                   // check for conversion from boolean to int
224
if (criteria.containsKey(DEDUPE))
225         {
226             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
227             if (possibleBoolean instanceof Boolean JavaDoc)
228             {
229                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
230             }
231          }
232             
233         setDbName(criteria);
234
235         if (con == null)
236         {
237             return BasePeer.doInsert(criteria);
238         }
239         else
240         {
241             return BasePeer.doInsert(criteria, con);
242         }
243     }
244
245     /**
246      * Add all the columns needed to create a new object.
247      *
248      * @param criteria object containing the columns to add.
249      * @throws TorqueException Any exceptions caught during processing will be
250      * rethrown wrapped into a TorqueException.
251      */

252     public static void addSelectColumns(Criteria criteria)
253             throws TorqueException
254     {
255           criteria.addSelectColumn(ATTRIBUTE_GROUP_ID);
256           criteria.addSelectColumn(NAME);
257           criteria.addSelectColumn(DESCRIPTION);
258           criteria.addSelectColumn(MODULE_ID);
259           criteria.addSelectColumn(ISSUE_TYPE_ID);
260           criteria.addSelectColumn(ACTIVE);
261           criteria.addSelectColumn(DEDUPE);
262           criteria.addSelectColumn(PREFERRED_ORDER);
263       }
264
265     /**
266      * Create a new object of type cls from a resultset row starting
267      * from a specified offset. This is done so that you can select
268      * other rows than just those needed for this object. You may
269      * for example want to create two objects from the same row.
270      *
271      * @throws TorqueException Any exceptions caught during processing will be
272      * rethrown wrapped into a TorqueException.
273      */

274     public static AttributeGroup row2Object(Record row,
275                                              int offset,
276                                              Class JavaDoc cls)
277         throws TorqueException
278     {
279         try
280         {
281             AttributeGroup obj = (AttributeGroup) cls.newInstance();
282             AttributeGroupPeer.populateObject(row, offset, obj);
283                   obj.setModified(false);
284               obj.setNew(false);
285
286             return obj;
287         }
288         catch (InstantiationException JavaDoc e)
289         {
290             throw new TorqueException(e);
291         }
292         catch (IllegalAccessException JavaDoc e)
293         {
294             throw new TorqueException(e);
295         }
296     }
297
298     /**
299      * Populates an object from a resultset row starting
300      * from a specified offset. This is done so that you can select
301      * other rows than just those needed for this object. You may
302      * for example want to create two objects from the same row.
303      *
304      * @throws TorqueException Any exceptions caught during processing will be
305      * rethrown wrapped into a TorqueException.
306      */

307     public static void populateObject(Record row,
308                                       int offset,
309                                       AttributeGroup obj)
310         throws TorqueException
311     {
312         try
313         {
314                 obj.setAttributeGroupId(row.getValue(offset + 0).asIntegerObj());
315                   obj.setName(row.getValue(offset + 1).asString());
316                   obj.setDescription(row.getValue(offset + 2).asString());
317                   obj.setModuleId(row.getValue(offset + 3).asIntegerObj());
318                   obj.setIssueTypeId(row.getValue(offset + 4).asIntegerObj());
319                   obj.setActive(row.getValue(offset + 5).asBoolean());
320                   obj.setDedupe(row.getValue(offset + 6).asBoolean());
321                   obj.setOrder(row.getValue(offset + 7).asInt());
322               }
323         catch (DataSetException e)
324         {
325             throw new TorqueException(e);
326         }
327     }
328
329     /**
330      * Method to do selects.
331      *
332      * @param criteria object used to create the SELECT statement.
333      * @return List of selected Objects
334      * @throws TorqueException Any exceptions caught during processing will be
335      * rethrown wrapped into a TorqueException.
336      */

337     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
338     {
339         return populateObjects(doSelectVillageRecords(criteria));
340     }
341
342     /**
343      * Method to do selects within a transaction.
344      *
345      * @param criteria object used to create the SELECT statement.
346      * @param con the connection to use
347      * @return List of selected Objects
348      * @throws TorqueException Any exceptions caught during processing will be
349      * rethrown wrapped into a TorqueException.
350      */

351     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
352         throws TorqueException
353     {
354         return populateObjects(doSelectVillageRecords(criteria, con));
355     }
356
357     /**
358      * Grabs the raw Village records to be formed into objects.
359      * This method handles connections internally. The Record objects
360      * returned by this method should be considered readonly. Do not
361      * alter the data and call save(), your results may vary, but are
362      * certainly likely to result in hard to track MT bugs.
363      *
364      * @throws TorqueException Any exceptions caught during processing will be
365      * rethrown wrapped into a TorqueException.
366      */

367     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
368         throws TorqueException
369     {
370         return BaseAttributeGroupPeer
371             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
372     }
373
374     /**
375      * Grabs the raw Village records to be formed into objects.
376      * This method should be used for transactions
377      *
378      * @param criteria object used to create the SELECT statement.
379      * @param con the connection to use
380      * @throws TorqueException Any exceptions caught during processing will be
381      * rethrown wrapped into a TorqueException.
382      */

383     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
384         throws TorqueException
385     {
386         if (criteria.getSelectColumns().size() == 0)
387         {
388             addSelectColumns(criteria);
389         }
390
391                                             // check for conversion from boolean to int
392
if (criteria.containsKey(ACTIVE))
393         {
394             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
395             if (possibleBoolean instanceof Boolean JavaDoc)
396             {
397                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
398             }
399          }
400                   // check for conversion from boolean to int
401
if (criteria.containsKey(DEDUPE))
402         {
403             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
404             if (possibleBoolean instanceof Boolean JavaDoc)
405             {
406                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
407             }
408          }
409             
410         setDbName(criteria);
411
412         // BasePeer returns a List of Value (Village) arrays. The array
413
// order follows the order columns were placed in the Select clause.
414
if (con == null)
415         {
416             return BasePeer.doSelect(criteria);
417         }
418         else
419         {
420             return BasePeer.doSelect(criteria, con);
421         }
422     }
423
424     /**
425      * The returned List will contain objects of the default type or
426      * objects that inherit from the default.
427      *
428      * @throws TorqueException Any exceptions caught during processing will be
429      * rethrown wrapped into a TorqueException.
430      */

431     public static List JavaDoc populateObjects(List JavaDoc records)
432         throws TorqueException
433     {
434         List JavaDoc results = new ArrayList JavaDoc(records.size());
435
436         // populate the object(s)
437
for (int i = 0; i < records.size(); i++)
438         {
439             Record row = (Record) records.get(i);
440               results.add(AttributeGroupPeer.row2Object(row, 1,
441                 AttributeGroupPeer.getOMClass()));
442           }
443         return results;
444     }
445  
446
447     /**
448      * The class that the Peer will make instances of.
449      * If the BO is abstract then you must implement this method
450      * in the BO.
451      *
452      * @throws TorqueException Any exceptions caught during processing will be
453      * rethrown wrapped into a TorqueException.
454      */

455     public static Class JavaDoc getOMClass()
456         throws TorqueException
457     {
458         return CLASS_DEFAULT;
459     }
460
461     /**
462      * Method to do updates.
463      *
464      * @param criteria object containing data that is used to create the UPDATE
465      * statement.
466      * @throws TorqueException Any exceptions caught during processing will be
467      * rethrown wrapped into a TorqueException.
468      */

469     public static void doUpdate(Criteria criteria) throws TorqueException
470     {
471          BaseAttributeGroupPeer
472             .doUpdate(criteria, (Connection JavaDoc) null);
473     }
474
475     /**
476      * Method to do updates. This method is to be used during a transaction,
477      * otherwise use the doUpdate(Criteria) method. It will take care of
478      * the connection details internally.
479      *
480      * @param criteria object containing data that is used to create the UPDATE
481      * statement.
482      * @param con the connection to use
483      * @throws TorqueException Any exceptions caught during processing will be
484      * rethrown wrapped into a TorqueException.
485      */

486     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
487         throws TorqueException
488     {
489         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
490                    selectCriteria.put(ATTRIBUTE_GROUP_ID, criteria.remove(ATTRIBUTE_GROUP_ID));
491                                                           // check for conversion from boolean to int
492
if (criteria.containsKey(ACTIVE))
493         {
494             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
495             if (possibleBoolean instanceof Boolean JavaDoc)
496             {
497                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
498             }
499          }
500                       // check for conversion from boolean to int
501
if (criteria.containsKey(DEDUPE))
502         {
503             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
504             if (possibleBoolean instanceof Boolean JavaDoc)
505             {
506                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
507             }
508          }
509                     
510         setDbName(criteria);
511
512         if (con == null)
513         {
514             BasePeer.doUpdate(selectCriteria, criteria);
515         }
516         else
517         {
518             BasePeer.doUpdate(selectCriteria, criteria, con);
519         }
520     }
521
522     /**
523      * Method to do deletes.
524      *
525      * @param criteria object containing data that is used DELETE from database.
526      * @throws TorqueException Any exceptions caught during processing will be
527      * rethrown wrapped into a TorqueException.
528      */

529      public static void doDelete(Criteria criteria) throws TorqueException
530      {
531          AttributeGroupPeer
532             .doDelete(criteria, (Connection JavaDoc) null);
533      }
534
535     /**
536      * Method to do deletes. This method is to be used during a transaction,
537      * otherwise use the doDelete(Criteria) method. It will take care of
538      * the connection details internally.
539      *
540      * @param criteria object containing data that is used DELETE from database.
541      * @param con the connection to use
542      * @throws TorqueException Any exceptions caught during processing will be
543      * rethrown wrapped into a TorqueException.
544      */

545      public static void doDelete(Criteria criteria, Connection JavaDoc con)
546         throws TorqueException
547      {
548                                             // check for conversion from boolean to int
549
if (criteria.containsKey(ACTIVE))
550         {
551             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
552             if (possibleBoolean instanceof Boolean JavaDoc)
553             {
554                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
555             }
556          }
557                   // check for conversion from boolean to int
558
if (criteria.containsKey(DEDUPE))
559         {
560             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
561             if (possibleBoolean instanceof Boolean JavaDoc)
562             {
563                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
564             }
565          }
566             
567         setDbName(criteria);
568
569         if (con == null)
570         {
571             BasePeer.doDelete(criteria);
572         }
573         else
574         {
575             BasePeer.doDelete(criteria, con);
576         }
577      }
578
579     /**
580      * Method to do selects
581      *
582      * @throws TorqueException Any exceptions caught during processing will be
583      * rethrown wrapped into a TorqueException.
584      */

585     public static List JavaDoc doSelect(AttributeGroup obj) throws TorqueException
586     {
587         return doSelect(buildSelectCriteria(obj));
588     }
589
590     /**
591      * Method to do inserts
592      *
593      * @throws TorqueException Any exceptions caught during processing will be
594      * rethrown wrapped into a TorqueException.
595      */

596     public static void doInsert(AttributeGroup obj) throws TorqueException
597     {
598           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
599           obj.setNew(false);
600         obj.setModified(false);
601     }
602
603     /**
604      * @param obj the data object to update in the database.
605      * @throws TorqueException Any exceptions caught during processing will be
606      * rethrown wrapped into a TorqueException.
607      */

608     public static void doUpdate(AttributeGroup obj) throws TorqueException
609     {
610         doUpdate(buildCriteria(obj));
611         obj.setModified(false);
612     }
613
614     /**
615      * @param obj the data object to delete in the database.
616      * @throws TorqueException Any exceptions caught during processing will be
617      * rethrown wrapped into a TorqueException.
618      */

619     public static void doDelete(AttributeGroup obj) throws TorqueException
620     {
621         doDelete(buildSelectCriteria(obj));
622     }
623
624     /**
625      * Method to do inserts. This method is to be used during a transaction,
626      * otherwise use the doInsert(AttributeGroup) method. It will take
627      * care of the connection details internally.
628      *
629      * @param obj the data object to insert into the database.
630      * @param con the connection to use
631      * @throws TorqueException Any exceptions caught during processing will be
632      * rethrown wrapped into a TorqueException.
633      */

634     public static void doInsert(AttributeGroup obj, Connection JavaDoc con)
635         throws TorqueException
636     {
637           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
638           obj.setNew(false);
639         obj.setModified(false);
640     }
641
642     /**
643      * Method to do update. This method is to be used during a transaction,
644      * otherwise use the doUpdate(AttributeGroup) method. It will take
645      * care of the connection details internally.
646      *
647      * @param obj the data object to update in the database.
648      * @param con the connection to use
649      * @throws TorqueException Any exceptions caught during processing will be
650      * rethrown wrapped into a TorqueException.
651      */

652     public static void doUpdate(AttributeGroup obj, Connection JavaDoc con)
653         throws TorqueException
654     {
655         doUpdate(buildCriteria(obj), con);
656         obj.setModified(false);
657     }
658
659     /**
660      * Method to delete. This method is to be used during a transaction,
661      * otherwise use the doDelete(AttributeGroup) method. It will take
662      * care of the connection details internally.
663      *
664      * @param obj the data object to delete in the database.
665      * @param con the connection to use
666      * @throws TorqueException Any exceptions caught during processing will be
667      * rethrown wrapped into a TorqueException.
668      */

669     public static void doDelete(AttributeGroup obj, Connection JavaDoc con)
670         throws TorqueException
671     {
672         doDelete(buildSelectCriteria(obj), con);
673     }
674
675     /**
676      * Method to do deletes.
677      *
678      * @param pk ObjectKey that is used DELETE from database.
679      * @throws TorqueException Any exceptions caught during processing will be
680      * rethrown wrapped into a TorqueException.
681      */

682     public static void doDelete(ObjectKey pk) throws TorqueException
683     {
684         BaseAttributeGroupPeer
685            .doDelete(pk, (Connection JavaDoc) null);
686     }
687
688     /**
689      * Method to delete. This method is to be used during a transaction,
690      * otherwise use the doDelete(ObjectKey) method. It will take
691      * care of the connection details internally.
692      *
693      * @param pk the primary key for the object to delete in the database.
694      * @param con the connection to use
695      * @throws TorqueException Any exceptions caught during processing will be
696      * rethrown wrapped into a TorqueException.
697      */

698     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
699         throws TorqueException
700     {
701         doDelete(buildCriteria(pk), con);
702     }
703
704     /** Build a Criteria object from an ObjectKey */
705     public static Criteria buildCriteria( ObjectKey pk )
706     {
707         Criteria criteria = new Criteria();
708               criteria.add(ATTRIBUTE_GROUP_ID, pk);
709           return criteria;
710      }
711
712     /** Build a Criteria object from the data object for this peer */
713     public static Criteria buildCriteria( AttributeGroup obj )
714     {
715         Criteria criteria = new Criteria(DATABASE_NAME);
716               if (!obj.isNew())
717             criteria.add(ATTRIBUTE_GROUP_ID, obj.getAttributeGroupId());
718               criteria.add(NAME, obj.getName());
719               criteria.add(DESCRIPTION, obj.getDescription());
720               criteria.add(MODULE_ID, obj.getModuleId());
721               criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
722               criteria.add(ACTIVE, obj.getActive());
723               criteria.add(DEDUPE, obj.getDedupe());
724               criteria.add(PREFERRED_ORDER, obj.getOrder());
725           return criteria;
726     }
727
728     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
729     public static Criteria buildSelectCriteria( AttributeGroup obj )
730     {
731         Criteria criteria = new Criteria(DATABASE_NAME);
732               if (!obj.isNew())
733                     criteria.add(ATTRIBUTE_GROUP_ID, obj.getAttributeGroupId());
734                           criteria.add(NAME, obj.getName());
735                           criteria.add(DESCRIPTION, obj.getDescription());
736                           criteria.add(MODULE_ID, obj.getModuleId());
737                           criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
738                           criteria.add(ACTIVE, obj.getActive());
739                           criteria.add(DEDUPE, obj.getDedupe());
740                           criteria.add(PREFERRED_ORDER, obj.getOrder());
741               return criteria;
742     }
743  
744     
745         /**
746      * Retrieve a single object by pk
747      *
748      * @param pk the primary key
749      * @throws TorqueException Any exceptions caught during processing will be
750      * rethrown wrapped into a TorqueException.
751      * @throws NoRowsException Primary key was not found in database.
752      * @throws TooManyRowsException Primary key was not found in database.
753      */

754     public static AttributeGroup retrieveByPK(Integer JavaDoc pk)
755         throws TorqueException, NoRowsException, TooManyRowsException
756     {
757         return retrieveByPK(SimpleKey.keyFor(pk));
758     }
759
760     /**
761      * Retrieve a single object by pk
762      *
763      * @param pk the primary key
764      * @param con the connection to use
765      * @throws TorqueException Any exceptions caught during processing will be
766      * rethrown wrapped into a TorqueException.
767      * @throws NoRowsException Primary key was not found in database.
768      * @throws TooManyRowsException Primary key was not found in database.
769      */

770     public static AttributeGroup retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
771         throws TorqueException, NoRowsException, TooManyRowsException
772     {
773         return retrieveByPK(SimpleKey.keyFor(pk), con);
774     }
775   
776     /**
777      * Retrieve a single object by pk
778      *
779      * @param pk the primary key
780      * @throws TorqueException Any exceptions caught during processing will be
781      * rethrown wrapped into a TorqueException.
782      * @throws NoRowsException Primary key was not found in database.
783      * @throws TooManyRowsException Primary key was not found in database.
784      */

785     public static AttributeGroup retrieveByPK(ObjectKey pk)
786         throws TorqueException, NoRowsException, TooManyRowsException
787     {
788         Connection JavaDoc db = null;
789         AttributeGroup retVal = null;
790         try
791         {
792             db = Torque.getConnection(DATABASE_NAME);
793             retVal = retrieveByPK(pk, db);
794         }
795         finally
796         {
797             Torque.closeConnection(db);
798         }
799         return(retVal);
800     }
801
802     /**
803      * Retrieve a single object by pk
804      *
805      * @param pk the primary key
806      * @param con the connection to use
807      * @throws TorqueException Any exceptions caught during processing will be
808      * rethrown wrapped into a TorqueException.
809      * @throws NoRowsException Primary key was not found in database.
810      * @throws TooManyRowsException Primary key was not found in database.
811      */

812     public static AttributeGroup retrieveByPK(ObjectKey pk, Connection JavaDoc con)
813         throws TorqueException, NoRowsException, TooManyRowsException
814     {
815         Criteria criteria = buildCriteria(pk);
816         List JavaDoc v = doSelect(criteria, con);
817         if (v.size() == 0)
818         {
819             throw new NoRowsException("Failed to select a row.");
820         }
821         else if (v.size() > 1)
822         {
823             throw new TooManyRowsException("Failed to select only one row.");
824         }
825         else
826         {
827             return (AttributeGroup)v.get(0);
828         }
829     }
830
831     /**
832      * Retrieve a multiple objects by pk
833      *
834      * @param pks List of primary keys
835      * @throws TorqueException Any exceptions caught during processing will be
836      * rethrown wrapped into a TorqueException.
837      */

838     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
839         throws TorqueException
840     {
841         Connection JavaDoc db = null;
842         List JavaDoc retVal = null;
843         try
844         {
845            db = Torque.getConnection(DATABASE_NAME);
846            retVal = retrieveByPKs(pks, db);
847         }
848         finally
849         {
850             Torque.closeConnection(db);
851         }
852         return(retVal);
853     }
854
855     /**
856      * Retrieve a multiple objects by pk
857      *
858      * @param pks List of primary keys
859      * @param dbcon the connection to use
860      * @throws TorqueException Any exceptions caught during processing will be
861      * rethrown wrapped into a TorqueException.
862      */

863     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
864         throws TorqueException
865     {
866         List JavaDoc objs = null;
867         if (pks == null || pks.size() == 0)
868         {
869             objs = new LinkedList JavaDoc();
870         }
871         else
872         {
873             Criteria criteria = new Criteria();
874               criteria.addIn( ATTRIBUTE_GROUP_ID, pks );
875           objs = doSelect(criteria, dbcon);
876         }
877         return objs;
878     }
879
880  
881
882
883
884             
885                                               
886                         
887                 
888
889     /**
890      * selects a collection of AttributeGroup objects pre-filled with their
891      * ScarabModule objects.
892      *
893      * This method is protected by default in order to keep the public
894      * api reasonable. You can provide public methods for those you
895      * actually need in AttributeGroupPeer.
896      *
897      * @throws TorqueException Any exceptions caught during processing will be
898      * rethrown wrapped into a TorqueException.
899      */

900     protected static List JavaDoc doSelectJoinScarabModule(Criteria criteria)
901         throws TorqueException
902     {
903         setDbName(criteria);
904
905         AttributeGroupPeer.addSelectColumns(criteria);
906         int offset = numColumns + 1;
907         ScarabModulePeer.addSelectColumns(criteria);
908
909
910                         criteria.addJoin(AttributeGroupPeer.MODULE_ID,
911             ScarabModulePeer.MODULE_ID);
912         
913
914                                                                                                                     // check for conversion from boolean to int
915
if (criteria.containsKey(ACTIVE))
916         {
917             Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
918             if (possibleBoolean instanceof Boolean JavaDoc)
919             {
920                 criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
921             }
922          }
923                                     // check for conversion from boolean to int
924
if (criteria.containsKey(DEDUPE))
925         {
926             Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
927             if (possibleBoolean instanceof Boolean JavaDoc)
928             {
929                 criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
930             }
931          }
932                                     
933         List JavaDoc rows = BasePeer.doSelect(criteria);
934         List JavaDoc results = new ArrayList JavaDoc();
935
936         for (int i = 0; i < rows.size(); i++)
937         {
938             Record row = (Record) rows.get(i);
939
940                             Class JavaDoc omClass = AttributeGroupPeer.getOMClass();
941                     AttributeGroup obj1 = (AttributeGroup) AttributeGroupPeer
942                 .row2Object(row, 1, omClass);
943                      omClass = ScarabModulePeer.getOMClass(row, offset);
944                     ScarabModule obj2 = (ScarabModule)ScarabModulePeer
945                 .row2Object(row, offset, omClass);
946
947             boolean newObject = true;
948             for (int j = 0; j < results.size(); j++)
949             {
950                 AttributeGroup temp_obj1 = (AttributeGroup)results.get(j);
951                 ScarabModule temp_obj2 = (ScarabModule)temp_obj1.getModule();
952                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
953                 {
954                     newObject = false;
955                               temp_obj2.addAttributeGroup(obj1);
956                               break;
957                 }
958             }
959                       if (newObject)
960             {
961                 obj2.initAttributeGroups();
962                 obj2.addAttributeGroup(obj1);
963             }
964                       results.add(obj1);
965         }
966         return results;
967     }
968                                                             
969                 
970                 
971
972     /**
973      * selects a collection of AttributeGroup objects pre-filled with their
974      * IssueType objects.
975      *
976      * This method is protected by default in order to keep the public
977      * api reasonable. You can provide public methods for those you
978      * actually need in AttributeGroupPeer.
979      *
980      * @throws TorqueException Any exceptions caught during processing will be
981      * rethrown wrapped into a TorqueException.
982      */

983     protected static List JavaDoc doSelectJoinIssueType(Criteria criteria)
984         throws TorqueException
985     {
986         setDbName(criteria);
987
988         AttributeGroupPeer.addSelectColumns(criteria);
989         int offset = numColumns + 1;
990         IssueTypePeer.addSelectColumns(criteria);
991
992
993                         criteria.addJoin(AttributeGroupPeer.ISSUE_TYPE_ID,
994             IssueTypePeer.ISSUE_TYPE_ID);
995         
996
997                                                                                                                     // check for conversion from boolean to int
998
if (criteria.containsKey(ACTIVE))
999         {
1000            Object JavaDoc possibleBoolean = criteria.get(ACTIVE);
1001            if (possibleBoolean instanceof Boolean JavaDoc)
1002            {
1003                criteria.add(ACTIVE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1004            }
1005         }
1006                                    // check for conversion from boolean to int
1007
if (criteria.containsKey(DEDUPE))
1008        {
1009            Object JavaDoc possibleBoolean = criteria.get(DEDUPE);
1010            if (possibleBoolean instanceof Boolean JavaDoc)
1011            {
1012                criteria.add(DEDUPE, ((Boolean JavaDoc) possibleBoolean).booleanValue() ? 1 : 0);
1013            }
1014         }
1015                                    
1016        List JavaDoc rows = BasePeer.doSelect(criteria);
1017        List JavaDoc results = new ArrayList JavaDoc();
1018
1019        for (int i = 0; i < rows.size(); i++)
1020        {
1021            Record row = (Record) rows.get(i);
1022
1023                            Class JavaDoc omClass = AttributeGroupPeer.getOMClass();
1024                    AttributeGroup obj1 = (AttributeGroup) AttributeGroupPeer
1025                .row2Object(row, 1, omClass);
1026                     omClass = IssueTypePeer.getOMClass();
1027                    IssueType obj2 = (IssueType)IssueTypePeer
1028                .row2Object(row, offset, omClass);
1029
1030            boolean newObject = true;
1031            for (int j = 0; j < results.size(); j++)
1032            {
1033                AttributeGroup temp_obj1 = (AttributeGroup)results.get(j);
1034                IssueType temp_obj2 = (IssueType)temp_obj1.getIssueType();
1035                if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
1036                {
1037                    newObject = false;
1038                              temp_obj2.addAttributeGroup(obj1);
1039                              break;
1040                }
1041            }
1042                      if (newObject)
1043            {
1044                obj2.initAttributeGroups();
1045                obj2.addAttributeGroup(obj1);
1046            }
1047                      results.add(obj1);
1048        }
1049        return results;
1050    }
1051                    
1052  
1053    
1054  
1055      /**
1056     * Returns the TableMap related to this peer. This method is not
1057     * needed for general use but a specific application could have a need.
1058     *
1059     * @throws TorqueException Any exceptions caught during processing will be
1060     * rethrown wrapped into a TorqueException.
1061     */

1062    protected static TableMap getTableMap()
1063        throws TorqueException
1064    {
1065        return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1066    }
1067   
1068    private static void setDbName(Criteria crit)
1069    {
1070        // Set the correct dbName if it has not been overridden
1071
// crit.getDbName will return the same object if not set to
1072
// another value so == check is okay and faster
1073
if (crit.getDbName() == Torque.getDefaultDB())
1074        {
1075            crit.setDbName(DATABASE_NAME);
1076        }
1077    }
1078}
1079
Popular Tags