KickJava   Java API By Example, From Geeks To Geeks.

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


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 BaseRAttributeAttributeGroupPeer
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_R_ATTRIBUTE_ATTRGROUP";
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(RAttributeAttributeGroupMapBuilder.CLASS_NAME);
57     }
58
59       /** the column name for the GROUP_ID field */
60     public static final String JavaDoc GROUP_ID;
61       /** the column name for the ATTRIBUTE_ID field */
62     public static final String JavaDoc ATTRIBUTE_ID;
63       /** the column name for the PREFERRED_ORDER field */
64     public static final String JavaDoc PREFERRED_ORDER;
65   
66     static
67     {
68           GROUP_ID = "SCARAB_R_ATTRIBUTE_ATTRGROUP.GROUP_ID";
69           ATTRIBUTE_ID = "SCARAB_R_ATTRIBUTE_ATTRGROUP.ATTRIBUTE_ID";
70           PREFERRED_ORDER = "SCARAB_R_ATTRIBUTE_ATTRGROUP.PREFERRED_ORDER";
71           if (Torque.isInit())
72         {
73             try
74             {
75                 getMapBuilder(RAttributeAttributeGroupMapBuilder.CLASS_NAME);
76             }
77             catch (Exception JavaDoc e)
78             {
79                 log.error("Could not initialize Peer", e);
80             }
81         }
82         else
83         {
84             Torque.registerMapBuilder(RAttributeAttributeGroupMapBuilder.CLASS_NAME);
85         }
86     }
87  
88     /** number of columns for this peer */
89     public static final int numColumns = 3;
90
91     /** A class that can be returned by this peer. */
92     protected static final String JavaDoc CLASSNAME_DEFAULT =
93         "org.tigris.scarab.om.RAttributeAttributeGroup";
94
95     /** A class that can be returned by this peer. */
96     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
97
98     /**
99      * Class object initialization method.
100      *
101      * @param className name of the class to initialize
102      * @return the initialized class
103      */

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

138     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
139             throws TorqueException
140     {
141         try
142         {
143             QueryDataSet qds = null;
144             List JavaDoc rows = null;
145             try
146             {
147                 qds = new QueryDataSet(results);
148                 rows = getSelectResults(qds);
149             }
150             finally
151             {
152                 if (qds != null)
153                 {
154                     qds.close();
155                 }
156             }
157
158             return populateObjects(rows);
159         }
160         catch (SQLException JavaDoc e)
161         {
162             throw new TorqueException(e);
163         }
164         catch (DataSetException e)
165         {
166             throw new TorqueException(e);
167         }
168     }
169
170
171   
172     /**
173      * Method to do inserts.
174      *
175      * @param criteria object used to create the INSERT statement.
176      * @throws TorqueException Any exceptions caught during processing will be
177      * rethrown wrapped into a TorqueException.
178      */

179     public static ObjectKey doInsert(Criteria criteria)
180         throws TorqueException
181     {
182         return BaseRAttributeAttributeGroupPeer
183             .doInsert(criteria, (Connection JavaDoc) null);
184     }
185
186     /**
187      * Method to do inserts. This method is to be used during a transaction,
188      * otherwise use the doInsert(Criteria) method. It will take care of
189      * the connection details internally.
190      *
191      * @param criteria object used to create the INSERT statement.
192      * @param con the connection to use
193      * @throws TorqueException Any exceptions caught during processing will be
194      * rethrown wrapped into a TorqueException.
195      */

196     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
197         throws TorqueException
198     {
199                     
200         setDbName(criteria);
201
202         if (con == null)
203         {
204             return BasePeer.doInsert(criteria);
205         }
206         else
207         {
208             return BasePeer.doInsert(criteria, con);
209         }
210     }
211
212     /**
213      * Add all the columns needed to create a new object.
214      *
215      * @param criteria object containing the columns to add.
216      * @throws TorqueException Any exceptions caught during processing will be
217      * rethrown wrapped into a TorqueException.
218      */

219     public static void addSelectColumns(Criteria criteria)
220             throws TorqueException
221     {
222           criteria.addSelectColumn(GROUP_ID);
223           criteria.addSelectColumn(ATTRIBUTE_ID);
224           criteria.addSelectColumn(PREFERRED_ORDER);
225       }
226
227     /**
228      * Create a new object of type cls from a resultset row starting
229      * from a specified offset. This is done so that you can select
230      * other rows than just those needed for this object. You may
231      * for example want to create two objects from the same row.
232      *
233      * @throws TorqueException Any exceptions caught during processing will be
234      * rethrown wrapped into a TorqueException.
235      */

236     public static RAttributeAttributeGroup row2Object(Record row,
237                                              int offset,
238                                              Class JavaDoc cls)
239         throws TorqueException
240     {
241         try
242         {
243             RAttributeAttributeGroup obj = (RAttributeAttributeGroup) cls.newInstance();
244             RAttributeAttributeGroupPeer.populateObject(row, offset, obj);
245                   obj.setModified(false);
246               obj.setNew(false);
247
248             return obj;
249         }
250         catch (InstantiationException JavaDoc e)
251         {
252             throw new TorqueException(e);
253         }
254         catch (IllegalAccessException JavaDoc e)
255         {
256             throw new TorqueException(e);
257         }
258     }
259
260     /**
261      * Populates an object from a resultset row starting
262      * from a specified offset. This is done so that you can select
263      * other rows than just those needed for this object. You may
264      * for example want to create two objects from the same row.
265      *
266      * @throws TorqueException Any exceptions caught during processing will be
267      * rethrown wrapped into a TorqueException.
268      */

269     public static void populateObject(Record row,
270                                       int offset,
271                                       RAttributeAttributeGroup obj)
272         throws TorqueException
273     {
274         try
275         {
276                 obj.setGroupId(row.getValue(offset + 0).asIntegerObj());
277                   obj.setAttributeId(row.getValue(offset + 1).asIntegerObj());
278                   obj.setOrder(row.getValue(offset + 2).asInt());
279               }
280         catch (DataSetException e)
281         {
282             throw new TorqueException(e);
283         }
284     }
285
286     /**
287      * Method to do selects.
288      *
289      * @param criteria object used to create the SELECT statement.
290      * @return List of selected Objects
291      * @throws TorqueException Any exceptions caught during processing will be
292      * rethrown wrapped into a TorqueException.
293      */

294     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
295     {
296         return populateObjects(doSelectVillageRecords(criteria));
297     }
298
299     /**
300      * Method to do selects within a transaction.
301      *
302      * @param criteria object used to create the SELECT statement.
303      * @param con the connection to use
304      * @return List of selected Objects
305      * @throws TorqueException Any exceptions caught during processing will be
306      * rethrown wrapped into a TorqueException.
307      */

308     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
309         throws TorqueException
310     {
311         return populateObjects(doSelectVillageRecords(criteria, con));
312     }
313
314     /**
315      * Grabs the raw Village records to be formed into objects.
316      * This method handles connections internally. The Record objects
317      * returned by this method should be considered readonly. Do not
318      * alter the data and call save(), your results may vary, but are
319      * certainly likely to result in hard to track MT bugs.
320      *
321      * @throws TorqueException Any exceptions caught during processing will be
322      * rethrown wrapped into a TorqueException.
323      */

324     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
325         throws TorqueException
326     {
327         return BaseRAttributeAttributeGroupPeer
328             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
329     }
330
331     /**
332      * Grabs the raw Village records to be formed into objects.
333      * This method should be used for transactions
334      *
335      * @param criteria object used to create the SELECT statement.
336      * @param con the connection to use
337      * @throws TorqueException Any exceptions caught during processing will be
338      * rethrown wrapped into a TorqueException.
339      */

340     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
341         throws TorqueException
342     {
343         if (criteria.getSelectColumns().size() == 0)
344         {
345             addSelectColumns(criteria);
346         }
347
348                     
349         setDbName(criteria);
350
351         // BasePeer returns a List of Value (Village) arrays. The array
352
// order follows the order columns were placed in the Select clause.
353
if (con == null)
354         {
355             return BasePeer.doSelect(criteria);
356         }
357         else
358         {
359             return BasePeer.doSelect(criteria, con);
360         }
361     }
362
363     /**
364      * The returned List will contain objects of the default type or
365      * objects that inherit from the default.
366      *
367      * @throws TorqueException Any exceptions caught during processing will be
368      * rethrown wrapped into a TorqueException.
369      */

370     public static List JavaDoc populateObjects(List JavaDoc records)
371         throws TorqueException
372     {
373         List JavaDoc results = new ArrayList JavaDoc(records.size());
374
375         // populate the object(s)
376
for (int i = 0; i < records.size(); i++)
377         {
378             Record row = (Record) records.get(i);
379               results.add(RAttributeAttributeGroupPeer.row2Object(row, 1,
380                 RAttributeAttributeGroupPeer.getOMClass()));
381           }
382         return results;
383     }
384  
385
386     /**
387      * The class that the Peer will make instances of.
388      * If the BO is abstract then you must implement this method
389      * in the BO.
390      *
391      * @throws TorqueException Any exceptions caught during processing will be
392      * rethrown wrapped into a TorqueException.
393      */

394     public static Class JavaDoc getOMClass()
395         throws TorqueException
396     {
397         return CLASS_DEFAULT;
398     }
399
400     /**
401      * Method to do updates.
402      *
403      * @param criteria object containing data that is used to create the UPDATE
404      * statement.
405      * @throws TorqueException Any exceptions caught during processing will be
406      * rethrown wrapped into a TorqueException.
407      */

408     public static void doUpdate(Criteria criteria) throws TorqueException
409     {
410          BaseRAttributeAttributeGroupPeer
411             .doUpdate(criteria, (Connection JavaDoc) null);
412     }
413
414     /**
415      * Method to do updates. This method is to be used during a transaction,
416      * otherwise use the doUpdate(Criteria) method. It will take care of
417      * the connection details internally.
418      *
419      * @param criteria object containing data that is used to create the UPDATE
420      * statement.
421      * @param con the connection to use
422      * @throws TorqueException Any exceptions caught during processing will be
423      * rethrown wrapped into a TorqueException.
424      */

425     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
426         throws TorqueException
427     {
428         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
429                    selectCriteria.put(GROUP_ID, criteria.remove(GROUP_ID));
430                        selectCriteria.put(ATTRIBUTE_ID, criteria.remove(ATTRIBUTE_ID));
431                 
432         setDbName(criteria);
433
434         if (con == null)
435         {
436             BasePeer.doUpdate(selectCriteria, criteria);
437         }
438         else
439         {
440             BasePeer.doUpdate(selectCriteria, criteria, con);
441         }
442     }
443
444     /**
445      * Method to do deletes.
446      *
447      * @param criteria object containing data that is used DELETE from database.
448      * @throws TorqueException Any exceptions caught during processing will be
449      * rethrown wrapped into a TorqueException.
450      */

451      public static void doDelete(Criteria criteria) throws TorqueException
452      {
453          RAttributeAttributeGroupPeer
454             .doDelete(criteria, (Connection JavaDoc) null);
455      }
456
457     /**
458      * Method to do deletes. This method is to be used during a transaction,
459      * otherwise use the doDelete(Criteria) method. It will take care of
460      * the connection details internally.
461      *
462      * @param criteria object containing data that is used DELETE from database.
463      * @param con the connection to use
464      * @throws TorqueException Any exceptions caught during processing will be
465      * rethrown wrapped into a TorqueException.
466      */

467      public static void doDelete(Criteria criteria, Connection JavaDoc con)
468         throws TorqueException
469      {
470                     
471         setDbName(criteria);
472
473         if (con == null)
474         {
475             BasePeer.doDelete(criteria);
476         }
477         else
478         {
479             BasePeer.doDelete(criteria, con);
480         }
481      }
482
483     /**
484      * Method to do selects
485      *
486      * @throws TorqueException Any exceptions caught during processing will be
487      * rethrown wrapped into a TorqueException.
488      */

489     public static List JavaDoc doSelect(RAttributeAttributeGroup obj) throws TorqueException
490     {
491         return doSelect(buildSelectCriteria(obj));
492     }
493
494     /**
495      * Method to do inserts
496      *
497      * @throws TorqueException Any exceptions caught during processing will be
498      * rethrown wrapped into a TorqueException.
499      */

500     public static void doInsert(RAttributeAttributeGroup obj) throws TorqueException
501     {
502           doInsert(buildCriteria(obj));
503           obj.setNew(false);
504         obj.setModified(false);
505     }
506
507     /**
508      * @param obj the data object to update in the database.
509      * @throws TorqueException Any exceptions caught during processing will be
510      * rethrown wrapped into a TorqueException.
511      */

512     public static void doUpdate(RAttributeAttributeGroup obj) throws TorqueException
513     {
514         doUpdate(buildCriteria(obj));
515         obj.setModified(false);
516     }
517
518     /**
519      * @param obj the data object to delete in the database.
520      * @throws TorqueException Any exceptions caught during processing will be
521      * rethrown wrapped into a TorqueException.
522      */

523     public static void doDelete(RAttributeAttributeGroup obj) throws TorqueException
524     {
525         doDelete(buildSelectCriteria(obj));
526     }
527
528     /**
529      * Method to do inserts. This method is to be used during a transaction,
530      * otherwise use the doInsert(RAttributeAttributeGroup) method. It will take
531      * care of the connection details internally.
532      *
533      * @param obj the data object to insert into the database.
534      * @param con the connection to use
535      * @throws TorqueException Any exceptions caught during processing will be
536      * rethrown wrapped into a TorqueException.
537      */

538     public static void doInsert(RAttributeAttributeGroup obj, Connection JavaDoc con)
539         throws TorqueException
540     {
541           doInsert(buildCriteria(obj), con);
542           obj.setNew(false);
543         obj.setModified(false);
544     }
545
546     /**
547      * Method to do update. This method is to be used during a transaction,
548      * otherwise use the doUpdate(RAttributeAttributeGroup) method. It will take
549      * care of the connection details internally.
550      *
551      * @param obj the data object to update in the database.
552      * @param con the connection to use
553      * @throws TorqueException Any exceptions caught during processing will be
554      * rethrown wrapped into a TorqueException.
555      */

556     public static void doUpdate(RAttributeAttributeGroup obj, Connection JavaDoc con)
557         throws TorqueException
558     {
559         doUpdate(buildCriteria(obj), con);
560         obj.setModified(false);
561     }
562
563     /**
564      * Method to delete. This method is to be used during a transaction,
565      * otherwise use the doDelete(RAttributeAttributeGroup) method. It will take
566      * care of the connection details internally.
567      *
568      * @param obj the data object to delete in the database.
569      * @param con the connection to use
570      * @throws TorqueException Any exceptions caught during processing will be
571      * rethrown wrapped into a TorqueException.
572      */

573     public static void doDelete(RAttributeAttributeGroup obj, Connection JavaDoc con)
574         throws TorqueException
575     {
576         doDelete(buildSelectCriteria(obj), con);
577     }
578
579     /**
580      * Method to do deletes.
581      *
582      * @param pk ObjectKey that is used DELETE from database.
583      * @throws TorqueException Any exceptions caught during processing will be
584      * rethrown wrapped into a TorqueException.
585      */

586     public static void doDelete(ObjectKey pk) throws TorqueException
587     {
588         BaseRAttributeAttributeGroupPeer
589            .doDelete(pk, (Connection JavaDoc) null);
590     }
591
592     /**
593      * Method to delete. This method is to be used during a transaction,
594      * otherwise use the doDelete(ObjectKey) method. It will take
595      * care of the connection details internally.
596      *
597      * @param pk the primary key for the object to delete in the database.
598      * @param con the connection to use
599      * @throws TorqueException Any exceptions caught during processing will be
600      * rethrown wrapped into a TorqueException.
601      */

602     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
603         throws TorqueException
604     {
605         doDelete(buildCriteria(pk), con);
606     }
607
608     /** Build a Criteria object from an ObjectKey */
609     public static Criteria buildCriteria( ObjectKey pk )
610     {
611         Criteria criteria = new Criteria();
612           SimpleKey[] keys = (SimpleKey[])pk.getValue();
613                     criteria.add(GROUP_ID, keys[0]);
614                       criteria.add(ATTRIBUTE_ID, keys[1]);
615                     return criteria;
616      }
617
618     /** Build a Criteria object from the data object for this peer */
619     public static Criteria buildCriteria( RAttributeAttributeGroup obj )
620     {
621         Criteria criteria = new Criteria(DATABASE_NAME);
622               criteria.add(GROUP_ID, obj.getGroupId());
623               criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
624               criteria.add(PREFERRED_ORDER, obj.getOrder());
625           return criteria;
626     }
627
628     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
629     public static Criteria buildSelectCriteria( RAttributeAttributeGroup obj )
630     {
631         Criteria criteria = new Criteria(DATABASE_NAME);
632                       criteria.add(GROUP_ID, obj.getGroupId());
633                           criteria.add(ATTRIBUTE_ID, obj.getAttributeId());
634                           criteria.add(PREFERRED_ORDER, obj.getOrder());
635               return criteria;
636     }
637  
638     
639     
640     /**
641      * Retrieve a single object by pk
642      *
643      * @param pk the primary key
644      * @throws TorqueException Any exceptions caught during processing will be
645      * rethrown wrapped into a TorqueException.
646      * @throws NoRowsException Primary key was not found in database.
647      * @throws TooManyRowsException Primary key was not found in database.
648      */

649     public static RAttributeAttributeGroup retrieveByPK(ObjectKey pk)
650         throws TorqueException, NoRowsException, TooManyRowsException
651     {
652         Connection JavaDoc db = null;
653         RAttributeAttributeGroup retVal = null;
654         try
655         {
656             db = Torque.getConnection(DATABASE_NAME);
657             retVal = retrieveByPK(pk, db);
658         }
659         finally
660         {
661             Torque.closeConnection(db);
662         }
663         return(retVal);
664     }
665
666     /**
667      * Retrieve a single object by pk
668      *
669      * @param pk the primary key
670      * @param con the connection to use
671      * @throws TorqueException Any exceptions caught during processing will be
672      * rethrown wrapped into a TorqueException.
673      * @throws NoRowsException Primary key was not found in database.
674      * @throws TooManyRowsException Primary key was not found in database.
675      */

676     public static RAttributeAttributeGroup retrieveByPK(ObjectKey pk, Connection JavaDoc con)
677         throws TorqueException, NoRowsException, TooManyRowsException
678     {
679         Criteria criteria = buildCriteria(pk);
680         List JavaDoc v = doSelect(criteria, con);
681         if (v.size() == 0)
682         {
683             throw new NoRowsException("Failed to select a row.");
684         }
685         else if (v.size() > 1)
686         {
687             throw new TooManyRowsException("Failed to select only one row.");
688         }
689         else
690         {
691             return (RAttributeAttributeGroup)v.get(0);
692         }
693     }
694
695     /**
696      * Retrieve a multiple objects by pk
697      *
698      * @param pks List of primary keys
699      * @throws TorqueException Any exceptions caught during processing will be
700      * rethrown wrapped into a TorqueException.
701      */

702     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
703         throws TorqueException
704     {
705         Connection JavaDoc db = null;
706         List JavaDoc retVal = null;
707         try
708         {
709            db = Torque.getConnection(DATABASE_NAME);
710            retVal = retrieveByPKs(pks, db);
711         }
712         finally
713         {
714             Torque.closeConnection(db);
715         }
716         return(retVal);
717     }
718
719     /**
720      * Retrieve a multiple objects by pk
721      *
722      * @param pks List of primary keys
723      * @param dbcon the connection to use
724      * @throws TorqueException Any exceptions caught during processing will be
725      * rethrown wrapped into a TorqueException.
726      */

727     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
728         throws TorqueException
729     {
730         List JavaDoc objs = null;
731         if (pks == null || pks.size() == 0)
732         {
733             objs = new LinkedList JavaDoc();
734         }
735         else
736         {
737             Criteria criteria = new Criteria();
738               Iterator JavaDoc iter = pks.iterator();
739             while (iter.hasNext())
740             {
741                 ObjectKey pk = (ObjectKey)iter.next();
742                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
743                             Criteria.Criterion c0 = criteria.getNewCriterion(
744                         GROUP_ID, keys[0], Criteria.EQUAL);
745                                     Criteria.Criterion c1 = criteria.getNewCriterion(
746                         ATTRIBUTE_ID, keys[1], Criteria.EQUAL);
747                                     c0.and(c1);
748                           criteria.or(c0);
749             }
750           objs = doSelect(criteria, dbcon);
751         }
752         return objs;
753     }
754
755  
756     /**
757      * retrieve object using using pk values.
758      *
759        * @param group_id Integer
760        * @param attribute_id Integer
761        */

762     public static RAttributeAttributeGroup retrieveByPK(
763        Integer JavaDoc group_id
764           , Integer JavaDoc attribute_id
765               ) throws TorqueException
766     {
767         Connection JavaDoc db = null;
768         RAttributeAttributeGroup retVal = null;
769         try
770         {
771            db = Torque.getConnection(DATABASE_NAME);
772            retVal = retrieveByPK(
773          group_id
774           , attribute_id
775                      , db);
776         }
777         finally
778         {
779             Torque.closeConnection(db);
780         }
781         return(retVal);
782     }
783
784       /**
785      * retrieve object using using pk values.
786      *
787        * @param group_id Integer
788        * @param attribute_id Integer
789        * @param con Connection
790      */

791     public static RAttributeAttributeGroup retrieveByPK(
792        Integer JavaDoc group_id
793           , Integer JavaDoc attribute_id
794              ,Connection JavaDoc con) throws TorqueException
795     {
796
797         Criteria criteria = new Criteria(5);
798           criteria.add(GROUP_ID, group_id);
799           criteria.add(ATTRIBUTE_ID, attribute_id);
800           List JavaDoc v = doSelect(criteria, con);
801         if (v.size() != 1)
802         {
803             throw new TorqueException("Failed to select one and only one row.");
804         }
805         else
806         {
807             return (RAttributeAttributeGroup) v.get(0);
808         }
809     }
810
811
812
813             
814                                               
815                 
816                 
817
818     /**
819      * selects a collection of RAttributeAttributeGroup objects pre-filled with their
820      * Attribute 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 JavaDoc doSelectJoinAttribute(Criteria criteria)
830         throws TorqueException
831     {
832         setDbName(criteria);
833
834         RAttributeAttributeGroupPeer.addSelectColumns(criteria);
835         int offset = numColumns + 1;
836         AttributePeer.addSelectColumns(criteria);
837
838
839                         criteria.addJoin(RAttributeAttributeGroupPeer.ATTRIBUTE_ID,
840             AttributePeer.ATTRIBUTE_ID);
841         
842
843                                                               
844         List JavaDoc rows = BasePeer.doSelect(criteria);
845         List JavaDoc results = new ArrayList JavaDoc();
846
847         for (int i = 0; i < rows.size(); i++)
848         {
849             Record row = (Record) rows.get(i);
850
851                             Class JavaDoc omClass = RAttributeAttributeGroupPeer.getOMClass();
852                     RAttributeAttributeGroup obj1 = (RAttributeAttributeGroup) RAttributeAttributeGroupPeer
853                 .row2Object(row, 1, omClass);
854                      omClass = AttributePeer.getOMClass();
855                     Attribute obj2 = (Attribute)AttributePeer
856                 .row2Object(row, offset, omClass);
857
858             boolean newObject = true;
859             for (int j = 0; j < results.size(); j++)
860             {
861                 RAttributeAttributeGroup temp_obj1 = (RAttributeAttributeGroup)results.get(j);
862                 Attribute temp_obj2 = (Attribute)temp_obj1.getAttribute();
863                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
864                 {
865                     newObject = false;
866                               temp_obj2.addRAttributeAttributeGroup(obj1);
867                               break;
868                 }
869             }
870                       if (newObject)
871             {
872                 obj2.initRAttributeAttributeGroups();
873                 obj2.addRAttributeAttributeGroup(obj1);
874             }
875                       results.add(obj1);
876         }
877         return results;
878     }
879                                                             
880                 
881                 
882
883     /**
884      * selects a collection of RAttributeAttributeGroup objects pre-filled with their
885      * AttributeGroup objects.
886      *
887      * This method is protected by default in order to keep the public
888      * api reasonable. You can provide public methods for those you
889      * actually need in RAttributeAttributeGroupPeer.
890      *
891      * @throws TorqueException Any exceptions caught during processing will be
892      * rethrown wrapped into a TorqueException.
893      */

894     protected static List JavaDoc doSelectJoinAttributeGroup(Criteria criteria)
895         throws TorqueException
896     {
897         setDbName(criteria);
898
899         RAttributeAttributeGroupPeer.addSelectColumns(criteria);
900         int offset = numColumns + 1;
901         AttributeGroupPeer.addSelectColumns(criteria);
902
903
904                         criteria.addJoin(RAttributeAttributeGroupPeer.GROUP_ID,
905             AttributeGroupPeer.ATTRIBUTE_GROUP_ID);
906         
907
908                                                               
909         List JavaDoc rows = BasePeer.doSelect(criteria);
910         List JavaDoc results = new ArrayList JavaDoc();
911
912         for (int i = 0; i < rows.size(); i++)
913         {
914             Record row = (Record) rows.get(i);
915
916                             Class JavaDoc omClass = RAttributeAttributeGroupPeer.getOMClass();
917                     RAttributeAttributeGroup obj1 = (RAttributeAttributeGroup) RAttributeAttributeGroupPeer
918                 .row2Object(row, 1, omClass);
919                      omClass = AttributeGroupPeer.getOMClass();
920                     AttributeGroup obj2 = (AttributeGroup)AttributeGroupPeer
921                 .row2Object(row, offset, omClass);
922
923             boolean newObject = true;
924             for (int j = 0; j < results.size(); j++)
925             {
926                 RAttributeAttributeGroup temp_obj1 = (RAttributeAttributeGroup)results.get(j);
927                 AttributeGroup temp_obj2 = (AttributeGroup)temp_obj1.getAttributeGroup();
928                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
929                 {
930                     newObject = false;
931                               temp_obj2.addRAttributeAttributeGroup(obj1);
932                               break;
933                 }
934             }
935                       if (newObject)
936             {
937                 obj2.initRAttributeAttributeGroups();
938                 obj2.addRAttributeAttributeGroup(obj1);
939             }
940                       results.add(obj1);
941         }
942         return results;
943     }
944                     
945   
946     
947   
948       /**
949      * Returns the TableMap related to this peer. This method is not
950      * needed for general use but a specific application could have a need.
951      *
952      * @throws TorqueException Any exceptions caught during processing will be
953      * rethrown wrapped into a TorqueException.
954      */

955     protected static TableMap getTableMap()
956         throws TorqueException
957     {
958         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
959     }
960    
961     private static void setDbName(Criteria crit)
962     {
963         // Set the correct dbName if it has not been overridden
964
// crit.getDbName will return the same object if not set to
965
// another value so == check is okay and faster
966
if (crit.getDbName() == Torque.getDefaultDB())
967         {
968             crit.setDbName(DATABASE_NAME);
969         }
970     }
971 }
972
Popular Tags