KickJava   Java API By Example, From Geeks To Geeks.

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


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 BaseTurbineUserPeer
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_USER";
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(TurbineUserMapBuilder.CLASS_NAME);
55     }
56
57       /** the column name for the USER_ID field */
58     public static final String JavaDoc USER_ID;
59       /** the column name for the LOGIN_NAME field */
60     public static final String JavaDoc LOGIN_NAME;
61       /** the column name for the PASSWORD_VALUE field */
62     public static final String JavaDoc PASSWORD_VALUE;
63       /** the column name for the FIRST_NAME field */
64     public static final String JavaDoc FIRST_NAME;
65       /** the column name for the LAST_NAME field */
66     public static final String JavaDoc LAST_NAME;
67       /** the column name for the EMAIL field */
68     public static final String JavaDoc EMAIL;
69       /** the column name for the CONFIRM_VALUE field */
70     public static final String JavaDoc CONFIRM_VALUE;
71       /** the column name for the MODIFIED field */
72     public static final String JavaDoc MODIFIED;
73       /** the column name for the CREATED field */
74     public static final String JavaDoc CREATED;
75       /** the column name for the LAST_LOGIN field */
76     public static final String JavaDoc LAST_LOGIN;
77       /** the column name for the OBJECTDATA field */
78     public static final String JavaDoc OBJECTDATA;
79   
80     static
81     {
82           USER_ID = "TURBINE_USER.USER_ID";
83           LOGIN_NAME = "TURBINE_USER.LOGIN_NAME";
84           PASSWORD_VALUE = "TURBINE_USER.PASSWORD_VALUE";
85           FIRST_NAME = "TURBINE_USER.FIRST_NAME";
86           LAST_NAME = "TURBINE_USER.LAST_NAME";
87           EMAIL = "TURBINE_USER.EMAIL";
88           CONFIRM_VALUE = "TURBINE_USER.CONFIRM_VALUE";
89           MODIFIED = "TURBINE_USER.MODIFIED";
90           CREATED = "TURBINE_USER.CREATED";
91           LAST_LOGIN = "TURBINE_USER.LAST_LOGIN";
92           OBJECTDATA = "TURBINE_USER.OBJECTDATA";
93           if (Torque.isInit())
94         {
95             try
96             {
97                 getMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
98             }
99             catch (Exception JavaDoc e)
100             {
101                 log.error("Could not initialize Peer", e);
102             }
103         }
104         else
105         {
106             Torque.registerMapBuilder(TurbineUserMapBuilder.CLASS_NAME);
107         }
108     }
109  
110     /** number of columns for this peer */
111     public static final int numColumns = 11;
112
113     /** A class that can be returned by this peer. */
114     protected static final String JavaDoc CLASSNAME_DEFAULT =
115         "org.apache.fulcrum.security.impl.db.entity.TurbineUser";
116
117     /** A class that can be returned by this peer. */
118     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
119
120     /**
121      * Class object initialization method.
122      *
123      * @param className name of the class to initialize
124      * @return the initialized class
125      */

126     private static Class JavaDoc initClass(String JavaDoc className)
127     {
128         Class JavaDoc c = null;
129         try
130         {
131             c = Class.forName(className);
132         }
133         catch (Throwable JavaDoc t)
134         {
135             log.error("A FATAL ERROR has occurred which should not "
136                 + "have happened under any circumstance. Please notify "
137                 + "the Torque developers <torque-dev@db.apache.org> "
138                 + "and give as many details as possible (including the error "
139                 + "stack trace).", t);
140
141             // Error objects should always be propogated.
142
if (t instanceof Error JavaDoc)
143             {
144                 throw (Error JavaDoc) t.fillInStackTrace();
145             }
146         }
147         return c;
148     }
149
150     /**
151      * Get the list of objects for a ResultSet. Please not that your
152      * resultset MUST return columns in the right order. You can use
153      * getFieldNames() in BaseObject to get the correct sequence.
154      *
155      * @param results the ResultSet
156      * @return the list of objects
157      * @throws TorqueException Any exceptions caught during processing will be
158      * rethrown wrapped into a TorqueException.
159      */

160     public static List JavaDoc resultSet2Objects(java.sql.ResultSet JavaDoc results)
161             throws TorqueException
162     {
163         try
164         {
165             QueryDataSet qds = null;
166             List JavaDoc rows = null;
167             try
168             {
169                 qds = new QueryDataSet(results);
170                 rows = getSelectResults(qds);
171             }
172             finally
173             {
174                 if (qds != null)
175                 {
176                     qds.close();
177                 }
178             }
179
180             return populateObjects(rows);
181         }
182         catch (SQLException JavaDoc e)
183         {
184             throw new TorqueException(e);
185         }
186         catch (DataSetException e)
187         {
188             throw new TorqueException(e);
189         }
190     }
191
192
193   
194     /**
195      * Method to do inserts.
196      *
197      * @param criteria object used to create the INSERT statement.
198      * @throws TorqueException Any exceptions caught during processing will be
199      * rethrown wrapped into a TorqueException.
200      */

201     public static ObjectKey doInsert(Criteria criteria)
202         throws TorqueException
203     {
204         return BaseTurbineUserPeer
205             .doInsert(criteria, (Connection JavaDoc) null);
206     }
207
208     /**
209      * Method to do inserts. This method is to be used during a transaction,
210      * otherwise use the doInsert(Criteria) method. It will take care of
211      * the connection details internally.
212      *
213      * @param criteria object used to create the INSERT statement.
214      * @param con the connection to use
215      * @throws TorqueException Any exceptions caught during processing will be
216      * rethrown wrapped into a TorqueException.
217      */

218     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
219         throws TorqueException
220     {
221                                                                     
222         // Set the correct dbName if it has not been overridden
223
// criteria.getDbName will return the same object if not set to
224
// another value so == check is okay and faster
225
if (criteria.getDbName() == Torque.getDefaultDB())
226         {
227             criteria.setDbName(DATABASE_NAME);
228         }
229         if (con == null)
230         {
231             return BasePeer.doInsert(criteria);
232         }
233         else
234         {
235             return BasePeer.doInsert(criteria, con);
236         }
237     }
238
239     /**
240      * Add all the columns needed to create a new object.
241      *
242      * @param criteria object containing the columns to add.
243      * @throws TorqueException Any exceptions caught during processing will be
244      * rethrown wrapped into a TorqueException.
245      */

246     public static void addSelectColumns(Criteria criteria)
247             throws TorqueException
248     {
249           criteria.addSelectColumn(USER_ID);
250           criteria.addSelectColumn(LOGIN_NAME);
251           criteria.addSelectColumn(PASSWORD_VALUE);
252           criteria.addSelectColumn(FIRST_NAME);
253           criteria.addSelectColumn(LAST_NAME);
254           criteria.addSelectColumn(EMAIL);
255           criteria.addSelectColumn(CONFIRM_VALUE);
256           criteria.addSelectColumn(MODIFIED);
257           criteria.addSelectColumn(CREATED);
258           criteria.addSelectColumn(LAST_LOGIN);
259           criteria.addSelectColumn(OBJECTDATA);
260       }
261
262     /**
263      * Create a new object of type cls from a resultset row starting
264      * from a specified offset. This is done so that you can select
265      * other rows than just those needed for this object. You may
266      * for example want to create two objects from the same row.
267      *
268      * @throws TorqueException Any exceptions caught during processing will be
269      * rethrown wrapped into a TorqueException.
270      */

271     public static TurbineUser row2Object(Record row,
272                                              int offset,
273                                              Class JavaDoc cls)
274         throws TorqueException
275     {
276         try
277         {
278             TurbineUser obj = (TurbineUser) cls.newInstance();
279             TurbineUserPeer.populateObject(row, offset, obj);
280                   obj.setModified(false);
281               obj.setNew(false);
282
283             return obj;
284         }
285         catch (InstantiationException JavaDoc e)
286         {
287             throw new TorqueException(e);
288         }
289         catch (IllegalAccessException JavaDoc e)
290         {
291             throw new TorqueException(e);
292         }
293     }
294
295     /**
296      * Populates an object from a resultset row starting
297      * from a specified offset. This is done so that you can select
298      * other rows than just those needed for this object. You may
299      * for example want to create two objects from the same row.
300      *
301      * @throws TorqueException Any exceptions caught during processing will be
302      * rethrown wrapped into a TorqueException.
303      */

304     public static void populateObject(Record row,
305                                       int offset,
306                                       TurbineUser obj)
307         throws TorqueException
308     {
309         try
310         {
311                 obj.setUserId(row.getValue(offset + 0).asIntegerObj());
312                   obj.setUserName(row.getValue(offset + 1).asString());
313                   obj.setPassword(row.getValue(offset + 2).asString());
314                   obj.setFirstName(row.getValue(offset + 3).asString());
315                   obj.setLastName(row.getValue(offset + 4).asString());
316                   obj.setEmail(row.getValue(offset + 5).asString());
317                   obj.setConfirmed(row.getValue(offset + 6).asString());
318                   obj.setModified(row.getValue(offset + 7).asUtilDate());
319                   obj.setCreateDate(row.getValue(offset + 8).asUtilDate());
320                   obj.setLastLogin(row.getValue(offset + 9).asUtilDate());
321                   obj.setObjectdata(row.getValue(offset + 10).asBytes());
322               }
323         catch (DataSetException e)
324         {
325             throw new TorqueException(e);
326         }
327     }
328
329     /**
330      * Method to do selects.
331      *
332      * @param criteria object used to create the SELECT statement.
333      * @return List of selected Objects
334      * @throws TorqueException Any exceptions caught during processing will be
335      * rethrown wrapped into a TorqueException.
336      */

337     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
338     {
339         return populateObjects(doSelectVillageRecords(criteria));
340     }
341
342     /**
343      * Method to do selects within a transaction.
344      *
345      * @param criteria object used to create the SELECT statement.
346      * @param con the connection to use
347      * @return List of selected Objects
348      * @throws TorqueException Any exceptions caught during processing will be
349      * rethrown wrapped into a TorqueException.
350      */

351     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
352         throws TorqueException
353     {
354         return populateObjects(doSelectVillageRecords(criteria, con));
355     }
356
357     /**
358      * Grabs the raw Village records to be formed into objects.
359      * This method handles connections internally. The Record objects
360      * returned by this method should be considered readonly. Do not
361      * alter the data and call save(), your results may vary, but are
362      * certainly likely to result in hard to track MT bugs.
363      *
364      * @throws TorqueException Any exceptions caught during processing will be
365      * rethrown wrapped into a TorqueException.
366      */

367     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
368         throws TorqueException
369     {
370         return BaseTurbineUserPeer
371             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
372     }
373
374     /**
375      * Grabs the raw Village records to be formed into objects.
376      * This method should be used for transactions
377      *
378      * @param con the connection to use
379      * @throws TorqueException Any exceptions caught during processing will be
380      * rethrown wrapped into a TorqueException.
381      */

382     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
383         throws TorqueException
384     {
385         if (criteria.getSelectColumns().size() == 0)
386         {
387             addSelectColumns(criteria);
388         }
389
390                                                                     
391         // Set the correct dbName if it has not been overridden
392
// criteria.getDbName will return the same object if not set to
393
// another value so == check is okay and faster
394
if (criteria.getDbName() == Torque.getDefaultDB())
395         {
396             criteria.setDbName(DATABASE_NAME);
397         }
398         // BasePeer returns a List of Value (Village) arrays. The array
399
// order follows the order columns were placed in the Select clause.
400
if (con == null)
401         {
402             return BasePeer.doSelect(criteria);
403         }
404         else
405         {
406             return BasePeer.doSelect(criteria, con);
407         }
408     }
409
410     /**
411      * The returned List will contain objects of the default type or
412      * objects that inherit from the default.
413      *
414      * @throws TorqueException Any exceptions caught during processing will be
415      * rethrown wrapped into a TorqueException.
416      */

417     public static List JavaDoc populateObjects(List JavaDoc records)
418         throws TorqueException
419     {
420         List JavaDoc results = new ArrayList JavaDoc(records.size());
421
422         // populate the object(s)
423
for (int i = 0; i < records.size(); i++)
424         {
425             Record row = (Record) records.get(i);
426               results.add(TurbineUserPeer.row2Object(row, 1,
427                 TurbineUserPeer.getOMClass()));
428           }
429         return results;
430     }
431  
432
433     /**
434      * The class that the Peer will make instances of.
435      * If the BO is abstract then you must implement this method
436      * in the BO.
437      *
438      * @throws TorqueException Any exceptions caught during processing will be
439      * rethrown wrapped into a TorqueException.
440      */

441     public static Class JavaDoc getOMClass()
442         throws TorqueException
443     {
444         return CLASS_DEFAULT;
445     }
446
447     /**
448      * Method to do updates.
449      *
450      * @param criteria object containing data that is used to create the UPDATE
451      * statement.
452      * @throws TorqueException Any exceptions caught during processing will be
453      * rethrown wrapped into a TorqueException.
454      */

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

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

502      public static void doDelete(Criteria criteria) throws TorqueException
503      {
504          BaseTurbineUserPeer
505             .doDelete(criteria, (Connection JavaDoc) null);
506      }
507
508     /**
509      * Method to do deletes. This method is to be used during a transaction,
510      * otherwise use the doDelete(Criteria) method. It will take care of
511      * the connection details internally.
512      *
513      * @param criteria object containing data that is used DELETE from database.
514      * @param con the connection to use
515      * @throws TorqueException Any exceptions caught during processing will be
516      * rethrown wrapped into a TorqueException.
517      */

518      public static void doDelete(Criteria criteria, Connection JavaDoc con)
519         throws TorqueException
520      {
521                                                                     
522         // Set the correct dbName if it has not been overridden
523
// criteria.getDbName will return the same object if not set to
524
// another value so == check is okay and faster
525
if (criteria.getDbName() == Torque.getDefaultDB())
526         {
527             criteria.setDbName(DATABASE_NAME);
528         }
529         if (con == null)
530         {
531             BasePeer.doDelete(criteria);
532         }
533         else
534         {
535             BasePeer.doDelete(criteria, con);
536         }
537      }
538
539     /**
540      * Method to do selects
541      *
542      * @throws TorqueException Any exceptions caught during processing will be
543      * rethrown wrapped into a TorqueException.
544      */

545     public static List JavaDoc doSelect(TurbineUser obj) throws TorqueException
546     {
547         return doSelect(buildCriteria(obj));
548     }
549
550     /**
551      * Method to do inserts
552      *
553      * @throws TorqueException Any exceptions caught during processing will be
554      * rethrown wrapped into a TorqueException.
555      */

556     public static void doInsert(TurbineUser obj) throws TorqueException
557     {
558           obj.setPrimaryKey(doInsert(buildCriteria(obj)));
559           obj.setNew(false);
560         obj.setModified(false);
561     }
562
563     /**
564      * @param obj the data object to update in the database.
565      * @throws TorqueException Any exceptions caught during processing will be
566      * rethrown wrapped into a TorqueException.
567      */

568     public static void doUpdate(TurbineUser obj) throws TorqueException
569     {
570         doUpdate(buildCriteria(obj));
571         obj.setModified(false);
572     }
573
574     /**
575      * @param obj the data object to delete in the database.
576      * @throws TorqueException Any exceptions caught during processing will be
577      * rethrown wrapped into a TorqueException.
578      */

579     public static void doDelete(TurbineUser obj) throws TorqueException
580     {
581         doDelete(buildCriteria(obj));
582     }
583
584     /**
585      * Method to do inserts. This method is to be used during a transaction,
586      * otherwise use the doInsert(TurbineUser) method. It will take
587      * care of the connection details internally.
588      *
589      * @param obj the data object to insert into the database.
590      * @param con the connection to use
591      * @throws TorqueException Any exceptions caught during processing will be
592      * rethrown wrapped into a TorqueException.
593      */

594     public static void doInsert(TurbineUser obj, Connection JavaDoc con)
595         throws TorqueException
596     {
597           obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
598           obj.setNew(false);
599         obj.setModified(false);
600     }
601
602     /**
603      * Method to do update. This method is to be used during a transaction,
604      * otherwise use the doUpdate(TurbineUser) method. It will take
605      * care of the connection details internally.
606      *
607      * @param obj the data object to update in the database.
608      * @param con the connection to use
609      * @throws TorqueException Any exceptions caught during processing will be
610      * rethrown wrapped into a TorqueException.
611      */

612     public static void doUpdate(TurbineUser obj, Connection JavaDoc con)
613         throws TorqueException
614     {
615         doUpdate(buildCriteria(obj), con);
616         obj.setModified(false);
617     }
618
619     /**
620      * Method to delete. This method is to be used during a transaction,
621      * otherwise use the doDelete(TurbineUser) method. It will take
622      * care of the connection details internally.
623      *
624      * @param obj the data object to delete in the database.
625      * @param con the connection to use
626      * @throws TorqueException Any exceptions caught during processing will be
627      * rethrown wrapped into a TorqueException.
628      */

629     public static void doDelete(TurbineUser obj, Connection JavaDoc con)
630         throws TorqueException
631     {
632         doDelete(buildCriteria(obj), con);
633     }
634
635     /**
636      * Method to do deletes.
637      *
638      * @param pk ObjectKey that is used DELETE from database.
639      * @throws TorqueException Any exceptions caught during processing will be
640      * rethrown wrapped into a TorqueException.
641      */

642     public static void doDelete(ObjectKey pk) throws TorqueException
643     {
644         BaseTurbineUserPeer
645            .doDelete(pk, (Connection JavaDoc) null);
646     }
647
648     /**
649      * Method to delete. This method is to be used during a transaction,
650      * otherwise use the doDelete(ObjectKey) method. It will take
651      * care of the connection details internally.
652      *
653      * @param pk the primary key for the object to delete in the database.
654      * @param con the connection to use
655      * @throws TorqueException Any exceptions caught during processing will be
656      * rethrown wrapped into a TorqueException.
657      */

658     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
659         throws TorqueException
660     {
661         doDelete(buildCriteria(pk), con);
662     }
663
664     /** Build a Criteria object from an ObjectKey */
665     public static Criteria buildCriteria( ObjectKey pk )
666     {
667         Criteria criteria = new Criteria();
668               criteria.add(USER_ID, pk);
669           return criteria;
670      }
671
672     /** Build a Criteria object from the data object for this peer */
673     public static Criteria buildCriteria( TurbineUser obj )
674     {
675         Criteria criteria = new Criteria(DATABASE_NAME);
676               if (!obj.isNew())
677                 criteria.add(USER_ID, obj.getUserId());
678                   criteria.add(LOGIN_NAME, obj.getUserName());
679                   criteria.add(PASSWORD_VALUE, obj.getPassword());
680                   criteria.add(FIRST_NAME, obj.getFirstName());
681                   criteria.add(LAST_NAME, obj.getLastName());
682                   criteria.add(EMAIL, obj.getEmail());
683                   criteria.add(CONFIRM_VALUE, obj.getConfirmed());
684                   criteria.add(MODIFIED, obj.getModified());
685                   criteria.add(CREATED, obj.getCreateDate());
686                   criteria.add(LAST_LOGIN, obj.getLastLogin());
687                   criteria.add(OBJECTDATA, obj.getObjectdata());
688           return criteria;
689     }
690  
691     
692         /**
693      * Retrieve a single object by pk
694      *
695      * @param pk the primary key
696      * @throws TorqueException Any exceptions caught during processing will be
697      * rethrown wrapped into a TorqueException.
698      * @throws NoRowsException Primary key was not found in database.
699      * @throws TooManyRowsException Primary key was not found in database.
700      */

701     public static TurbineUser retrieveByPK(Integer JavaDoc pk)
702         throws TorqueException, NoRowsException, TooManyRowsException
703     {
704         return retrieveByPK(SimpleKey.keyFor(pk));
705     }
706   
707     /**
708      * Retrieve a single object by pk
709      *
710      * @param pk the primary key
711      * @throws TorqueException Any exceptions caught during processing will be
712      * rethrown wrapped into a TorqueException.
713      * @throws NoRowsException Primary key was not found in database.
714      * @throws TooManyRowsException Primary key was not found in database.
715      */

716     public static TurbineUser retrieveByPK(ObjectKey pk)
717         throws TorqueException, NoRowsException, TooManyRowsException
718     {
719         Connection JavaDoc db = null;
720         TurbineUser retVal = null;
721         try
722         {
723             db = Torque.getConnection(DATABASE_NAME);
724             retVal = retrieveByPK(pk, db);
725         }
726         finally
727         {
728             Torque.closeConnection(db);
729         }
730         return(retVal);
731     }
732
733     /**
734      * Retrieve a single object by pk
735      *
736      * @param pk the primary key
737      * @param con the connection to use
738      * @throws TorqueException Any exceptions caught during processing will be
739      * rethrown wrapped into a TorqueException.
740      * @throws NoRowsException Primary key was not found in database.
741      * @throws TooManyRowsException Primary key was not found in database.
742      */

743     public static TurbineUser retrieveByPK(ObjectKey pk, Connection JavaDoc con)
744         throws TorqueException, NoRowsException, TooManyRowsException
745     {
746         Criteria criteria = buildCriteria(pk);
747         List JavaDoc v = doSelect(criteria, con);
748         if (v.size() == 0)
749         {
750             throw new NoRowsException("Failed to select a row.");
751         }
752         else if (v.size() > 1)
753         {
754             throw new TooManyRowsException("Failed to select only one row.");
755         }
756         else
757         {
758             return (TurbineUser)v.get(0);
759         }
760     }
761
762     /**
763      * Retrieve a multiple objects by pk
764      *
765      * @param pks List of primary keys
766      * @throws TorqueException Any exceptions caught during processing will be
767      * rethrown wrapped into a TorqueException.
768      */

769     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
770         throws TorqueException
771     {
772         Connection JavaDoc db = null;
773         List JavaDoc retVal = null;
774         try
775         {
776            db = Torque.getConnection(DATABASE_NAME);
777            retVal = retrieveByPKs(pks, db);
778         }
779         finally
780         {
781             Torque.closeConnection(db);
782         }
783         return(retVal);
784     }
785
786     /**
787      * Retrieve a multiple objects by pk
788      *
789      * @param pks List of primary keys
790      * @param dbcon the connection to use
791      * @throws TorqueException Any exceptions caught during processing will be
792      * rethrown wrapped into a TorqueException.
793      */

794     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
795         throws TorqueException
796     {
797         List JavaDoc objs = null;
798         if (pks == null || pks.size() == 0)
799         {
800             objs = new LinkedList JavaDoc();
801         }
802         else
803         {
804             Criteria criteria = new Criteria();
805               criteria.addIn( USER_ID, pks );
806           objs = doSelect(criteria, dbcon);
807         }
808         return objs;
809     }
810
811  
812
813
814
815         
816   
817   
818     
819   
820       /**
821      * Returns the TableMap related to this peer. This method is not
822      * needed for general use but a specific application could have a need.
823      *
824      * @throws TorqueException Any exceptions caught during processing will be
825      * rethrown wrapped into a TorqueException.
826      */

827     protected static TableMap getTableMap()
828         throws TorqueException
829     {
830         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
831     }
832    }
833
Popular Tags