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.TorqueRuntimeException;
17  import org.apache.torque.map.MapBuilder;
18  import org.apache.torque.map.TableMap;
19  import org.apache.torque.om.DateKey;
20  import org.apache.torque.om.NumberKey;
21  import org.apache.torque.om.StringKey;
22  import org.apache.torque.om.ObjectKey;
23  import org.apache.torque.om.SimpleKey;
24  import org.apache.torque.util.BasePeer;
25  import org.apache.torque.util.Criteria;
26  
27  import com.workingdogs.village.DataSetException;
28  import com.workingdogs.village.QueryDataSet;
29  import com.workingdogs.village.Record;
30  
31  // Local classes
32  import org.apache.turbine.services.security.torque.om.map.*;
33  
34  
35  
36  
37  /**
38   * This class was autogenerated by Torque on:
39   *
40   * [Thu Jun 23 17:25:46 CEST 2011]
41   *
42   */
43  public abstract class BaseTurbineUserPeer
44      extends BasePeer
45  {
46      /** Serial version */
47      private static final long serialVersionUID = 1308842746584L;
48  
49  
50      /** the default database name for this class */
51      public static final String DATABASE_NAME;
52  
53       /** the table name for this class */
54      public static final String TABLE_NAME;
55  
56      /**
57       * @return the map builder for this peer
58       * @throws TorqueException Any exceptions caught during processing will be
59       *         rethrown wrapped into a TorqueException.
60       * @deprecated Torque.getMapBuilder(TurbineUserMapBuilder.CLASS_NAME) instead
61       */
62      public static MapBuilder getMapBuilder()
63          throws TorqueException
64      {
65          return Torque.getMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
66      }
67  
68      /** the column name for the USER_ID field */
69      public static final String USER_ID;
70      /** the column name for the LOGIN_NAME field */
71      public static final String LOGIN_NAME;
72      /** the column name for the PASSWORD_VALUE field */
73      public static final String PASSWORD_VALUE;
74      /** the column name for the FIRST_NAME field */
75      public static final String FIRST_NAME;
76      /** the column name for the LAST_NAME field */
77      public static final String LAST_NAME;
78      /** the column name for the EMAIL field */
79      public static final String EMAIL;
80      /** the column name for the CONFIRM_VALUE field */
81      public static final String CONFIRM_VALUE;
82      /** the column name for the MODIFIED field */
83      public static final String MODIFIED;
84      /** the column name for the CREATED field */
85      public static final String CREATED;
86      /** the column name for the LAST_LOGIN field */
87      public static final String LAST_LOGIN;
88      /** the column name for the OBJECTDATA field */
89      public static final String OBJECTDATA;
90  
91      static
92      {
93          DATABASE_NAME = "default";
94          TABLE_NAME = "TURBINE_USER";
95  
96          USER_ID = "TURBINE_USER.USER_ID";
97          LOGIN_NAME = "TURBINE_USER.LOGIN_NAME";
98          PASSWORD_VALUE = "TURBINE_USER.PASSWORD_VALUE";
99          FIRST_NAME = "TURBINE_USER.FIRST_NAME";
100         LAST_NAME = "TURBINE_USER.LAST_NAME";
101         EMAIL = "TURBINE_USER.EMAIL";
102         CONFIRM_VALUE = "TURBINE_USER.CONFIRM_VALUE";
103         MODIFIED = "TURBINE_USER.MODIFIED";
104         CREATED = "TURBINE_USER.CREATED";
105         LAST_LOGIN = "TURBINE_USER.LAST_LOGIN";
106         OBJECTDATA = "TURBINE_USER.OBJECTDATA";
107         if (Torque.isInit())
108         {
109             try
110             {
111                 Torque.getMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
112             }
113             catch (TorqueException e)
114             {
115                 log.error("Could not initialize Peer", e);
116                 throw new TorqueRuntimeException(e);
117             }
118         }
119         else
120         {
121             Torque.registerMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
122         }
123     }
124  
125     /** number of columns for this peer */
126     public static final int numColumns =  11;
127 
128     /** A class that can be returned by this peer. */
129     protected static final String CLASSNAME_DEFAULT =
130         "org.apache.turbine.services.security.torque.om.TurbineUser";
131 
132     /** A class that can be returned by this peer. */
133     protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
134 
135     /**
136      * Class object initialization method.
137      *
138      * @param className name of the class to initialize
139      * @return the initialized class
140      */
141     private static Class initClass(String className)
142     {
143         Class c = null;
144         try
145         {
146             c = Class.forName(className);
147         }
148         catch (Throwable t)
149         {
150             log.error("A FATAL ERROR has occurred which should not "
151                 + "have happened under any circumstance.  Please notify "
152                 + "the Torque developers <torque-dev@db.apache.org> "
153                 + "and give as many details as possible (including the error "
154                 + "stack trace).", t);
155 
156             // Error objects should always be propagated.
157             if (t instanceof Error)
158             {
159                 throw (Error) t.fillInStackTrace();
160             }
161         }
162         return c;
163     }
164 
165     /**
166      * Get the list of objects for a ResultSet.  Please not that your
167      * resultset MUST return columns in the right order.  You can use
168      * getFieldNames() in BaseObject to get the correct sequence.
169      *
170      * @param results the ResultSet
171      * @return the list of objects
172      * @throws TorqueException Any exceptions caught during processing will be
173      *         rethrown wrapped into a TorqueException.
174      */
175     public static List<TurbineUser> resultSet2Objects(java.sql.ResultSet results)
176             throws TorqueException
177     {
178         try
179         {
180             QueryDataSet qds = null;
181             List<Record> rows = null;
182             try
183             {
184                 qds = new QueryDataSet(results);
185                 rows = getSelectResults(qds);
186             }
187             finally
188             {
189                 if (qds != null)
190                 {
191                     qds.close();
192                 }
193             }
194 
195             return populateObjects(rows);
196         }
197         catch (SQLException e)
198         {
199             throw new TorqueException(e);
200         }
201         catch (DataSetException e)
202         {
203             throw new TorqueException(e);
204         }
205     }
206 
207 
208 
209     /**
210      * Method to do inserts.
211      *
212      * @param criteria object used to create the INSERT statement.
213      * @throws TorqueException Any exceptions caught during processing will be
214      *         rethrown wrapped into a TorqueException.
215      */
216     public static ObjectKey doInsert(Criteria criteria)
217         throws TorqueException
218     {
219         return BaseTurbineUserPeer
220             .doInsert(criteria, (Connection) null);
221     }
222 
223     /**
224      * Method to do inserts.  This method is to be used during a transaction,
225      * otherwise use the doInsert(Criteria) method.  It will take care of
226      * the connection details internally.
227      *
228      * @param criteria object used to create the INSERT statement.
229      * @param con the connection to use
230      * @throws TorqueException Any exceptions caught during processing will be
231      *         rethrown wrapped into a TorqueException.
232      */
233     public static ObjectKey doInsert(Criteria criteria, Connection con)
234         throws TorqueException
235     {
236         correctBooleans(criteria);
237 
238         setDbName(criteria);
239 
240         if (con == null)
241         {
242             return BasePeer.doInsert(criteria);
243         }
244         else
245         {
246             return BasePeer.doInsert(criteria, con);
247         }
248     }
249 
250     /**
251      * Add all the columns needed to create a new object.
252      *
253      * @param criteria object containing the columns to add.
254      * @throws TorqueException Any exceptions caught during processing will be
255      *         rethrown wrapped into a TorqueException.
256      */
257     public static void addSelectColumns(Criteria criteria)
258             throws TorqueException
259     {
260         criteria.addSelectColumn(USER_ID);
261         criteria.addSelectColumn(LOGIN_NAME);
262         criteria.addSelectColumn(PASSWORD_VALUE);
263         criteria.addSelectColumn(FIRST_NAME);
264         criteria.addSelectColumn(LAST_NAME);
265         criteria.addSelectColumn(EMAIL);
266         criteria.addSelectColumn(CONFIRM_VALUE);
267         criteria.addSelectColumn(MODIFIED);
268         criteria.addSelectColumn(CREATED);
269         criteria.addSelectColumn(LAST_LOGIN);
270         criteria.addSelectColumn(OBJECTDATA);
271     }
272 
273     /**
274      * changes the boolean values in the criteria to the appropriate type,
275      * whenever a booleanchar or booleanint column is involved.
276      * This enables the user to create criteria using Boolean values
277      * for booleanchar or booleanint columns
278      * @param criteria the criteria in which the boolean values should be corrected
279      * @throws TorqueException if the database map for the criteria cannot be 
280                obtained.
281      */
282     public static void correctBooleans(Criteria criteria) throws TorqueException
283     {
284         correctBooleans(criteria, getTableMap());
285     }
286 
287     /**
288      * Create a new object of type cls from a resultset row starting
289      * from a specified offset.  This is done so that you can select
290      * other rows than just those needed for this object.  You may
291      * for example want to create two objects from the same row.
292      *
293      * @throws TorqueException Any exceptions caught during processing will be
294      *         rethrown wrapped into a TorqueException.
295      */
296     public static TurbineUser row2Object(Record row,
297                                              int offset,
298                                              Class cls)
299         throws TorqueException
300     {
301         try
302         {
303             TurbineUser obj = (TurbineUser) cls.newInstance();
304             TurbineUserPeer.populateObject(row, offset, obj);
305                 obj.setModified(false);
306             obj.setNew(false);
307 
308             return obj;
309         }
310         catch (InstantiationException e)
311         {
312             throw new TorqueException(e);
313         }
314         catch (IllegalAccessException e)
315         {
316             throw new TorqueException(e);
317         }
318     }
319 
320     /**
321      * Populates an object from a resultset row starting
322      * from a specified offset.  This is done so that you can select
323      * other rows than just those needed for this object.  You may
324      * for example want to create two objects from the same row.
325      *
326      * @throws TorqueException Any exceptions caught during processing will be
327      *         rethrown wrapped into a TorqueException.
328      */
329     public static void populateObject(Record row,
330                                       int offset,
331                                       TurbineUser obj)
332         throws TorqueException
333     {
334         try
335         {
336             obj.setUserId(row.getValue(offset + 0).asInt());
337             obj.setUserName(row.getValue(offset + 1).asString());
338             obj.setPassword(row.getValue(offset + 2).asString());
339             obj.setFirstName(row.getValue(offset + 3).asString());
340             obj.setLastName(row.getValue(offset + 4).asString());
341             obj.setEmail(row.getValue(offset + 5).asString());
342             obj.setConfirmed(row.getValue(offset + 6).asString());
343             obj.setModified(row.getValue(offset + 7).asUtilDate());
344             obj.setCreateDate(row.getValue(offset + 8).asUtilDate());
345             obj.setLastLogin(row.getValue(offset + 9).asUtilDate());
346             obj.setObjectdata(row.getValue(offset + 10).asBytes());
347         }
348         catch (DataSetException e)
349         {
350             throw new TorqueException(e);
351         }
352     }
353 
354     /**
355      * Method to do selects.
356      *
357      * @param criteria object used to create the SELECT statement.
358      * @return List of selected Objects
359      * @throws TorqueException Any exceptions caught during processing will be
360      *         rethrown wrapped into a TorqueException.
361      */
362     public static List<TurbineUser> doSelect(Criteria criteria) throws TorqueException
363     {
364         return populateObjects(doSelectVillageRecords(criteria));
365     }
366 
367     /**
368      * Method to do selects within a transaction.
369      *
370      * @param criteria object used to create the SELECT statement.
371      * @param con the connection to use
372      * @return List of selected Objects
373      * @throws TorqueException Any exceptions caught during processing will be
374      *         rethrown wrapped into a TorqueException.
375      */
376     public static List<TurbineUser> doSelect(Criteria criteria, Connection con)
377         throws TorqueException
378     {
379         return populateObjects(doSelectVillageRecords(criteria, con));
380     }
381 
382     /**
383      * Grabs the raw Village records to be formed into objects.
384      * This method handles connections internally.  The Record objects
385      * returned by this method should be considered readonly.  Do not
386      * alter the data and call save(), your results may vary, but are
387      * certainly likely to result in hard to track MT bugs.
388      *
389      * @throws TorqueException Any exceptions caught during processing will be
390      *         rethrown wrapped into a TorqueException.
391      */
392     public static List<Record> doSelectVillageRecords(Criteria criteria)
393         throws TorqueException
394     {
395         return BaseTurbineUserPeer
396             .doSelectVillageRecords(criteria, (Connection) null);
397     }
398 
399     /**
400      * Grabs the raw Village records to be formed into objects.
401      * This method should be used for transactions
402      *
403      * @param criteria object used to create the SELECT statement.
404      * @param con the connection to use
405      * @throws TorqueException Any exceptions caught during processing will be
406      *         rethrown wrapped into a TorqueException.
407      */
408     public static List<Record> doSelectVillageRecords(Criteria criteria, Connection con)
409         throws TorqueException
410     {
411         if (criteria.getSelectColumns().size() == 0)
412         {
413             addSelectColumns(criteria);
414         }
415         correctBooleans(criteria);
416 
417         setDbName(criteria);
418 
419         // BasePeer returns a List of Value (Village) arrays.  The array
420         // order follows the order columns were placed in the Select clause.
421         if (con == null)
422         {
423             return BasePeer.doSelect(criteria);
424         }
425         else
426         {
427             return BasePeer.doSelect(criteria, con);
428         }
429     }
430 
431     /**
432      * The returned List will contain objects of the default type or
433      * objects that inherit from the default.
434      *
435      * @throws TorqueException Any exceptions caught during processing will be
436      *         rethrown wrapped into a TorqueException.
437      */
438     public static List<TurbineUser> populateObjects(List<Record> records)
439         throws TorqueException
440     {
441         List<TurbineUser> results = new ArrayList<TurbineUser>(records.size());
442 
443         // populate the object(s)
444         for (int i = 0; i < records.size(); i++)
445         {
446             Record row =  records.get(i);
447             results.add(TurbineUserPeer.row2Object(row, 1,
448                 TurbineUserPeer.getOMClass()));
449         }
450         return results;
451     }
452  
453 
454     /**
455      * The class that the Peer will make instances of.
456      * If the BO is abstract then you must implement this method
457      * in the BO.
458      *
459      * @throws TorqueException Any exceptions caught during processing will be
460      *         rethrown wrapped into a TorqueException.
461      */
462     public static Class getOMClass()
463         throws TorqueException
464     {
465         return CLASS_DEFAULT;
466     }
467 
468     /**
469      * Method to do updates.
470      *
471      * @param criteria object containing data that is used to create the UPDATE
472      *        statement.
473      * @throws TorqueException Any exceptions caught during processing will be
474      *         rethrown wrapped into a TorqueException.
475      */
476     public static void doUpdate(Criteria criteria) throws TorqueException
477     {
478          BaseTurbineUserPeer
479             .doUpdate(criteria, (Connection) null);
480     }
481 
482     /**
483      * Method to do updates.  This method is to be used during a transaction,
484      * otherwise use the doUpdate(Criteria) method.  It will take care of
485      * the connection details internally.
486      *
487      * @param criteria object containing data that is used to create the UPDATE
488      *        statement.
489      * @param con the connection to use
490      * @throws TorqueException Any exceptions caught during processing will be
491      *         rethrown wrapped into a TorqueException.
492      */
493     public static void doUpdate(Criteria criteria, Connection con)
494         throws TorqueException
495     {
496         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
497         correctBooleans(criteria);
498 
499 
500          selectCriteria.put(USER_ID, criteria.remove(USER_ID));
501 
502 
503 
504 
505 
506 
507 
508 
509 
510 
511 
512         setDbName(criteria);
513 
514         if (con == null)
515         {
516             BasePeer.doUpdate(selectCriteria, criteria);
517         }
518         else
519         {
520             BasePeer.doUpdate(selectCriteria, criteria, con);
521         }
522     }
523 
524     /**
525      * Method to do deletes.
526      *
527      * @param criteria object containing data that is used DELETE from database.
528      * @throws TorqueException Any exceptions caught during processing will be
529      *         rethrown wrapped into a TorqueException.
530      */
531      public static void doDelete(Criteria criteria) throws TorqueException
532      {
533          TurbineUserPeer
534             .doDelete(criteria, (Connection) null);
535      }
536 
537     /**
538      * Method to do deletes.  This method is to be used during a transaction,
539      * otherwise use the doDelete(Criteria) method.  It will take care of
540      * the connection details internally.
541      *
542      * @param criteria object containing data that is used DELETE from database.
543      * @param con the connection to use
544      * @throws TorqueException Any exceptions caught during processing will be
545      *         rethrown wrapped into a TorqueException.
546      */
547      public static void doDelete(Criteria criteria, Connection con)
548         throws TorqueException
549      {
550         correctBooleans(criteria);
551 
552         setDbName(criteria);
553 
554         if (con == null)
555         {
556             BasePeer.doDelete(criteria, TABLE_NAME);
557         }
558         else
559         {
560             BasePeer.doDelete(criteria, TABLE_NAME, con);
561         }
562      }
563 
564     /**
565      * Method to do selects
566      *
567      * @throws TorqueException Any exceptions caught during processing will be
568      *         rethrown wrapped into a TorqueException.
569      */
570     public static List<TurbineUser> doSelect(TurbineUser obj) throws TorqueException
571     {
572         return doSelect(buildSelectCriteria(obj));
573     }
574 
575     /**
576      * Method to do inserts
577      *
578      * @throws TorqueException Any exceptions caught during processing will be
579      *         rethrown wrapped into a TorqueException.
580      */
581     public static void doInsert(TurbineUser obj) throws TorqueException
582     {
583         obj.setPrimaryKey(doInsert(buildCriteria(obj)));
584         obj.setNew(false);
585         obj.setModified(false);
586     }
587 
588     /**
589      * @param obj the data object to update in the database.
590      * @throws TorqueException Any exceptions caught during processing will be
591      *         rethrown wrapped into a TorqueException.
592      */
593     public static void doUpdate(TurbineUser obj) throws TorqueException
594     {
595         doUpdate(buildCriteria(obj));
596         obj.setModified(false);
597     }
598 
599     /**
600      * @param obj the data object to delete in the database.
601      * @throws TorqueException Any exceptions caught during processing will be
602      *         rethrown wrapped into a TorqueException.
603      */
604     public static void doDelete(TurbineUser obj) throws TorqueException
605     {
606         doDelete(buildSelectCriteria(obj));
607     }
608 
609     /**
610      * Method to do inserts.  This method is to be used during a transaction,
611      * otherwise use the doInsert(TurbineUser) method.  It will take
612      * care of the connection details internally.
613      *
614      * @param obj the data object to insert into the database.
615      * @param con the connection to use
616      * @throws TorqueException Any exceptions caught during processing will be
617      *         rethrown wrapped into a TorqueException.
618      */
619     public static void doInsert(TurbineUser obj, Connection con)
620         throws TorqueException
621     {
622         obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
623         obj.setNew(false);
624         obj.setModified(false);
625     }
626 
627     /**
628      * Method to do update.  This method is to be used during a transaction,
629      * otherwise use the doUpdate(TurbineUser) method.  It will take
630      * care of the connection details internally.
631      *
632      * @param obj the data object to update in the database.
633      * @param con the connection to use
634      * @throws TorqueException Any exceptions caught during processing will be
635      *         rethrown wrapped into a TorqueException.
636      */
637     public static void doUpdate(TurbineUser obj, Connection con)
638         throws TorqueException
639     {
640         doUpdate(buildCriteria(obj), con);
641         obj.setModified(false);
642     }
643 
644     /**
645      * Method to delete.  This method is to be used during a transaction,
646      * otherwise use the doDelete(TurbineUser) method.  It will take
647      * care of the connection details internally.
648      *
649      * @param obj the data object to delete in the database.
650      * @param con the connection to use
651      * @throws TorqueException Any exceptions caught during processing will be
652      *         rethrown wrapped into a TorqueException.
653      */
654     public static void doDelete(TurbineUser obj, Connection con)
655         throws TorqueException
656     {
657         doDelete(buildSelectCriteria(obj), con);
658     }
659 
660     /**
661      * Method to do deletes.
662      *
663      * @param pk ObjectKey that is used DELETE from database.
664      * @throws TorqueException Any exceptions caught during processing will be
665      *         rethrown wrapped into a TorqueException.
666      */
667     public static void doDelete(ObjectKey pk) throws TorqueException
668     {
669         BaseTurbineUserPeer
670            .doDelete(pk, (Connection) null);
671     }
672 
673     /**
674      * Method to delete.  This method is to be used during a transaction,
675      * otherwise use the doDelete(ObjectKey) method.  It will take
676      * care of the connection details internally.
677      *
678      * @param pk the primary key for the object to delete in the database.
679      * @param con the connection to use
680      * @throws TorqueException Any exceptions caught during processing will be
681      *         rethrown wrapped into a TorqueException.
682      */
683     public static void doDelete(ObjectKey pk, Connection con)
684         throws TorqueException
685     {
686         doDelete(buildCriteria(pk), con);
687     }
688 
689     /** Build a Criteria object from an ObjectKey */
690     public static Criteria buildCriteria( ObjectKey pk )
691     {
692         Criteria criteria = new Criteria();
693             criteria.add(USER_ID, pk);
694         return criteria;
695      }
696 
697     /** Build a Criteria object from the data object for this peer */
698     public static Criteria buildCriteria( TurbineUser obj )
699     {
700         Criteria criteria = new Criteria(DATABASE_NAME);
701         if (!obj.isNew())
702         criteria.add(USER_ID, obj.getUserId());
703         criteria.add(LOGIN_NAME, obj.getUserName());
704         criteria.add(PASSWORD_VALUE, obj.getPassword());
705         criteria.add(FIRST_NAME, obj.getFirstName());
706         criteria.add(LAST_NAME, obj.getLastName());
707         criteria.add(EMAIL, obj.getEmail());
708         criteria.add(CONFIRM_VALUE, obj.getConfirmed());
709         criteria.add(MODIFIED, obj.getModified());
710         criteria.add(CREATED, obj.getCreateDate());
711         criteria.add(LAST_LOGIN, obj.getLastLogin());
712         criteria.add(OBJECTDATA, obj.getObjectdata());
713         return criteria;
714     }
715 
716     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
717     public static Criteria buildSelectCriteria( TurbineUser obj )
718     {
719         Criteria criteria = new Criteria(DATABASE_NAME);
720         if (!obj.isNew())
721         {
722             criteria.add(USER_ID, obj.getUserId());
723         }
724             criteria.add(LOGIN_NAME, obj.getUserName());
725             criteria.add(PASSWORD_VALUE, obj.getPassword());
726             criteria.add(FIRST_NAME, obj.getFirstName());
727             criteria.add(LAST_NAME, obj.getLastName());
728             criteria.add(EMAIL, obj.getEmail());
729             criteria.add(CONFIRM_VALUE, obj.getConfirmed());
730             criteria.add(MODIFIED, obj.getModified());
731             criteria.add(CREATED, obj.getCreateDate());
732             criteria.add(LAST_LOGIN, obj.getLastLogin());
733         return criteria;
734     }
735  
736 
737     /**
738      * Retrieve a single object by pk
739      *
740      * @param pk the primary key
741      * @throws TorqueException Any exceptions caught during processing will be
742      *         rethrown wrapped into a TorqueException.
743      * @throws NoRowsException Primary key was not found in database.
744      * @throws TooManyRowsException Primary key was not found in database.
745      */
746     public static TurbineUser retrieveByPK(int pk)
747         throws TorqueException, NoRowsException, TooManyRowsException
748     {
749         return retrieveByPK(SimpleKey.keyFor(pk));
750     }
751 
752     /**
753      * Retrieve a single object by pk
754      *
755      * @param pk the primary key
756      * @param con the connection to use
757      * @throws TorqueException Any exceptions caught during processing will be
758      *         rethrown wrapped into a TorqueException.
759      * @throws NoRowsException Primary key was not found in database.
760      * @throws TooManyRowsException Primary key was not found in database.
761      */
762     public static TurbineUser retrieveByPK(int pk, Connection con)
763         throws TorqueException, NoRowsException, TooManyRowsException
764     {
765         return retrieveByPK(SimpleKey.keyFor(pk), con);
766     }
767 
768     /**
769      * Retrieve a single object by pk
770      *
771      * @param pk the primary key
772      * @throws TorqueException Any exceptions caught during processing will be
773      *         rethrown wrapped into a TorqueException.
774      * @throws NoRowsException Primary key was not found in database.
775      * @throws TooManyRowsException Primary key was not found in database.
776      */
777     public static TurbineUser retrieveByPK(ObjectKey pk)
778         throws TorqueException, NoRowsException, TooManyRowsException
779     {
780         Connection db = null;
781         TurbineUser retVal = null;
782         try
783         {
784             db = Torque.getConnection(DATABASE_NAME);
785             retVal = retrieveByPK(pk, db);
786         }
787         finally
788         {
789             Torque.closeConnection(db);
790         }
791         return retVal;
792     }
793 
794     /**
795      * Retrieve a single object by pk
796      *
797      * @param pk the primary key
798      * @param con the connection to use
799      * @throws TorqueException Any exceptions caught during processing will be
800      *         rethrown wrapped into a TorqueException.
801      * @throws NoRowsException Primary key was not found in database.
802      * @throws TooManyRowsException Primary key was not found in database.
803      */
804     public static TurbineUser retrieveByPK(ObjectKey pk, Connection con)
805         throws TorqueException, NoRowsException, TooManyRowsException
806     {
807         Criteria criteria = buildCriteria(pk);
808         List<TurbineUser> v = doSelect(criteria, con);
809         if (v.size() == 0)
810         {
811             throw new NoRowsException("Failed to select a row.");
812         }
813         else if (v.size() > 1)
814         {
815             throw new TooManyRowsException("Failed to select only one row.");
816         }
817         else
818         {
819             return (TurbineUser)v.get(0);
820         }
821     }
822 
823     /**
824      * Retrieve a multiple objects by pk
825      *
826      * @param pks List of primary keys
827      * @throws TorqueException Any exceptions caught during processing will be
828      *         rethrown wrapped into a TorqueException.
829      */
830     public static List<TurbineUser> retrieveByPKs(List<ObjectKey> pks)
831         throws TorqueException
832     {
833         Connection db = null;
834         List<TurbineUser> retVal = null;
835         try
836         {
837            db = Torque.getConnection(DATABASE_NAME);
838            retVal = retrieveByPKs(pks, db);
839         }
840         finally
841         {
842             Torque.closeConnection(db);
843         }
844         return retVal;
845     }
846 
847     /**
848      * Retrieve a multiple objects by pk
849      *
850      * @param pks List of primary keys
851      * @param dbcon the connection to use
852      * @throws TorqueException Any exceptions caught during processing will be
853      *         rethrown wrapped into a TorqueException.
854      */
855     public static List<TurbineUser> retrieveByPKs( List<ObjectKey> pks, Connection dbcon )
856         throws TorqueException
857     {
858         List<TurbineUser> objs = null;
859         if (pks == null || pks.size() == 0)
860         {
861             objs = new LinkedList<TurbineUser>();
862         }
863         else
864         {
865             Criteria criteria = new Criteria();
866             criteria.addIn( USER_ID, pks );
867         objs = doSelect(criteria, dbcon);
868         }
869         return objs;
870     }
871 
872  
873 
874 
875 
876 
877 
878 
879 
880 
881     /**
882      * Returns the TableMap related to this peer.
883      *
884      * @throws TorqueException Any exceptions caught during processing will be
885      *         rethrown wrapped into a TorqueException.
886      */
887     public static TableMap getTableMap()
888         throws TorqueException
889     {
890         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
891     }
892  
893     private static void setDbName(Criteria crit)
894     {
895         // Set the correct dbName if it has not been overridden
896         // crit.getDbName will return the same object if not set to
897         // another value so == check is okay and faster
898         if (crit.getDbName() == Torque.getDefaultDB())
899         {
900             crit.setDbName(DATABASE_NAME);
901         }
902     }
903     
904 
905     // The following methods wrap some methods in BasePeer
906     // to have more support for Java5 generic types in the Peer
907     
908     /**
909      * Utility method which executes a given sql statement.  This
910      * method should be used for select statements only.  Use
911      * executeStatement for update, insert, and delete operations.
912      *
913      * @param queryString A String with the sql statement to execute.
914      * @return List of Record objects.
915      * @throws TorqueException Any exceptions caught during processing will be
916      *         rethrown wrapped into a TorqueException.
917      * @see org.apache.torque.util.BasePeer#executeQuery(String)
918      */
919     public static List<Record> executeQuery(String queryString) throws TorqueException
920     {
921         return BasePeer.executeQuery(queryString);
922     }
923 
924     /**
925      * Utility method which executes a given sql statement.  This
926      * method should be used for select statements only.  Use
927      * executeStatement for update, insert, and delete operations.
928      *
929      * @param queryString A String with the sql statement to execute.
930      * @param dbName The database to connect to.
931      * @return List of Record objects.
932      * @throws TorqueException Any exceptions caught during processing will be
933      *         rethrown wrapped into a TorqueException.
934      * @see org.apache.torque.util.BasePeer#executeQuery(String,String)
935      */
936     public static List<Record> executeQuery(String queryString, String dbName)
937         throws TorqueException
938     {
939         return BasePeer.executeQuery(queryString,dbName);
940     }
941     
942 
943     /**
944      * Method for performing a SELECT.  Returns all results.
945      *
946      * @param queryString A String with the sql statement to execute.
947      * @param dbName The database to connect to.
948      * @param singleRecord Whether or not we want to select only a
949      * single record.
950      * @return List of Record objects.
951      * @throws TorqueException Any exceptions caught during processing will be
952      *         rethrown wrapped into a TorqueException.
953      * @see org.apache.torque.util.BasePeer#executeQuery(String,String,boolean)
954      */
955     public static List<Record> executeQuery(
956         String queryString,
957         String dbName,
958         boolean singleRecord)
959         throws TorqueException
960     {
961         return BasePeer.executeQuery(queryString,dbName,singleRecord);
962     }
963 
964     /**
965      * Method for performing a SELECT.  Returns all results.
966      *
967      * @param queryString A String with the sql statement to execute.
968      * @param singleRecord Whether or not we want to select only a
969      * single record.
970      * @param con A Connection.
971      * @return List of Record objects.
972      * @throws TorqueException Any exceptions caught during processing will be
973      *         rethrown wrapped into a TorqueException.
974      * @see org.apache.torque.util.BasePeer#executeQuery(String,boolean,Connection)
975      */
976     public static List<Record> executeQuery(
977         String queryString,
978         boolean singleRecord,
979         Connection con)
980         throws TorqueException
981     {
982         return BasePeer.executeQuery(queryString,singleRecord,con);
983     }
984 
985     /**
986      * Method for performing a SELECT.
987      *
988      * @param queryString A String with the sql statement to execute.
989      * @param start The first row to return.
990      * @param numberOfResults The number of rows to return.
991      * @param dbName The database to connect to.
992      * @param singleRecord Whether or not we want to select only a
993      * single record.
994      * @return List of Record objects.
995      * @throws TorqueException Any exceptions caught during processing will be
996      *         rethrown wrapped into a TorqueException.
997      * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean)
998      */
999     public static List<Record> executeQuery(
1000         String queryString,
1001         int start,
1002         int numberOfResults,
1003         String dbName,
1004         boolean singleRecord)
1005         throws TorqueException
1006     {
1007         return BasePeer.executeQuery(queryString,start,numberOfResults,dbName,singleRecord);
1008     }
1009 
1010     /**
1011      * Method for performing a SELECT.  Returns all results.
1012      *
1013      * @param queryString A String with the sql statement to execute.
1014      * @param start The first row to return.
1015      * @param numberOfResults The number of rows to return.
1016      * @param singleRecord Whether or not we want to select only a
1017      * single record.
1018      * @param con A Connection.
1019      * @return List of Record objects.
1020      * @throws TorqueException Any exceptions caught during processing will be
1021      *         rethrown wrapped into a TorqueException.
1022      * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean,Connection)
1023      */
1024     public static List<Record> executeQuery(
1025         String queryString,
1026         int start,
1027         int numberOfResults,
1028         boolean singleRecord,
1029         Connection con)
1030         throws TorqueException
1031     {
1032         return BasePeer.executeQuery(queryString,start,numberOfResults,singleRecord,con);
1033     }
1034 
1035     /**
1036      * Returns all records in a QueryDataSet as a List of Record
1037      * objects.  Used for functionality like util.LargeSelect.
1038      *
1039      * @see #getSelectResults(QueryDataSet, int, int, boolean)
1040      * @param qds the QueryDataSet
1041      * @return a List of Record objects
1042      * @throws TorqueException Any exceptions caught during processing will be
1043      *         rethrown wrapped into a TorqueException.
1044      * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet)
1045      */
1046     public static List<Record> getSelectResults(QueryDataSet qds)
1047         throws TorqueException
1048     {
1049         return BasePeer.getSelectResults(qds);
1050     }
1051     
1052     /**
1053      * Returns all records in a QueryDataSet as a List of Record
1054      * objects.  Used for functionality like util.LargeSelect.
1055      *
1056      * @see #getSelectResults(QueryDataSet, int, int, boolean)
1057      * @param qds the QueryDataSet
1058      * @param singleRecord
1059      * @return a List of Record objects
1060      * @throws TorqueException Any exceptions caught during processing will be
1061      *         rethrown wrapped into a TorqueException.
1062      * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,boolean)
1063      */
1064     public static List<Record> getSelectResults(QueryDataSet qds, boolean singleRecord)
1065         throws TorqueException
1066     {
1067         return BasePeer.getSelectResults(qds,singleRecord);
1068     }
1069     
1070     /**
1071      * Returns numberOfResults records in a QueryDataSet as a List
1072      * of Record objects.  Starting at record 0.  Used for
1073      * functionality like util.LargeSelect.
1074      *
1075      * @see #getSelectResults(QueryDataSet, int, int, boolean)
1076      * @param qds the QueryDataSet
1077      * @param numberOfResults
1078      * @param singleRecord
1079      * @return a List of Record objects
1080      * @throws TorqueException Any exceptions caught during processing will be
1081      *         rethrown wrapped into a TorqueException.
1082      * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,boolean)
1083      */
1084     public static List<Record> getSelectResults(
1085         QueryDataSet qds,
1086         int numberOfResults,
1087         boolean singleRecord)
1088         throws TorqueException
1089     {
1090         return BasePeer.getSelectResults(qds,numberOfResults,singleRecord);
1091     }
1092 
1093     /**
1094      * Returns numberOfResults records in a QueryDataSet as a List
1095      * of Record objects.  Starting at record start.  Used for
1096      * functionality like util.LargeSelect.
1097      *
1098      * @param qds The <code>QueryDataSet</code> to extract results
1099      * from.
1100      * @param start The index from which to start retrieving
1101      * <code>Record</code> objects from the data set.
1102      * @param numberOfResults The number of results to return (or
1103      * <code> -1</code> for all results).
1104      * @param singleRecord Whether or not we want to select only a
1105      * single record.
1106      * @return A <code>List</code> of <code>Record</code> objects.
1107      * @exception TorqueException If any <code>Exception</code> occurs.
1108      * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,int,boolean)
1109      */
1110     public static List getSelectResults(
1111         QueryDataSet qds,
1112         int start,
1113         int numberOfResults,
1114         boolean singleRecord)
1115         throws TorqueException
1116     {
1117         return BasePeer.getSelectResults(qds,start,numberOfResults,singleRecord);
1118     }
1119 
1120     /**
1121      * Performs a SQL <code>select</code> using a PreparedStatement.
1122      * Note: this method does not handle null criteria values.
1123      *
1124      * @param criteria
1125      * @param con
1126      * @return a List of Record objects.
1127      * @throws TorqueException Error performing database query.
1128      * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria,Connection)
1129      */
1130     public static List<Record> doPSSelect(Criteria criteria, Connection con)
1131         throws TorqueException
1132     {
1133         return BasePeer.doPSSelect(criteria,con);
1134     }
1135 
1136     /**
1137      * Do a Prepared Statement select according to the given criteria
1138      *
1139      * @param criteria
1140      * @return a List of Record objects.
1141      * @throws TorqueException Any exceptions caught during processing will be
1142      *         rethrown wrapped into a TorqueException.
1143      * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria)
1144      */
1145     public static List<Record> doPSSelect(Criteria criteria) throws TorqueException
1146     {
1147         return BasePeer.doPSSelect(criteria);
1148     }
1149 }