KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fulcrum > security > impl > db > entity > BaseTurbineRolePermissionPeer


1 package org.apache.fulcrum.security.impl.db.entity;
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.apache.fulcrum.security.impl.db.entity.map.*;
32
33
34   
35   
36 /**
37  */

38 public abstract class BaseTurbineRolePermissionPeer
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 = "TURBINE_ROLE_PERMISSION";
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(TurbineRolePermissionMapBuilder.CLASS_NAME);
57     }
58
59       /** the column name for the ROLE_ID field */
60     public static final String JavaDoc ROLE_ID;
61       /** the column name for the PERMISSION_ID field */
62     public static final String JavaDoc PERMISSION_ID;
63   
64     static
65     {
66           ROLE_ID = "TURBINE_ROLE_PERMISSION.ROLE_ID";
67           PERMISSION_ID = "TURBINE_ROLE_PERMISSION.PERMISSION_ID";
68           if (Torque.isInit())
69         {
70             try
71             {
72                 getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME);
73             }
74             catch (Exception JavaDoc e)
75             {
76                 log.error("Could not initialize Peer", e);
77             }
78         }
79         else
80         {
81             Torque.registerMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME);
82         }
83     }
84  
85     /** number of columns for this peer */
86     public static final int numColumns = 2;
87
88     /** A class that can be returned by this peer. */
89     protected static final String JavaDoc CLASSNAME_DEFAULT =
90         "org.apache.fulcrum.security.impl.db.entity.TurbineRolePermission";
91
92     /** A class that can be returned by this peer. */
93     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
94
95     /**
96      * Class object initialization method.
97      *
98      * @param className name of the class to initialize
99      * @return the initialized class
100      */

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

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

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

193     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
194         throws TorqueException
195     {
196               
197         // Set the correct dbName if it has not been overridden
198
// criteria.getDbName will return the same object if not set to
199
// another value so == check is okay and faster
200
if (criteria.getDbName() == Torque.getDefaultDB())
201         {
202             criteria.setDbName(DATABASE_NAME);
203         }
204         if (con == null)
205         {
206             return BasePeer.doInsert(criteria);
207         }
208         else
209         {
210             return BasePeer.doInsert(criteria, con);
211         }
212     }
213
214     /**
215      * Add all the columns needed to create a new object.
216      *
217      * @param criteria object containing the columns to add.
218      * @throws TorqueException Any exceptions caught during processing will be
219      * rethrown wrapped into a TorqueException.
220      */

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

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

270     public static void populateObject(Record row,
271                                       int offset,
272                                       TurbineRolePermission obj)
273         throws TorqueException
274     {
275         try
276         {
277                 obj.setRoleId(row.getValue(offset + 0).asIntegerObj());
278                   obj.setPermissionId(row.getValue(offset + 1).asIntegerObj());
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 BaseTurbineRolePermissionPeer
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 con the connection to use
336      * @throws TorqueException Any exceptions caught during processing will be
337      * rethrown wrapped into a TorqueException.
338      */

339     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
340         throws TorqueException
341     {
342         if (criteria.getSelectColumns().size() == 0)
343         {
344             addSelectColumns(criteria);
345         }
346
347               
348         // Set the correct dbName if it has not been overridden
349
// criteria.getDbName will return the same object if not set to
350
// another value so == check is okay and faster
351
if (criteria.getDbName() == Torque.getDefaultDB())
352         {
353             criteria.setDbName(DATABASE_NAME);
354         }
355         // BasePeer returns a List of Value (Village) arrays. The array
356
// order follows the order columns were placed in the Select clause.
357
if (con == null)
358         {
359             return BasePeer.doSelect(criteria);
360         }
361         else
362         {
363             return BasePeer.doSelect(criteria, con);
364         }
365     }
366
367     /**
368      * The returned List will contain objects of the default type or
369      * objects that inherit from the default.
370      *
371      * @throws TorqueException Any exceptions caught during processing will be
372      * rethrown wrapped into a TorqueException.
373      */

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

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

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

429     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
430         throws TorqueException
431     {
432         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
433                    selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID));
434                        selectCriteria.put(PERMISSION_ID, criteria.remove(PERMISSION_ID));
435       
436         // Set the correct dbName if it has not been overridden
437
// criteria.getDbName will return the same object if not set to
438
// another value so == check is okay and faster
439
if (criteria.getDbName() == Torque.getDefaultDB())
440         {
441             criteria.setDbName(DATABASE_NAME);
442         }
443         if (con == null)
444         {
445             BasePeer.doUpdate(selectCriteria, criteria);
446         }
447         else
448         {
449             BasePeer.doUpdate(selectCriteria, criteria, con);
450         }
451     }
452
453     /**
454      * Method to do deletes.
455      *
456      * @param criteria object containing data that is used DELETE from database.
457      * @throws TorqueException Any exceptions caught during processing will be
458      * rethrown wrapped into a TorqueException.
459      */

460      public static void doDelete(Criteria criteria) throws TorqueException
461      {
462          BaseTurbineRolePermissionPeer
463             .doDelete(criteria, (Connection JavaDoc) null);
464      }
465
466     /**
467      * Method to do deletes. This method is to be used during a transaction,
468      * otherwise use the doDelete(Criteria) method. It will take care of
469      * the connection details internally.
470      *
471      * @param criteria object containing data that is used DELETE from database.
472      * @param con the connection to use
473      * @throws TorqueException Any exceptions caught during processing will be
474      * rethrown wrapped into a TorqueException.
475      */

476      public static void doDelete(Criteria criteria, Connection JavaDoc con)
477         throws TorqueException
478      {
479               
480         // Set the correct dbName if it has not been overridden
481
// criteria.getDbName will return the same object if not set to
482
// another value so == check is okay and faster
483
if (criteria.getDbName() == Torque.getDefaultDB())
484         {
485             criteria.setDbName(DATABASE_NAME);
486         }
487         if (con == null)
488         {
489             BasePeer.doDelete(criteria);
490         }
491         else
492         {
493             BasePeer.doDelete(criteria, con);
494         }
495      }
496
497     /**
498      * Method to do selects
499      *
500      * @throws TorqueException Any exceptions caught during processing will be
501      * rethrown wrapped into a TorqueException.
502      */

503     public static List JavaDoc doSelect(TurbineRolePermission obj) throws TorqueException
504     {
505         return doSelect(buildCriteria(obj));
506     }
507
508     /**
509      * Method to do inserts
510      *
511      * @throws TorqueException Any exceptions caught during processing will be
512      * rethrown wrapped into a TorqueException.
513      */

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

526     public static void doUpdate(TurbineRolePermission obj) throws TorqueException
527     {
528         doUpdate(buildCriteria(obj));
529         obj.setModified(false);
530     }
531
532     /**
533      * @param obj the data object to delete in the database.
534      * @throws TorqueException Any exceptions caught during processing will be
535      * rethrown wrapped into a TorqueException.
536      */

537     public static void doDelete(TurbineRolePermission obj) throws TorqueException
538     {
539         doDelete(buildCriteria(obj));
540     }
541
542     /**
543      * Method to do inserts. This method is to be used during a transaction,
544      * otherwise use the doInsert(TurbineRolePermission) method. It will take
545      * care of the connection details internally.
546      *
547      * @param obj the data object to insert into the database.
548      * @param con the connection to use
549      * @throws TorqueException Any exceptions caught during processing will be
550      * rethrown wrapped into a TorqueException.
551      */

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

570     public static void doUpdate(TurbineRolePermission obj, Connection JavaDoc con)
571         throws TorqueException
572     {
573         doUpdate(buildCriteria(obj), con);
574         obj.setModified(false);
575     }
576
577     /**
578      * Method to delete. This method is to be used during a transaction,
579      * otherwise use the doDelete(TurbineRolePermission) method. It will take
580      * care of the connection details internally.
581      *
582      * @param obj the data object to delete in the database.
583      * @param con the connection to use
584      * @throws TorqueException Any exceptions caught during processing will be
585      * rethrown wrapped into a TorqueException.
586      */

587     public static void doDelete(TurbineRolePermission obj, Connection JavaDoc con)
588         throws TorqueException
589     {
590         doDelete(buildCriteria(obj), con);
591     }
592
593     /**
594      * Method to do deletes.
595      *
596      * @param pk ObjectKey that is used DELETE from database.
597      * @throws TorqueException Any exceptions caught during processing will be
598      * rethrown wrapped into a TorqueException.
599      */

600     public static void doDelete(ObjectKey pk) throws TorqueException
601     {
602         BaseTurbineRolePermissionPeer
603            .doDelete(pk, (Connection JavaDoc) null);
604     }
605
606     /**
607      * Method to delete. This method is to be used during a transaction,
608      * otherwise use the doDelete(ObjectKey) method. It will take
609      * care of the connection details internally.
610      *
611      * @param pk the primary key for the object to delete in the database.
612      * @param con the connection to use
613      * @throws TorqueException Any exceptions caught during processing will be
614      * rethrown wrapped into a TorqueException.
615      */

616     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
617         throws TorqueException
618     {
619         doDelete(buildCriteria(pk), con);
620     }
621
622     /** Build a Criteria object from an ObjectKey */
623     public static Criteria buildCriteria( ObjectKey pk )
624     {
625         Criteria criteria = new Criteria();
626           SimpleKey[] keys = (SimpleKey[])pk.getValue();
627                     criteria.add(ROLE_ID, keys[0]);
628                       criteria.add(PERMISSION_ID, keys[1]);
629                     return criteria;
630      }
631
632     /** Build a Criteria object from the data object for this peer */
633     public static Criteria buildCriteria( TurbineRolePermission obj )
634     {
635         Criteria criteria = new Criteria(DATABASE_NAME);
636                   criteria.add(ROLE_ID, obj.getRoleId());
637                   criteria.add(PERMISSION_ID, obj.getPermissionId());
638           return criteria;
639     }
640  
641     
642     
643     /**
644      * Retrieve a single object by pk
645      *
646      * @param pk the primary key
647      * @throws TorqueException Any exceptions caught during processing will be
648      * rethrown wrapped into a TorqueException.
649      * @throws NoRowsException Primary key was not found in database.
650      * @throws TooManyRowsException Primary key was not found in database.
651      */

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

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

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

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

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

794     public static TurbineRolePermission retrieveByPK(
795        Integer JavaDoc role_id
796           , Integer JavaDoc permission_id
797              ,Connection JavaDoc con) throws TorqueException
798     {
799
800         Criteria criteria = new Criteria(5);
801           criteria.add(ROLE_ID, role_id);
802           criteria.add(PERMISSION_ID, permission_id);
803           List JavaDoc v = doSelect(criteria, con);
804         if (v.size() != 1)
805         {
806             throw new TorqueException("Failed to select one and only one row.");
807         }
808         else
809         {
810             return (TurbineRolePermission) v.get(0);
811         }
812     }
813
814
815
816             
817                                               
818                 
819                 
820
821     /**
822      * selects a collection of TurbineRolePermission objects pre-filled with their
823      * TurbineRole objects.
824      *
825      * This method is protected by default in order to keep the public
826      * api reasonable. You can provide public methods for those you
827      * actually need in TurbineRolePermissionPeer.
828      *
829      * @throws TorqueException Any exceptions caught during processing will be
830      * rethrown wrapped into a TorqueException.
831      */

832     protected static List JavaDoc doSelectJoinTurbineRole(Criteria c)
833         throws TorqueException
834     {
835         // Set the correct dbName if it has not been overridden
836
// c.getDbName will return the same object if not set to
837
// another value so == check is okay and faster
838
if (c.getDbName() == Torque.getDefaultDB())
839         {
840             c.setDbName(DATABASE_NAME);
841         }
842
843         TurbineRolePermissionPeer.addSelectColumns(c);
844         int offset = numColumns + 1;
845         TurbineRolePeer.addSelectColumns(c);
846
847
848                         c.addJoin(TurbineRolePermissionPeer.ROLE_ID,
849             TurbineRolePeer.ROLE_ID);
850         
851
852                                             
853         List JavaDoc rows = BasePeer.doSelect(c);
854         List JavaDoc results = new ArrayList JavaDoc();
855
856         for (int i = 0; i < rows.size(); i++)
857         {
858             Record row = (Record) rows.get(i);
859
860                             Class JavaDoc omClass = TurbineRolePermissionPeer.getOMClass();
861                     TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer
862                 .row2Object(row, 1, omClass);
863                      omClass = TurbineRolePeer.getOMClass();
864                     TurbineRole obj2 = (TurbineRole)TurbineRolePeer
865                 .row2Object(row, offset, omClass);
866
867             boolean newObject = true;
868             for (int j = 0; j < results.size(); j++)
869             {
870                 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j);
871                 TurbineRole temp_obj2 = (TurbineRole)temp_obj1.getTurbineRole();
872                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
873                 {
874                     newObject = false;
875                     temp_obj2.addTurbineRolePermission(obj1);
876                     break;
877                 }
878             }
879             if (newObject)
880             {
881                 obj2.initTurbineRolePermissions();
882                 obj2.addTurbineRolePermission(obj1);
883             }
884             results.add(obj1);
885         }
886         return results;
887     }
888                                                             
889                 
890                 
891
892     /**
893      * selects a collection of TurbineRolePermission objects pre-filled with their
894      * TurbinePermission objects.
895      *
896      * This method is protected by default in order to keep the public
897      * api reasonable. You can provide public methods for those you
898      * actually need in TurbineRolePermissionPeer.
899      *
900      * @throws TorqueException Any exceptions caught during processing will be
901      * rethrown wrapped into a TorqueException.
902      */

903     protected static List JavaDoc doSelectJoinTurbinePermission(Criteria c)
904         throws TorqueException
905     {
906         // Set the correct dbName if it has not been overridden
907
// c.getDbName will return the same object if not set to
908
// another value so == check is okay and faster
909
if (c.getDbName() == Torque.getDefaultDB())
910         {
911             c.setDbName(DATABASE_NAME);
912         }
913
914         TurbineRolePermissionPeer.addSelectColumns(c);
915         int offset = numColumns + 1;
916         TurbinePermissionPeer.addSelectColumns(c);
917
918
919                         c.addJoin(TurbineRolePermissionPeer.PERMISSION_ID,
920             TurbinePermissionPeer.PERMISSION_ID);
921         
922
923                                             
924         List JavaDoc rows = BasePeer.doSelect(c);
925         List JavaDoc results = new ArrayList JavaDoc();
926
927         for (int i = 0; i < rows.size(); i++)
928         {
929             Record row = (Record) rows.get(i);
930
931                             Class JavaDoc omClass = TurbineRolePermissionPeer.getOMClass();
932                     TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer
933                 .row2Object(row, 1, omClass);
934                      omClass = TurbinePermissionPeer.getOMClass();
935                     TurbinePermission obj2 = (TurbinePermission)TurbinePermissionPeer
936                 .row2Object(row, offset, omClass);
937
938             boolean newObject = true;
939             for (int j = 0; j < results.size(); j++)
940             {
941                 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j);
942                 TurbinePermission temp_obj2 = (TurbinePermission)temp_obj1.getTurbinePermission();
943                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
944                 {
945                     newObject = false;
946                     temp_obj2.addTurbineRolePermission(obj1);
947                     break;
948                 }
949             }
950             if (newObject)
951             {
952                 obj2.initTurbineRolePermissions();
953                 obj2.addTurbineRolePermission(obj1);
954             }
955             results.add(obj1);
956         }
957         return results;
958     }
959                     
960   
961     
962   
963       /**
964      * Returns the TableMap related to this peer. This method is not
965      * needed for general use but a specific application could have a need.
966      *
967      * @throws TorqueException Any exceptions caught during processing will be
968      * rethrown wrapped into a TorqueException.
969      */

970     protected static TableMap getTableMap()
971         throws TorqueException
972     {
973         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
974     }
975    }
976
Popular Tags