KickJava   Java API By Example, From Geeks To Geeks.

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


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 BasePendingGroupUserRolePeer
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_PENDING_GROUP_USER_ROLE";
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(PendingGroupUserRoleMapBuilder.CLASS_NAME);
57     }
58
59       /** the column name for the USER_ID field */
60     public static final String JavaDoc USER_ID;
61       /** the column name for the GROUP_ID field */
62     public static final String JavaDoc GROUP_ID;
63       /** the column name for the ROLE_NAME field */
64     public static final String JavaDoc ROLE_NAME;
65   
66     static
67     {
68           USER_ID = "SCARAB_PENDING_GROUP_USER_ROLE.USER_ID";
69           GROUP_ID = "SCARAB_PENDING_GROUP_USER_ROLE.GROUP_ID";
70           ROLE_NAME = "SCARAB_PENDING_GROUP_USER_ROLE.ROLE_NAME";
71           if (Torque.isInit())
72         {
73             try
74             {
75                 getMapBuilder(PendingGroupUserRoleMapBuilder.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(PendingGroupUserRoleMapBuilder.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.PendingGroupUserRole";
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 BasePendingGroupUserRolePeer
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(USER_ID);
223           criteria.addSelectColumn(GROUP_ID);
224           criteria.addSelectColumn(ROLE_NAME);
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 PendingGroupUserRole row2Object(Record row,
237                                              int offset,
238                                              Class JavaDoc cls)
239         throws TorqueException
240     {
241         try
242         {
243             PendingGroupUserRole obj = (PendingGroupUserRole) cls.newInstance();
244             PendingGroupUserRolePeer.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                                       PendingGroupUserRole obj)
272         throws TorqueException
273     {
274         try
275         {
276                 obj.setUserId(row.getValue(offset + 0).asIntegerObj());
277                   obj.setGroupId(row.getValue(offset + 1).asIntegerObj());
278                   obj.setRoleName(row.getValue(offset + 2).asString());
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 BasePendingGroupUserRolePeer
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(PendingGroupUserRolePeer.row2Object(row, 1,
380                 PendingGroupUserRolePeer.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          BasePendingGroupUserRolePeer
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(USER_ID, criteria.remove(USER_ID));
430                        selectCriteria.put(GROUP_ID, criteria.remove(GROUP_ID));
431                        selectCriteria.put(ROLE_NAME, criteria.remove(ROLE_NAME));
432       
433         setDbName(criteria);
434
435         if (con == null)
436         {
437             BasePeer.doUpdate(selectCriteria, criteria);
438         }
439         else
440         {
441             BasePeer.doUpdate(selectCriteria, criteria, con);
442         }
443     }
444
445     /**
446      * Method to do deletes.
447      *
448      * @param criteria object containing data that is used DELETE from database.
449      * @throws TorqueException Any exceptions caught during processing will be
450      * rethrown wrapped into a TorqueException.
451      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

768     public static PendingGroupUserRole retrieveByPK(
769        Integer JavaDoc user_id
770           , Integer JavaDoc group_id
771           , String JavaDoc role_name
772               ) throws TorqueException
773     {
774         Connection JavaDoc db = null;
775         PendingGroupUserRole retVal = null;
776         try
777         {
778            db = Torque.getConnection(DATABASE_NAME);
779            retVal = retrieveByPK(
780          user_id
781           , group_id
782           , role_name
783                      , db);
784         }
785         finally
786         {
787             Torque.closeConnection(db);
788         }
789         return(retVal);
790     }
791
792       /**
793      * retrieve object using using pk values.
794      *
795        * @param user_id Integer
796        * @param group_id Integer
797        * @param role_name String
798        * @param con Connection
799      */

800     public static PendingGroupUserRole retrieveByPK(
801        Integer JavaDoc user_id
802           , Integer JavaDoc group_id
803           , String JavaDoc role_name
804              ,Connection JavaDoc con) throws TorqueException
805     {
806
807         Criteria criteria = new Criteria(5);
808           criteria.add(USER_ID, user_id);
809           criteria.add(GROUP_ID, group_id);
810           criteria.add(ROLE_NAME, role_name);
811           List JavaDoc v = doSelect(criteria, con);
812         if (v.size() != 1)
813         {
814             throw new TorqueException("Failed to select one and only one row.");
815         }
816         else
817         {
818             return (PendingGroupUserRole) v.get(0);
819         }
820     }
821
822
823
824             
825                                               
826                         
827                 
828
829     /**
830      * selects a collection of PendingGroupUserRole objects pre-filled with their
831      * ScarabUserImpl objects.
832      *
833      * This method is protected by default in order to keep the public
834      * api reasonable. You can provide public methods for those you
835      * actually need in PendingGroupUserRolePeer.
836      *
837      * @throws TorqueException Any exceptions caught during processing will be
838      * rethrown wrapped into a TorqueException.
839      */

840     protected static List JavaDoc doSelectJoinScarabUserImpl(Criteria criteria)
841         throws TorqueException
842     {
843         setDbName(criteria);
844
845         PendingGroupUserRolePeer.addSelectColumns(criteria);
846         int offset = numColumns + 1;
847         ScarabUserImplPeer.addSelectColumns(criteria);
848
849
850                         criteria.addJoin(PendingGroupUserRolePeer.USER_ID,
851             ScarabUserImplPeer.USER_ID);
852         
853
854                                                               
855         List JavaDoc rows = BasePeer.doSelect(criteria);
856         List JavaDoc results = new ArrayList JavaDoc();
857
858         for (int i = 0; i < rows.size(); i++)
859         {
860             Record row = (Record) rows.get(i);
861
862                             Class JavaDoc omClass = PendingGroupUserRolePeer.getOMClass();
863                     PendingGroupUserRole obj1 = (PendingGroupUserRole) PendingGroupUserRolePeer
864                 .row2Object(row, 1, omClass);
865                      omClass = ScarabUserImplPeer.getOMClass();
866                     ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer
867                 .row2Object(row, offset, omClass);
868
869             boolean newObject = true;
870             for (int j = 0; j < results.size(); j++)
871             {
872                 PendingGroupUserRole temp_obj1 = (PendingGroupUserRole)results.get(j);
873                 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUser();
874                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
875                 {
876                     newObject = false;
877                               temp_obj2.addPendingGroupUserRole(obj1);
878                               break;
879                 }
880             }
881                       if (newObject)
882             {
883                 obj2.initPendingGroupUserRoles();
884                 obj2.addPendingGroupUserRole(obj1);
885             }
886                       results.add(obj1);
887         }
888         return results;
889     }
890                                                             
891                         
892                 
893
894     /**
895      * selects a collection of PendingGroupUserRole objects pre-filled with their
896      * ScarabModule objects.
897      *
898      * This method is protected by default in order to keep the public
899      * api reasonable. You can provide public methods for those you
900      * actually need in PendingGroupUserRolePeer.
901      *
902      * @throws TorqueException Any exceptions caught during processing will be
903      * rethrown wrapped into a TorqueException.
904      */

905     protected static List JavaDoc doSelectJoinScarabModule(Criteria criteria)
906         throws TorqueException
907     {
908         setDbName(criteria);
909
910         PendingGroupUserRolePeer.addSelectColumns(criteria);
911         int offset = numColumns + 1;
912         ScarabModulePeer.addSelectColumns(criteria);
913
914
915                         criteria.addJoin(PendingGroupUserRolePeer.GROUP_ID,
916             ScarabModulePeer.MODULE_ID);
917         
918
919                                                               
920         List JavaDoc rows = BasePeer.doSelect(criteria);
921         List JavaDoc results = new ArrayList JavaDoc();
922
923         for (int i = 0; i < rows.size(); i++)
924         {
925             Record row = (Record) rows.get(i);
926
927                             Class JavaDoc omClass = PendingGroupUserRolePeer.getOMClass();
928                     PendingGroupUserRole obj1 = (PendingGroupUserRole) PendingGroupUserRolePeer
929                 .row2Object(row, 1, omClass);
930                      omClass = ScarabModulePeer.getOMClass(row, offset);
931                     ScarabModule obj2 = (ScarabModule)ScarabModulePeer
932                 .row2Object(row, offset, omClass);
933
934             boolean newObject = true;
935             for (int j = 0; j < results.size(); j++)
936             {
937                 PendingGroupUserRole temp_obj1 = (PendingGroupUserRole)results.get(j);
938                 ScarabModule temp_obj2 = (ScarabModule)temp_obj1.getModule();
939                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
940                 {
941                     newObject = false;
942                               temp_obj2.addPendingGroupUserRole(obj1);
943                               break;
944                 }
945             }
946                       if (newObject)
947             {
948                 obj2.initPendingGroupUserRoles();
949                 obj2.addPendingGroupUserRole(obj1);
950             }
951                       results.add(obj1);
952         }
953         return results;
954     }
955                     
956   
957     
958   
959       /**
960      * Returns the TableMap related to this peer. This method is not
961      * needed for general use but a specific application could have a need.
962      *
963      * @throws TorqueException Any exceptions caught during processing will be
964      * rethrown wrapped into a TorqueException.
965      */

966     protected static TableMap getTableMap()
967         throws TorqueException
968     {
969         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
970     }
971    
972     private static void setDbName(Criteria crit)
973     {
974         // Set the correct dbName if it has not been overridden
975
// crit.getDbName will return the same object if not set to
976
// another value so == check is okay and faster
977
if (crit.getDbName() == Torque.getDefaultDB())
978         {
979             crit.setDbName(DATABASE_NAME);
980         }
981     }
982 }
983
Popular Tags