View Javadoc

1   package org.apache.turbine.services.security.torque.om;
2   
3   import java.math.BigDecimal;
4   import java.sql.Connection;
5   import java.sql.SQLException;
6   import java.util.ArrayList;
7   import java.util.Date;
8   import java.util.Iterator;
9   import java.util.LinkedList;
10  import java.util.List;
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.turbine.services.security.torque.om.map.*;
32  
33  
34  
35  /***
36   * This class was autogenerated by Torque on:
37   *
38   * [Mon May 28 10:17:20 EST 2007]
39   *
40   */
41  public abstract class BaseTurbineRolePermissionPeer
42      extends BasePeer
43  {
44  
45      /*** the default database name for this class */
46      public static final String DATABASE_NAME = "default";
47  
48       /*** the table name for this class */
49      public static final String TABLE_NAME = "TURBINE_ROLE_PERMISSION";
50  
51      /***
52       * @return the map builder for this peer
53       * @throws TorqueException Any exceptions caught during processing will be
54       *         rethrown wrapped into a TorqueException.
55       */
56      public static MapBuilder getMapBuilder()
57          throws TorqueException
58      {
59          return getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME);
60      }
61  
62        /*** the column name for the ROLE_ID field */
63      public static final String ROLE_ID;
64        /*** the column name for the PERMISSION_ID field */
65      public static final String PERMISSION_ID;
66    
67      static
68      {
69            ROLE_ID = "TURBINE_ROLE_PERMISSION.ROLE_ID";
70            PERMISSION_ID = "TURBINE_ROLE_PERMISSION.PERMISSION_ID";
71            if (Torque.isInit())
72          {
73              try
74              {
75                  getMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME);
76              }
77              catch (Exception e)
78              {
79                  log.error("Could not initialize Peer", e);
80                  throw new RuntimeException(e);
81              }
82          }
83          else
84          {
85              Torque.registerMapBuilder(TurbineRolePermissionMapBuilder.CLASS_NAME);
86          }
87      }
88   
89      /*** number of columns for this peer */
90      public static final int numColumns =  2;
91  
92      /*** A class that can be returned by this peer. */
93      protected static final String CLASSNAME_DEFAULT =
94          "org.apache.turbine.services.security.torque.om.TurbineRolePermission";
95  
96      /*** A class that can be returned by this peer. */
97      protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
98  
99      /***
100      * Class object initialization method.
101      *
102      * @param className name of the class to initialize
103      * @return the initialized class
104      */
105     private static Class initClass(String className)
106     {
107         Class c = null;
108         try
109         {
110             c = Class.forName(className);
111         }
112         catch (Throwable t)
113         {
114             log.error("A FATAL ERROR has occurred which should not "
115                 + "have happened under any circumstance.  Please notify "
116                 + "the Torque developers <torque-dev@db.apache.org> "
117                 + "and give as many details as possible (including the error "
118                 + "stack trace).", t);
119 
120             // Error objects should always be propogated.
121             if (t instanceof Error)
122             {
123                 throw (Error) t.fillInStackTrace();
124             }
125         }
126         return c;
127     }
128 
129     /***
130      * Get the list of objects for a ResultSet.  Please not that your
131      * resultset MUST return columns in the right order.  You can use
132      * getFieldNames() in BaseObject to get the correct sequence.
133      *
134      * @param results the ResultSet
135      * @return the list of objects
136      * @throws TorqueException Any exceptions caught during processing will be
137      *         rethrown wrapped into a TorqueException.
138      */
139     public static List resultSet2Objects(java.sql.ResultSet results)
140             throws TorqueException
141     {
142         try
143         {
144             QueryDataSet qds = null;
145             List rows = null;
146             try
147             {
148                 qds = new QueryDataSet(results);
149                 rows = getSelectResults(qds);
150             }
151             finally
152             {
153                 if (qds != null)
154                 {
155                     qds.close();
156                 }
157             }
158 
159             return populateObjects(rows);
160         }
161         catch (SQLException e)
162         {
163             throw new TorqueException(e);
164         }
165         catch (DataSetException e)
166         {
167             throw new TorqueException(e);
168         }
169     }
170 
171 
172   
173     /***
174      * Method to do inserts.
175      *
176      * @param criteria object used to create the INSERT statement.
177      * @throws TorqueException Any exceptions caught during processing will be
178      *         rethrown wrapped into a TorqueException.
179      */
180     public static ObjectKey doInsert(Criteria criteria)
181         throws TorqueException
182     {
183         return BaseTurbineRolePermissionPeer
184             .doInsert(criteria, (Connection) null);
185     }
186 
187     /***
188      * Method to do inserts.  This method is to be used during a transaction,
189      * otherwise use the doInsert(Criteria) method.  It will take care of
190      * the connection details internally.
191      *
192      * @param criteria object used to create the INSERT statement.
193      * @param con the connection to use
194      * @throws TorqueException Any exceptions caught during processing will be
195      *         rethrown wrapped into a TorqueException.
196      */
197     public static ObjectKey doInsert(Criteria criteria, Connection con)
198         throws TorqueException
199     {
200         correctBooleans(criteria);
201 
202         setDbName(criteria);
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      * changes the boolean values in the criteria to the appropriate type,
230      * whenever a booleanchar or booleanint column is involved.
231      * This enables the user to create criteria using Boolean values
232      * for booleanchar or booleanint columns
233      * @param criteria the criteria in which the boolean values should be corrected
234      */
235     public static void correctBooleans(Criteria criteria)
236     {
237                     }
238 
239     /***
240      * Create a new object of type cls from a resultset row starting
241      * from a specified offset.  This is done so that you can select
242      * other rows than just those needed for this object.  You may
243      * for example want to create two objects from the same row.
244      *
245      * @throws TorqueException Any exceptions caught during processing will be
246      *         rethrown wrapped into a TorqueException.
247      */
248     public static TurbineRolePermission row2Object(Record row,
249                                              int offset,
250                                              Class cls)
251         throws TorqueException
252     {
253         try
254         {
255             TurbineRolePermission obj = (TurbineRolePermission) cls.newInstance();
256             TurbineRolePermissionPeer.populateObject(row, offset, obj);
257                   obj.setModified(false);
258               obj.setNew(false);
259 
260             return obj;
261         }
262         catch (InstantiationException e)
263         {
264             throw new TorqueException(e);
265         }
266         catch (IllegalAccessException e)
267         {
268             throw new TorqueException(e);
269         }
270     }
271 
272     /***
273      * Populates an object from a resultset row starting
274      * from a specified offset.  This is done so that you can select
275      * other rows than just those needed for this object.  You may
276      * for example want to create two objects from the same row.
277      *
278      * @throws TorqueException Any exceptions caught during processing will be
279      *         rethrown wrapped into a TorqueException.
280      */
281     public static void populateObject(Record row,
282                                       int offset,
283                                       TurbineRolePermission obj)
284         throws TorqueException
285     {
286         try
287         {
288                 obj.setRoleId(row.getValue(offset + 0).asInt());
289                   obj.setPermissionId(row.getValue(offset + 1).asInt());
290               }
291         catch (DataSetException e)
292         {
293             throw new TorqueException(e);
294         }
295     }
296 
297     /***
298      * Method to do selects.
299      *
300      * @param criteria object used to create the SELECT statement.
301      * @return List of selected Objects
302      * @throws TorqueException Any exceptions caught during processing will be
303      *         rethrown wrapped into a TorqueException.
304      */
305     public static List doSelect(Criteria criteria) throws TorqueException
306     {
307         return populateObjects(doSelectVillageRecords(criteria));
308     }
309 
310     /***
311      * Method to do selects within a transaction.
312      *
313      * @param criteria object used to create the SELECT statement.
314      * @param con the connection to use
315      * @return List of selected Objects
316      * @throws TorqueException Any exceptions caught during processing will be
317      *         rethrown wrapped into a TorqueException.
318      */
319     public static List doSelect(Criteria criteria, Connection con)
320         throws TorqueException
321     {
322         return populateObjects(doSelectVillageRecords(criteria, con));
323     }
324 
325     /***
326      * Grabs the raw Village records to be formed into objects.
327      * This method handles connections internally.  The Record objects
328      * returned by this method should be considered readonly.  Do not
329      * alter the data and call save(), your results may vary, but are
330      * certainly likely to result in hard to track MT bugs.
331      *
332      * @throws TorqueException Any exceptions caught during processing will be
333      *         rethrown wrapped into a TorqueException.
334      */
335     public static List doSelectVillageRecords(Criteria criteria)
336         throws TorqueException
337     {
338         return BaseTurbineRolePermissionPeer
339             .doSelectVillageRecords(criteria, (Connection) null);
340     }
341 
342     /***
343      * Grabs the raw Village records to be formed into objects.
344      * This method should be used for transactions
345      *
346      * @param criteria object used to create the SELECT statement.
347      * @param con the connection to use
348      * @throws TorqueException Any exceptions caught during processing will be
349      *         rethrown wrapped into a TorqueException.
350      */
351     public static List doSelectVillageRecords(Criteria criteria, Connection con)
352         throws TorqueException
353     {
354         if (criteria.getSelectColumns().size() == 0)
355         {
356             addSelectColumns(criteria);
357         }
358         correctBooleans(criteria);
359 
360         setDbName(criteria);
361 
362         // BasePeer returns a List of Value (Village) arrays.  The array
363         // order follows the order columns were placed in the Select clause.
364         if (con == null)
365         {
366             return BasePeer.doSelect(criteria);
367         }
368         else
369         {
370             return BasePeer.doSelect(criteria, con);
371         }
372     }
373 
374     /***
375      * The returned List will contain objects of the default type or
376      * objects that inherit from the default.
377      *
378      * @throws TorqueException Any exceptions caught during processing will be
379      *         rethrown wrapped into a TorqueException.
380      */
381     public static List populateObjects(List records)
382         throws TorqueException
383     {
384         List results = new ArrayList(records.size());
385 
386         // populate the object(s)
387         for (int i = 0; i < records.size(); i++)
388         {
389             Record row = (Record) records.get(i);
390               results.add(TurbineRolePermissionPeer.row2Object(row, 1,
391                 TurbineRolePermissionPeer.getOMClass()));
392           }
393         return results;
394     }
395  
396 
397     /***
398      * The class that the Peer will make instances of.
399      * If the BO is abstract then you must implement this method
400      * in the BO.
401      *
402      * @throws TorqueException Any exceptions caught during processing will be
403      *         rethrown wrapped into a TorqueException.
404      */
405     public static Class getOMClass()
406         throws TorqueException
407     {
408         return CLASS_DEFAULT;
409     }
410 
411     /***
412      * Method to do updates.
413      *
414      * @param criteria object containing data that is used to create the UPDATE
415      *        statement.
416      * @throws TorqueException Any exceptions caught during processing will be
417      *         rethrown wrapped into a TorqueException.
418      */
419     public static void doUpdate(Criteria criteria) throws TorqueException
420     {
421          BaseTurbineRolePermissionPeer
422             .doUpdate(criteria, (Connection) null);
423     }
424 
425     /***
426      * Method to do updates.  This method is to be used during a transaction,
427      * otherwise use the doUpdate(Criteria) method.  It will take care of
428      * the connection details internally.
429      *
430      * @param criteria object containing data that is used to create the UPDATE
431      *        statement.
432      * @param con the connection to use
433      * @throws TorqueException Any exceptions caught during processing will be
434      *         rethrown wrapped into a TorqueException.
435      */
436     public static void doUpdate(Criteria criteria, Connection con)
437         throws TorqueException
438     {
439         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
440         correctBooleans(criteria);
441 
442   
443              selectCriteria.put(ROLE_ID, criteria.remove(ROLE_ID));
444       
445              selectCriteria.put(PERMISSION_ID, criteria.remove(PERMISSION_ID));
446       
447         setDbName(criteria);
448 
449         if (con == null)
450         {
451             BasePeer.doUpdate(selectCriteria, criteria);
452         }
453         else
454         {
455             BasePeer.doUpdate(selectCriteria, criteria, con);
456         }
457     }
458 
459     /***
460      * Method to do deletes.
461      *
462      * @param criteria object containing data that is used DELETE from database.
463      * @throws TorqueException Any exceptions caught during processing will be
464      *         rethrown wrapped into a TorqueException.
465      */
466      public static void doDelete(Criteria criteria) throws TorqueException
467      {
468          TurbineRolePermissionPeer
469             .doDelete(criteria, (Connection) null);
470      }
471 
472     /***
473      * Method to do deletes.  This method is to be used during a transaction,
474      * otherwise use the doDelete(Criteria) method.  It will take care of
475      * the connection details internally.
476      *
477      * @param criteria object containing data that is used DELETE from database.
478      * @param con the connection to use
479      * @throws TorqueException Any exceptions caught during processing will be
480      *         rethrown wrapped into a TorqueException.
481      */
482      public static void doDelete(Criteria criteria, Connection con)
483         throws TorqueException
484      {
485         correctBooleans(criteria);
486 
487         setDbName(criteria);
488 
489         if (con == null)
490         {
491             BasePeer.doDelete(criteria);
492         }
493         else
494         {
495             BasePeer.doDelete(criteria, con);
496         }
497      }
498 
499     /***
500      * Method to do selects
501      *
502      * @throws TorqueException Any exceptions caught during processing will be
503      *         rethrown wrapped into a TorqueException.
504      */
505     public static List doSelect(TurbineRolePermission obj) throws TorqueException
506     {
507         return doSelect(buildSelectCriteria(obj));
508     }
509 
510     /***
511      * Method to do inserts
512      *
513      * @throws TorqueException Any exceptions caught during processing will be
514      *         rethrown wrapped into a TorqueException.
515      */
516     public static void doInsert(TurbineRolePermission obj) throws TorqueException
517     {
518           doInsert(buildCriteria(obj));
519           obj.setNew(false);
520         obj.setModified(false);
521     }
522 
523     /***
524      * @param obj the data object to update in the database.
525      * @throws TorqueException Any exceptions caught during processing will be
526      *         rethrown wrapped into a TorqueException.
527      */
528     public static void doUpdate(TurbineRolePermission obj) throws TorqueException
529     {
530         doUpdate(buildCriteria(obj));
531         obj.setModified(false);
532     }
533 
534     /***
535      * @param obj the data object to delete in the database.
536      * @throws TorqueException Any exceptions caught during processing will be
537      *         rethrown wrapped into a TorqueException.
538      */
539     public static void doDelete(TurbineRolePermission obj) throws TorqueException
540     {
541         doDelete(buildSelectCriteria(obj));
542     }
543 
544     /***
545      * Method to do inserts.  This method is to be used during a transaction,
546      * otherwise use the doInsert(TurbineRolePermission) method.  It will take
547      * care of the connection details internally.
548      *
549      * @param obj the data object to insert into the database.
550      * @param con the connection to use
551      * @throws TorqueException Any exceptions caught during processing will be
552      *         rethrown wrapped into a TorqueException.
553      */
554     public static void doInsert(TurbineRolePermission obj, Connection con)
555         throws TorqueException
556     {
557           doInsert(buildCriteria(obj), con);
558           obj.setNew(false);
559         obj.setModified(false);
560     }
561 
562     /***
563      * Method to do update.  This method is to be used during a transaction,
564      * otherwise use the doUpdate(TurbineRolePermission) method.  It will take
565      * care of the connection details internally.
566      *
567      * @param obj the data object to update in the database.
568      * @param con the connection to use
569      * @throws TorqueException Any exceptions caught during processing will be
570      *         rethrown wrapped into a TorqueException.
571      */
572     public static void doUpdate(TurbineRolePermission obj, Connection con)
573         throws TorqueException
574     {
575         doUpdate(buildCriteria(obj), con);
576         obj.setModified(false);
577     }
578 
579     /***
580      * Method to delete.  This method is to be used during a transaction,
581      * otherwise use the doDelete(TurbineRolePermission) method.  It will take
582      * care of the connection details internally.
583      *
584      * @param obj the data object to delete in the database.
585      * @param con the connection to use
586      * @throws TorqueException Any exceptions caught during processing will be
587      *         rethrown wrapped into a TorqueException.
588      */
589     public static void doDelete(TurbineRolePermission obj, Connection con)
590         throws TorqueException
591     {
592         doDelete(buildSelectCriteria(obj), con);
593     }
594 
595     /***
596      * Method to do deletes.
597      *
598      * @param pk ObjectKey that is used DELETE from database.
599      * @throws TorqueException Any exceptions caught during processing will be
600      *         rethrown wrapped into a TorqueException.
601      */
602     public static void doDelete(ObjectKey pk) throws TorqueException
603     {
604         BaseTurbineRolePermissionPeer
605            .doDelete(pk, (Connection) null);
606     }
607 
608     /***
609      * Method to delete.  This method is to be used during a transaction,
610      * otherwise use the doDelete(ObjectKey) method.  It will take
611      * care of the connection details internally.
612      *
613      * @param pk the primary key for the object to delete in the database.
614      * @param con the connection to use
615      * @throws TorqueException Any exceptions caught during processing will be
616      *         rethrown wrapped into a TorqueException.
617      */
618     public static void doDelete(ObjectKey pk, Connection con)
619         throws TorqueException
620     {
621         doDelete(buildCriteria(pk), con);
622     }
623 
624     /*** Build a Criteria object from an ObjectKey */
625     public static Criteria buildCriteria( ObjectKey pk )
626     {
627         Criteria criteria = new Criteria();
628           SimpleKey[] keys = (SimpleKey[])pk.getValue();
629                     criteria.add(ROLE_ID, keys[0]);
630                       criteria.add(PERMISSION_ID, keys[1]);
631                     return criteria;
632      }
633 
634     /*** Build a Criteria object from the data object for this peer */
635     public static Criteria buildCriteria( TurbineRolePermission obj )
636     {
637         Criteria criteria = new Criteria(DATABASE_NAME);
638               criteria.add(ROLE_ID, obj.getRoleId());
639               criteria.add(PERMISSION_ID, obj.getPermissionId());
640           return criteria;
641     }
642 
643     /*** Build a Criteria object from the data object for this peer, skipping all binary columns */
644     public static Criteria buildSelectCriteria( TurbineRolePermission obj )
645     {
646         Criteria criteria = new Criteria(DATABASE_NAME);
647                       criteria.add(ROLE_ID, obj.getRoleId());
648                               criteria.add(PERMISSION_ID, obj.getPermissionId());
649                   return criteria;
650     }
651  
652     
653     
654     /***
655      * Retrieve a single object by pk
656      *
657      * @param pk the primary key
658      * @throws TorqueException Any exceptions caught during processing will be
659      *         rethrown wrapped into a TorqueException.
660      * @throws NoRowsException Primary key was not found in database.
661      * @throws TooManyRowsException Primary key was not found in database.
662      */
663     public static TurbineRolePermission retrieveByPK(ObjectKey pk)
664         throws TorqueException, NoRowsException, TooManyRowsException
665     {
666         Connection db = null;
667         TurbineRolePermission retVal = null;
668         try
669         {
670             db = Torque.getConnection(DATABASE_NAME);
671             retVal = retrieveByPK(pk, db);
672         }
673         finally
674         {
675             Torque.closeConnection(db);
676         }
677         return retVal;
678     }
679 
680     /***
681      * Retrieve a single object by pk
682      *
683      * @param pk the primary key
684      * @param con the connection to use
685      * @throws TorqueException Any exceptions caught during processing will be
686      *         rethrown wrapped into a TorqueException.
687      * @throws NoRowsException Primary key was not found in database.
688      * @throws TooManyRowsException Primary key was not found in database.
689      */
690     public static TurbineRolePermission retrieveByPK(ObjectKey pk, Connection con)
691         throws TorqueException, NoRowsException, TooManyRowsException
692     {
693         Criteria criteria = buildCriteria(pk);
694         List v = doSelect(criteria, con);
695         if (v.size() == 0)
696         {
697             throw new NoRowsException("Failed to select a row.");
698         }
699         else if (v.size() > 1)
700         {
701             throw new TooManyRowsException("Failed to select only one row.");
702         }
703         else
704         {
705             return (TurbineRolePermission)v.get(0);
706         }
707     }
708 
709     /***
710      * Retrieve a multiple objects by pk
711      *
712      * @param pks List of primary keys
713      * @throws TorqueException Any exceptions caught during processing will be
714      *         rethrown wrapped into a TorqueException.
715      */
716     public static List retrieveByPKs(List pks)
717         throws TorqueException
718     {
719         Connection db = null;
720         List retVal = null;
721         try
722         {
723            db = Torque.getConnection(DATABASE_NAME);
724            retVal = retrieveByPKs(pks, db);
725         }
726         finally
727         {
728             Torque.closeConnection(db);
729         }
730         return retVal;
731     }
732 
733     /***
734      * Retrieve a multiple objects by pk
735      *
736      * @param pks List of primary keys
737      * @param dbcon the connection to use
738      * @throws TorqueException Any exceptions caught during processing will be
739      *         rethrown wrapped into a TorqueException.
740      */
741     public static List retrieveByPKs( List pks, Connection dbcon )
742         throws TorqueException
743     {
744         List objs = null;
745         if (pks == null || pks.size() == 0)
746         {
747             objs = new LinkedList();
748         }
749         else
750         {
751             Criteria criteria = new Criteria();
752               Iterator iter = pks.iterator();
753             while (iter.hasNext())
754             {
755                 ObjectKey pk = (ObjectKey)iter.next();
756                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
757                             Criteria.Criterion c0 = criteria.getNewCriterion(
758                         ROLE_ID, keys[0], Criteria.EQUAL);
759                                     Criteria.Criterion c1 = criteria.getNewCriterion(
760                         PERMISSION_ID, keys[1], Criteria.EQUAL);
761                                     c0.and(c1);
762                           criteria.or(c0);
763             }
764           objs = doSelect(criteria, dbcon);
765         }
766         return objs;
767     }
768 
769  
770     /***
771      * retrieve object using using pk values.
772      *
773        * @param role_id int
774        * @param permission_id int
775        */
776     public static TurbineRolePermission retrieveByPK(
777        int role_id
778           , int permission_id
779               ) throws TorqueException
780     {
781         Connection db = null;
782         TurbineRolePermission retVal = null;
783         try
784         {
785            db = Torque.getConnection(DATABASE_NAME);
786            retVal = retrieveByPK(
787          role_id
788           , permission_id
789                      , db);
790         }
791         finally
792         {
793             Torque.closeConnection(db);
794         }
795         return retVal;
796     }
797 
798       /***
799      * retrieve object using using pk values.
800      *
801        * @param role_id int
802        * @param permission_id int
803        * @param con Connection
804      */
805     public static TurbineRolePermission retrieveByPK(
806        int role_id
807           , int permission_id
808              ,Connection con) throws TorqueException
809     {
810 
811         Criteria criteria = new Criteria(5);
812           criteria.add(ROLE_ID, role_id);
813           criteria.add(PERMISSION_ID, permission_id);
814           List v = doSelect(criteria, con);
815         if (v.size() == 1)
816         {
817             return (TurbineRolePermission) v.get(0);
818         }
819         else
820         {
821             throw new TorqueException("Failed to select one and only one row.");
822         }
823     }
824 
825 
826 
827             
828                                               
829                 
830                 
831 
832     /***
833      * selects a collection of TurbineRolePermission objects pre-filled with their
834      * TurbineRole objects.
835      *
836      * This method is protected by default in order to keep the public
837      * api reasonable.  You can provide public methods for those you
838      * actually need in TurbineRolePermissionPeer.
839      *
840      * @throws TorqueException Any exceptions caught during processing will be
841      *         rethrown wrapped into a TorqueException.
842      */
843     protected static List doSelectJoinTurbineRole(Criteria criteria)
844         throws TorqueException
845     {
846         return doSelectJoinTurbineRole(criteria, null);
847     }
848 
849     /***
850      * selects a collection of TurbineRolePermission objects pre-filled with their
851      * TurbineRole objects.
852      *
853      * This method is protected by default in order to keep the public
854      * api reasonable.  You can provide public methods for those you
855      * actually need in TurbineRolePermissionPeer.
856      *
857      * @throws TorqueException Any exceptions caught during processing will be
858      *         rethrown wrapped into a TorqueException.
859      */
860     protected static List doSelectJoinTurbineRole(Criteria criteria, Connection conn)
861         throws TorqueException
862     {
863         setDbName(criteria);
864 
865         TurbineRolePermissionPeer.addSelectColumns(criteria);
866         int offset = numColumns + 1;
867         TurbineRolePeer.addSelectColumns(criteria);
868 
869 
870                         criteria.addJoin(TurbineRolePermissionPeer.ROLE_ID,
871             TurbineRolePeer.ROLE_ID);
872         
873         correctBooleans(criteria);
874 
875         List rows;
876         if (conn == null)
877         {
878             rows = BasePeer.doSelect(criteria);
879         }
880         else
881         {
882             rows = BasePeer.doSelect(criteria,conn);
883         }
884 
885         List results = new ArrayList();
886 
887         for (int i = 0; i < rows.size(); i++)
888         {
889             Record row = (Record) rows.get(i);
890 
891                             Class omClass = TurbineRolePermissionPeer.getOMClass();
892                     TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer
893                 .row2Object(row, 1, omClass);
894                      omClass = TurbineRolePeer.getOMClass();
895                     TurbineRole obj2 = (TurbineRole)TurbineRolePeer
896                 .row2Object(row, offset, omClass);
897 
898             boolean newObject = true;
899             for (int j = 0; j < results.size(); j++)
900             {
901                 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j);
902                 TurbineRole temp_obj2 = (TurbineRole)temp_obj1.getTurbineRole();
903                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
904                 {
905                     newObject = false;
906                               temp_obj2.addTurbineRolePermission(obj1);
907                               break;
908                 }
909             }
910                       if (newObject)
911             {
912                 obj2.initTurbineRolePermissions();
913                 obj2.addTurbineRolePermission(obj1);
914             }
915                       results.add(obj1);
916         }
917         return results;
918     }
919                                                             
920                 
921                 
922 
923     /***
924      * selects a collection of TurbineRolePermission objects pre-filled with their
925      * TurbinePermission objects.
926      *
927      * This method is protected by default in order to keep the public
928      * api reasonable.  You can provide public methods for those you
929      * actually need in TurbineRolePermissionPeer.
930      *
931      * @throws TorqueException Any exceptions caught during processing will be
932      *         rethrown wrapped into a TorqueException.
933      */
934     protected static List doSelectJoinTurbinePermission(Criteria criteria)
935         throws TorqueException
936     {
937         return doSelectJoinTurbinePermission(criteria, null);
938     }
939 
940     /***
941      * selects a collection of TurbineRolePermission objects pre-filled with their
942      * TurbinePermission objects.
943      *
944      * This method is protected by default in order to keep the public
945      * api reasonable.  You can provide public methods for those you
946      * actually need in TurbineRolePermissionPeer.
947      *
948      * @throws TorqueException Any exceptions caught during processing will be
949      *         rethrown wrapped into a TorqueException.
950      */
951     protected static List doSelectJoinTurbinePermission(Criteria criteria, Connection conn)
952         throws TorqueException
953     {
954         setDbName(criteria);
955 
956         TurbineRolePermissionPeer.addSelectColumns(criteria);
957         int offset = numColumns + 1;
958         TurbinePermissionPeer.addSelectColumns(criteria);
959 
960 
961                         criteria.addJoin(TurbineRolePermissionPeer.PERMISSION_ID,
962             TurbinePermissionPeer.PERMISSION_ID);
963         
964         correctBooleans(criteria);
965 
966         List rows;
967         if (conn == null)
968         {
969             rows = BasePeer.doSelect(criteria);
970         }
971         else
972         {
973             rows = BasePeer.doSelect(criteria,conn);
974         }
975 
976         List results = new ArrayList();
977 
978         for (int i = 0; i < rows.size(); i++)
979         {
980             Record row = (Record) rows.get(i);
981 
982                             Class omClass = TurbineRolePermissionPeer.getOMClass();
983                     TurbineRolePermission obj1 = (TurbineRolePermission) TurbineRolePermissionPeer
984                 .row2Object(row, 1, omClass);
985                      omClass = TurbinePermissionPeer.getOMClass();
986                     TurbinePermission obj2 = (TurbinePermission)TurbinePermissionPeer
987                 .row2Object(row, offset, omClass);
988 
989             boolean newObject = true;
990             for (int j = 0; j < results.size(); j++)
991             {
992                 TurbineRolePermission temp_obj1 = (TurbineRolePermission)results.get(j);
993                 TurbinePermission temp_obj2 = (TurbinePermission)temp_obj1.getTurbinePermission();
994                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
995                 {
996                     newObject = false;
997                               temp_obj2.addTurbineRolePermission(obj1);
998                               break;
999                 }
1000             }
1001                       if (newObject)
1002             {
1003                 obj2.initTurbineRolePermissions();
1004                 obj2.addTurbineRolePermission(obj1);
1005             }
1006                       results.add(obj1);
1007         }
1008         return results;
1009     }
1010                     
1011   
1012     
1013   
1014       /***
1015      * Returns the TableMap related to this peer.  This method is not
1016      * needed for general use but a specific application could have a need.
1017      *
1018      * @throws TorqueException Any exceptions caught during processing will be
1019      *         rethrown wrapped into a TorqueException.
1020      */
1021     protected static TableMap getTableMap()
1022         throws TorqueException
1023     {
1024         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
1025     }
1026    
1027     private static void setDbName(Criteria crit)
1028     {
1029         // Set the correct dbName if it has not been overridden
1030         // crit.getDbName will return the same object if not set to
1031         // another value so == check is okay and faster
1032         if (crit.getDbName() == Torque.getDefaultDB())
1033         {
1034             crit.setDbName(DATABASE_NAME);
1035         }
1036     }
1037 }