KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tigris > scarab > om > BaseUserPreferencePeer


1 package org.tigris.scarab.om;
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.tigris.scarab.om.map.*;
32
33
34   
35 /**
36  */

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

52     public static MapBuilder getMapBuilder()
53         throws TorqueException
54     {
55         return getMapBuilder(UserPreferenceMapBuilder.CLASS_NAME);
56     }
57
58       /** the column name for the USER_ID field */
59     public static final String JavaDoc USER_ID;
60       /** the column name for the PASSWORD_EXPIRE field */
61     public static final String JavaDoc PASSWORD_EXPIRE;
62       /** the column name for the ENTER_ISSUE_REDIRECT field */
63     public static final String JavaDoc ENTER_ISSUE_REDIRECT;
64       /** the column name for the HOME_PAGE field */
65     public static final String JavaDoc HOME_PAGE;
66       /** the column name for the LOCALE field */
67     public static final String JavaDoc LOCALE;
68   
69     static
70     {
71           USER_ID = "SCARAB_USER_PREFERENCE.USER_ID";
72           PASSWORD_EXPIRE = "SCARAB_USER_PREFERENCE.PASSWORD_EXPIRE";
73           ENTER_ISSUE_REDIRECT = "SCARAB_USER_PREFERENCE.ENTER_ISSUE_REDIRECT";
74           HOME_PAGE = "SCARAB_USER_PREFERENCE.HOME_PAGE";
75           LOCALE = "SCARAB_USER_PREFERENCE.LOCALE";
76           if (Torque.isInit())
77         {
78             try
79             {
80                 getMapBuilder(UserPreferenceMapBuilder.CLASS_NAME);
81             }
82             catch (Exception JavaDoc e)
83             {
84                 log.error("Could not initialize Peer", e);
85             }
86         }
87         else
88         {
89             Torque.registerMapBuilder(UserPreferenceMapBuilder.CLASS_NAME);
90         }
91     }
92  
93     /** number of columns for this peer */
94     public static final int numColumns = 5;
95
96     /** A class that can be returned by this peer. */
97     protected static final String JavaDoc CLASSNAME_DEFAULT =
98         "org.tigris.scarab.om.UserPreference";
99
100     /** A class that can be returned by this peer. */
101     protected static final Class JavaDoc CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
102
103     /**
104      * Class object initialization method.
105      *
106      * @param className name of the class to initialize
107      * @return the initialized class
108      */

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

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

184     public static ObjectKey doInsert(Criteria criteria)
185         throws TorqueException
186     {
187         return BaseUserPreferencePeer
188             .doInsert(criteria, (Connection JavaDoc) null);
189     }
190
191     /**
192      * Method to do inserts. This method is to be used during a transaction,
193      * otherwise use the doInsert(Criteria) method. It will take care of
194      * the connection details internally.
195      *
196      * @param criteria object used to create the INSERT statement.
197      * @param con the connection to use
198      * @throws TorqueException Any exceptions caught during processing will be
199      * rethrown wrapped into a TorqueException.
200      */

201     public static ObjectKey doInsert(Criteria criteria, Connection JavaDoc con)
202         throws TorqueException
203     {
204                                 
205         setDbName(criteria);
206
207         if (con == null)
208         {
209             return BasePeer.doInsert(criteria);
210         }
211         else
212         {
213             return BasePeer.doInsert(criteria, con);
214         }
215     }
216
217     /**
218      * Add all the columns needed to create a new object.
219      *
220      * @param criteria object containing the columns to add.
221      * @throws TorqueException Any exceptions caught during processing will be
222      * rethrown wrapped into a TorqueException.
223      */

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

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

276     public static void populateObject(Record row,
277                                       int offset,
278                                       UserPreference obj)
279         throws TorqueException
280     {
281         try
282         {
283                 obj.setUserId(row.getValue(offset + 0).asIntegerObj());
284                   obj.setPasswordExpire(row.getValue(offset + 1).asUtilDate());
285                   obj.setEnterIssueRedirect(row.getValue(offset + 2).asInt());
286                   obj.setHomePage(row.getValue(offset + 3).asString());
287                   obj.setLocale(row.getValue(offset + 4).asString());
288               }
289         catch (DataSetException e)
290         {
291             throw new TorqueException(e);
292         }
293     }
294
295     /**
296      * Method to do selects.
297      *
298      * @param criteria object used to create the SELECT statement.
299      * @return List of selected Objects
300      * @throws TorqueException Any exceptions caught during processing will be
301      * rethrown wrapped into a TorqueException.
302      */

303     public static List JavaDoc doSelect(Criteria criteria) throws TorqueException
304     {
305         return populateObjects(doSelectVillageRecords(criteria));
306     }
307
308     /**
309      * Method to do selects within a transaction.
310      *
311      * @param criteria object used to create the SELECT statement.
312      * @param con the connection to use
313      * @return List of selected Objects
314      * @throws TorqueException Any exceptions caught during processing will be
315      * rethrown wrapped into a TorqueException.
316      */

317     public static List JavaDoc doSelect(Criteria criteria, Connection JavaDoc con)
318         throws TorqueException
319     {
320         return populateObjects(doSelectVillageRecords(criteria, con));
321     }
322
323     /**
324      * Grabs the raw Village records to be formed into objects.
325      * This method handles connections internally. The Record objects
326      * returned by this method should be considered readonly. Do not
327      * alter the data and call save(), your results may vary, but are
328      * certainly likely to result in hard to track MT bugs.
329      *
330      * @throws TorqueException Any exceptions caught during processing will be
331      * rethrown wrapped into a TorqueException.
332      */

333     public static List JavaDoc doSelectVillageRecords(Criteria criteria)
334         throws TorqueException
335     {
336         return BaseUserPreferencePeer
337             .doSelectVillageRecords(criteria, (Connection JavaDoc) null);
338     }
339
340     /**
341      * Grabs the raw Village records to be formed into objects.
342      * This method should be used for transactions
343      *
344      * @param criteria object used to create the SELECT statement.
345      * @param con the connection to use
346      * @throws TorqueException Any exceptions caught during processing will be
347      * rethrown wrapped into a TorqueException.
348      */

349     public static List JavaDoc doSelectVillageRecords(Criteria criteria, Connection JavaDoc con)
350         throws TorqueException
351     {
352         if (criteria.getSelectColumns().size() == 0)
353         {
354             addSelectColumns(criteria);
355         }
356
357                                 
358         setDbName(criteria);
359
360         // BasePeer returns a List of Value (Village) arrays. The array
361
// order follows the order columns were placed in the Select clause.
362
if (con == null)
363         {
364             return BasePeer.doSelect(criteria);
365         }
366         else
367         {
368             return BasePeer.doSelect(criteria, con);
369         }
370     }
371
372     /**
373      * The returned List will contain objects of the default type or
374      * objects that inherit from the default.
375      *
376      * @throws TorqueException Any exceptions caught during processing will be
377      * rethrown wrapped into a TorqueException.
378      */

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

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

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

434     public static void doUpdate(Criteria criteria, Connection JavaDoc con)
435         throws TorqueException
436     {
437         Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
438                    selectCriteria.put(USER_ID, criteria.remove(USER_ID));
439                                               
440         setDbName(criteria);
441
442         if (con == null)
443         {
444             BasePeer.doUpdate(selectCriteria, criteria);
445         }
446         else
447         {
448             BasePeer.doUpdate(selectCriteria, criteria, con);
449         }
450     }
451
452     /**
453      * Method to do deletes.
454      *
455      * @param criteria object containing data that is used DELETE from database.
456      * @throws TorqueException Any exceptions caught during processing will be
457      * rethrown wrapped into a TorqueException.
458      */

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

475      public static void doDelete(Criteria criteria, Connection JavaDoc con)
476         throws TorqueException
477      {
478                                 
479         setDbName(criteria);
480
481         if (con == null)
482         {
483             BasePeer.doDelete(criteria);
484         }
485         else
486         {
487             BasePeer.doDelete(criteria, con);
488         }
489      }
490
491     /**
492      * Method to do selects
493      *
494      * @throws TorqueException Any exceptions caught during processing will be
495      * rethrown wrapped into a TorqueException.
496      */

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

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

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

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

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

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

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

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

610     public static void doDelete(ObjectKey pk, Connection JavaDoc con)
611         throws TorqueException
612     {
613         doDelete(buildCriteria(pk), con);
614     }
615
616     /** Build a Criteria object from an ObjectKey */
617     public static Criteria buildCriteria( ObjectKey pk )
618     {
619         Criteria criteria = new Criteria();
620               criteria.add(USER_ID, pk);
621           return criteria;
622      }
623
624     /** Build a Criteria object from the data object for this peer */
625     public static Criteria buildCriteria( UserPreference obj )
626     {
627         Criteria criteria = new Criteria(DATABASE_NAME);
628               criteria.add(USER_ID, obj.getUserId());
629               criteria.add(PASSWORD_EXPIRE, obj.getPasswordExpire());
630               criteria.add(ENTER_ISSUE_REDIRECT, obj.getEnterIssueRedirect());
631               criteria.add(HOME_PAGE, obj.getHomePage());
632               criteria.add(LOCALE, obj.getLocale());
633           return criteria;
634     }
635
636     /** Build a Criteria object from the data object for this peer, skipping all binary columns */
637     public static Criteria buildSelectCriteria( UserPreference obj )
638     {
639         Criteria criteria = new Criteria(DATABASE_NAME);
640                       criteria.add(USER_ID, obj.getUserId());
641                           criteria.add(PASSWORD_EXPIRE, obj.getPasswordExpire());
642                           criteria.add(ENTER_ISSUE_REDIRECT, obj.getEnterIssueRedirect());
643                           criteria.add(HOME_PAGE, obj.getHomePage());
644                           criteria.add(LOCALE, obj.getLocale());
645               return criteria;
646     }
647  
648     
649         /**
650      * Retrieve a single object by pk
651      *
652      * @param pk the primary key
653      * @throws TorqueException Any exceptions caught during processing will be
654      * rethrown wrapped into a TorqueException.
655      * @throws NoRowsException Primary key was not found in database.
656      * @throws TooManyRowsException Primary key was not found in database.
657      */

658     public static UserPreference retrieveByPK(Integer JavaDoc pk)
659         throws TorqueException, NoRowsException, TooManyRowsException
660     {
661         return retrieveByPK(SimpleKey.keyFor(pk));
662     }
663
664     /**
665      * Retrieve a single object by pk
666      *
667      * @param pk the primary key
668      * @param con the connection to use
669      * @throws TorqueException Any exceptions caught during processing will be
670      * rethrown wrapped into a TorqueException.
671      * @throws NoRowsException Primary key was not found in database.
672      * @throws TooManyRowsException Primary key was not found in database.
673      */

674     public static UserPreference retrieveByPK(Integer JavaDoc pk, Connection JavaDoc con)
675         throws TorqueException, NoRowsException, TooManyRowsException
676     {
677         return retrieveByPK(SimpleKey.keyFor(pk), con);
678     }
679   
680     /**
681      * Retrieve a single object by pk
682      *
683      * @param pk the primary key
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 UserPreference retrieveByPK(ObjectKey pk)
690         throws TorqueException, NoRowsException, TooManyRowsException
691     {
692         Connection JavaDoc db = null;
693         UserPreference retVal = null;
694         try
695         {
696             db = Torque.getConnection(DATABASE_NAME);
697             retVal = retrieveByPK(pk, db);
698         }
699         finally
700         {
701             Torque.closeConnection(db);
702         }
703         return(retVal);
704     }
705
706     /**
707      * Retrieve a single object by pk
708      *
709      * @param pk the primary key
710      * @param con the connection to use
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 UserPreference retrieveByPK(ObjectKey pk, Connection JavaDoc con)
717         throws TorqueException, NoRowsException, TooManyRowsException
718     {
719         Criteria criteria = buildCriteria(pk);
720         List JavaDoc v = doSelect(criteria, con);
721         if (v.size() == 0)
722         {
723             throw new NoRowsException("Failed to select a row.");
724         }
725         else if (v.size() > 1)
726         {
727             throw new TooManyRowsException("Failed to select only one row.");
728         }
729         else
730         {
731             return (UserPreference)v.get(0);
732         }
733     }
734
735     /**
736      * Retrieve a multiple objects by pk
737      *
738      * @param pks List of primary keys
739      * @throws TorqueException Any exceptions caught during processing will be
740      * rethrown wrapped into a TorqueException.
741      */

742     public static List JavaDoc retrieveByPKs(List JavaDoc pks)
743         throws TorqueException
744     {
745         Connection JavaDoc db = null;
746         List JavaDoc retVal = null;
747         try
748         {
749            db = Torque.getConnection(DATABASE_NAME);
750            retVal = retrieveByPKs(pks, db);
751         }
752         finally
753         {
754             Torque.closeConnection(db);
755         }
756         return(retVal);
757     }
758
759     /**
760      * Retrieve a multiple objects by pk
761      *
762      * @param pks List of primary keys
763      * @param dbcon the connection to use
764      * @throws TorqueException Any exceptions caught during processing will be
765      * rethrown wrapped into a TorqueException.
766      */

767     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
768         throws TorqueException
769     {
770         List JavaDoc objs = null;
771         if (pks == null || pks.size() == 0)
772         {
773             objs = new LinkedList JavaDoc();
774         }
775         else
776         {
777             Criteria criteria = new Criteria();
778               criteria.addIn( USER_ID, pks );
779           objs = doSelect(criteria, dbcon);
780         }
781         return objs;
782     }
783
784  
785
786
787
788           
789                                               
790                         
791                 
792
793     /**
794      * selects a collection of UserPreference objects pre-filled with their
795      * ScarabUserImpl objects.
796      *
797      * This method is protected by default in order to keep the public
798      * api reasonable. You can provide public methods for those you
799      * actually need in UserPreferencePeer.
800      *
801      * @throws TorqueException Any exceptions caught during processing will be
802      * rethrown wrapped into a TorqueException.
803      */

804     protected static List JavaDoc doSelectJoinScarabUserImpl(Criteria criteria)
805         throws TorqueException
806     {
807         setDbName(criteria);
808
809         UserPreferencePeer.addSelectColumns(criteria);
810         int offset = numColumns + 1;
811         ScarabUserImplPeer.addSelectColumns(criteria);
812
813
814                         criteria.addJoin(UserPreferencePeer.USER_ID,
815             ScarabUserImplPeer.USER_ID);
816         
817
818                                                                                                   
819         List JavaDoc rows = BasePeer.doSelect(criteria);
820         List JavaDoc results = new ArrayList JavaDoc();
821
822         for (int i = 0; i < rows.size(); i++)
823         {
824             Record row = (Record) rows.get(i);
825
826                             Class JavaDoc omClass = UserPreferencePeer.getOMClass();
827                     UserPreference obj1 = (UserPreference) UserPreferencePeer
828                 .row2Object(row, 1, omClass);
829                      omClass = ScarabUserImplPeer.getOMClass();
830                     ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer
831                 .row2Object(row, offset, omClass);
832
833             boolean newObject = true;
834             for (int j = 0; j < results.size(); j++)
835             {
836                 UserPreference temp_obj1 = (UserPreference)results.get(j);
837                 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUser();
838                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
839                 {
840                     newObject = false;
841                               temp_obj2.addUserPreference(obj1);
842                               break;
843                 }
844             }
845                       if (newObject)
846             {
847                 obj2.initUserPreferences();
848                 obj2.addUserPreference(obj1);
849             }
850                       results.add(obj1);
851         }
852         return results;
853     }
854                     
855   
856     
857   
858       /**
859      * Returns the TableMap related to this peer. This method is not
860      * needed for general use but a specific application could have a need.
861      *
862      * @throws TorqueException Any exceptions caught during processing will be
863      * rethrown wrapped into a TorqueException.
864      */

865     protected static TableMap getTableMap()
866         throws TorqueException
867     {
868         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
869     }
870    
871     private static void setDbName(Criteria crit)
872     {
873         // Set the correct dbName if it has not been overridden
874
// crit.getDbName will return the same object if not set to
875
// another value so == check is okay and faster
876
if (crit.getDbName() == Torque.getDefaultDB())
877         {
878             crit.setDbName(DATABASE_NAME);
879         }
880     }
881 }
882
Popular Tags