KickJava   Java API By Example, From Geeks To Geeks.

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


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 public abstract class BaseTurbineRolePeer
37     extends BasePeer
38 {
39
40     /** the default database name for this class */
41     public static final String JavaDoc DATABASE_NAME = "scarab";
42
43      /** the table name for this class */
44     public static final String JavaDoc TABLE_NAME = "TURBINE_ROLE";
45
46     /**
47      * @return the map builder for this peer
48      * @throws TorqueException Any exceptions caught during processing will be
49      * rethrown wrapped into a TorqueException.
50      */

51     public static MapBuilder getMapBuilder()
52         throws TorqueException
53     {
54         return getMapBuilder(TurbineRoleMapBuilder.CLASS_NAME);
55     }
56
57       /** the column name for the ROLE_ID field */
58     public static final String JavaDoc ROLE_ID;
59       /** the column name for the ROLE_NAME field */
60     public static final String JavaDoc ROLE_NAME;
61   
62     static
63     {
64           ROLE_ID = "TURBINE_ROLE.ROLE_ID";
65           ROLE_NAME = "TURBINE_ROLE.ROLE_NAME";
66           if (Torque.isInit())
67         {
68             try
69             {
70                 getMapBuilder(TurbineRoleMapBuilder.CLASS_NAME);
71             }
72             catch (Exception JavaDoc e)
73             {
74                 log.error("Could not initialize Peer", e);
75             }
76         }
77         else
78         {
79             Torque.registerMapBuilder(TurbineRoleMapBuilder.CLASS_NAME);
80         }
81     }
82  
83     /** number of columns for this peer */
84     public static final int numColumns = 2;
85
86     /** A class that can be returned by this peer. */
87     protected static final String JavaDoc CLASSNAME_DEFAULT =
88         "org.apache.fulcrum.security.impl.db.entity.TurbineRole";
89
90     /** A class that can be returned by this peer. */
91     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
92
93     /**
94      * Class object initialization method.
95      *
96      * @param className name of the class to initialize
97      * @return the initialized class
98      */

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

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

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

191     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
192         throws TorqueException
193     {
194               
195         // Set the correct dbName if it has not been overridden
196
// criteria.getDbName will return the same object if not set to
197
// another value so == check is okay and faster
198
if (criteria.getDbName() == Torque.getDefaultDB())
199         {
200             criteria.setDbName(DATABASE_NAME);
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(ROLE_ID);
223           criteria.addSelectColumn(ROLE_NAME);
224       }
225
226     /**
227      * Create a new object of type cls from a resultset row starting
228      * from a specified offset. This is done so that you can select
229      * other rows than just those needed for this object. You may
230      * for example want to create two objects from the same row.
231      *
232      * @throws TorqueException Any exceptions caught during processing will be
233      * rethrown wrapped into a TorqueException.
234      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

647     public static TurbineRole retrieveByPK(Integer JavaDoc pk)
648         throws TorqueException, NoRowsException, TooManyRowsException
649     {
650         return retrieveByPK(SimpleKey.keyFor(pk));
651     }
652   
653     /**
654      * Retrieve a single object by pk
655      *
656      * @param pk the primary key
657      * @throws TorqueException Any exceptions caught during processing will be
658      * rethrown wrapped into a TorqueException.
659      * @throws NoRowsException Primary key was not found in database.
660      * @throws TooManyRowsException Primary key was not found in database.
661      */

662     public static TurbineRole retrieveByPK(ObjectKey pk)
663         throws TorqueException, NoRowsException, TooManyRowsException
664     {
665         Connection JavaDoc db = null;
666         TurbineRole retVal = null;
667         try
668         {
669             db = Torque.getConnection(DATABASE_NAME);
670             retVal = retrieveByPK(pk, db);
671         }
672         finally
673         {
674             Torque.closeConnection(db);
675         }
676         return(retVal);
677     }
678
679     /**
680      * Retrieve a single object by pk
681      *
682      * @param pk the primary key
683      * @param con the connection to use
684      * @throws TorqueException Any exceptions caught during processing will be
685      * rethrown wrapped into a TorqueException.
686      * @throws NoRowsException Primary key was not found in database.
687      * @throws TooManyRowsException Primary key was not found in database.
688      */

689     public static TurbineRole retrieveByPK(ObjectKey pk, Connection JavaDoc con)
690         throws TorqueException, NoRowsException, TooManyRowsException
691     {
692         Criteria criteria = buildCriteria(pk);
693         List JavaDoc v = doSelect(criteria, con);
694         if (v.size() == 0)
695         {
696             throw new NoRowsException("Failed to select a row.");
697         }
698         else if (v.size() > 1)
699         {
700             throw new TooManyRowsException("Failed to select only one row.");
701         }
702         else
703         {
704             return (TurbineRole)v.get(0);
705         }
706     }
707
708     /**
709      * Retrieve a multiple objects by pk
710      *
711      * @param pks List of primary keys
712      * @throws TorqueException Any exceptions caught during processing will be
713      * rethrown wrapped into a TorqueException.
714      */

715     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
716         throws TorqueException
717     {
718         Connection JavaDoc db = null;
719         List JavaDoc retVal = null;
720         try
721         {
722            db = Torque.getConnection(DATABASE_NAME);
723            retVal = retrieveByPKs(pks, db);
724         }
725         finally
726         {
727             Torque.closeConnection(db);
728         }
729         return(retVal);
730     }
731
732     /**
733      * Retrieve a multiple objects by pk
734      *
735      * @param pks List of primary keys
736      * @param dbcon the connection to use
737      * @throws TorqueException Any exceptions caught during processing will be
738      * rethrown wrapped into a TorqueException.
739      */

740     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
741         throws TorqueException
742     {
743         List JavaDoc objs = null;
744         if (pks == null || pks.size() == 0)
745         {
746             objs = new LinkedList JavaDoc();
747         }
748         else
749         {
750             Criteria criteria = new Criteria();
751               criteria.addIn( ROLE_ID, pks );
752           objs = doSelect(criteria, dbcon);
753         }
754         return objs;
755     }
756
757  
758
759
760
761         
762   
763   
764     
765   
766       /**
767      * Returns the TableMap related to this peer. This method is not
768      * needed for general use but a specific application could have a need.
769      *
770      * @throws TorqueException Any exceptions caught during processing will be
771      * rethrown wrapped into a TorqueException.
772      */

773     protected static TableMap getTableMap()
774         throws TorqueException
775     {
776         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
777     }
778    }
779
Popular Tags