KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

456      public static void doDelete(Criteria criteria) throws TorqueException
457      {
458          UserVotePeer
459             .doDelete(criteria, (Connection JavaDoc) null);
460      }
461
462     /**
463      * Method to do deletes. This method is to be used during a transaction,
464      * otherwise use the doDelete(Criteria) method. It will take care of
465      * the connection details internally.
466      *
467      * @param criteria object containing data that is used DELETE from database.
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 doDelete(Criteria criteria, Connection JavaDoc con)
473         throws TorqueException
474      {
475                           
476         setDbName(criteria);
477
478         if (con == null)
479         {
480             BasePeer.doDelete(criteria);
481         }
482         else
483         {
484             BasePeer.doDelete(criteria, con);
485         }
486      }
487
488     /**
489      * Method to do selects
490      *
491      * @throws TorqueException Any exceptions caught during processing will be
492      * rethrown wrapped into a TorqueException.
493      */

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

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

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

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

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

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

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

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

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

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

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

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

734     public static List JavaDoc retrieveByPKs( List JavaDoc pks, Connection JavaDoc dbcon )
735         throws TorqueException
736     {
737         List JavaDoc objs = null;
738         if (pks == null || pks.size() == 0)
739         {
740             objs = new LinkedList JavaDoc();
741         }
742         else
743         {
744             Criteria criteria = new Criteria();
745               Iterator JavaDoc iter = pks.iterator();
746             while (iter.hasNext())
747             {
748                 ObjectKey pk = (ObjectKey)iter.next();
749                 SimpleKey[] keys = (SimpleKey[])pk.getValue();
750                             Criteria.Criterion c0 = criteria.getNewCriterion(
751                         MODULE_ID, keys[0], Criteria.EQUAL);
752                                     Criteria.Criterion c1 = criteria.getNewCriterion(
753                         USER_ID, keys[1], Criteria.EQUAL);
754                                     c0.and(c1);
755                           criteria.or(c0);
756             }
757           objs = doSelect(criteria, dbcon);
758         }
759         return objs;
760     }
761
762  
763     /**
764      * retrieve object using using pk values.
765      *
766        * @param module_id Integer
767        * @param user_id Integer
768        */

769     public static UserVote retrieveByPK(
770        Integer JavaDoc module_id
771           , Integer JavaDoc user_id
772               ) throws TorqueException
773     {
774         Connection JavaDoc db = null;
775         UserVote retVal = null;
776         try
777         {
778            db = Torque.getConnection(DATABASE_NAME);
779            retVal = retrieveByPK(
780          module_id
781           , user_id
782                      , db);
783         }
784         finally
785         {
786             Torque.closeConnection(db);
787         }
788         return(retVal);
789     }
790
791       /**
792      * retrieve object using using pk values.
793      *
794        * @param module_id Integer
795        * @param user_id Integer
796        * @param con Connection
797      */

798     public static UserVote retrieveByPK(
799        Integer JavaDoc module_id
800           , Integer JavaDoc user_id
801              ,Connection JavaDoc con) throws TorqueException
802     {
803
804         Criteria criteria = new Criteria(5);
805           criteria.add(MODULE_ID, module_id);
806           criteria.add(USER_ID, user_id);
807           List JavaDoc v = doSelect(criteria, con);
808         if (v.size() != 1)
809         {
810             throw new TorqueException("Failed to select one and only one row.");
811         }
812         else
813         {
814             return (UserVote) v.get(0);
815         }
816     }
817
818
819
820             
821                                               
822                         
823                 
824
825     /**
826      * selects a collection of UserVote objects pre-filled with their
827      * ScarabModule objects.
828      *
829      * This method is protected by default in order to keep the public
830      * api reasonable. You can provide public methods for those you
831      * actually need in UserVotePeer.
832      *
833      * @throws TorqueException Any exceptions caught during processing will be
834      * rethrown wrapped into a TorqueException.
835      */

836     protected static List JavaDoc doSelectJoinScarabModule(Criteria criteria)
837         throws TorqueException
838     {
839         setDbName(criteria);
840
841         UserVotePeer.addSelectColumns(criteria);
842         int offset = numColumns + 1;
843         ScarabModulePeer.addSelectColumns(criteria);
844
845
846                         criteria.addJoin(UserVotePeer.MODULE_ID,
847             ScarabModulePeer.MODULE_ID);
848         
849
850                                                                                 
851         List JavaDoc rows = BasePeer.doSelect(criteria);
852         List JavaDoc results = new ArrayList JavaDoc();
853
854         for (int i = 0; i < rows.size(); i++)
855         {
856             Record row = (Record) rows.get(i);
857
858                             Class JavaDoc omClass = UserVotePeer.getOMClass();
859                     UserVote obj1 = (UserVote) UserVotePeer
860                 .row2Object(row, 1, omClass);
861                      omClass = ScarabModulePeer.getOMClass(row, offset);
862                     ScarabModule obj2 = (ScarabModule)ScarabModulePeer
863                 .row2Object(row, offset, omClass);
864
865             boolean newObject = true;
866             for (int j = 0; j < results.size(); j++)
867             {
868                 UserVote temp_obj1 = (UserVote)results.get(j);
869                 ScarabModule temp_obj2 = (ScarabModule)temp_obj1.getModule();
870                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
871                 {
872                     newObject = false;
873                               temp_obj2.addUserVote(obj1);
874                               break;
875                 }
876             }
877                       if (newObject)
878             {
879                 obj2.initUserVotes();
880                 obj2.addUserVote(obj1);
881             }
882                       results.add(obj1);
883         }
884         return results;
885     }
886                                                             
887                         
888                 
889
890     /**
891      * selects a collection of UserVote objects pre-filled with their
892      * ScarabUserImpl objects.
893      *
894      * This method is protected by default in order to keep the public
895      * api reasonable. You can provide public methods for those you
896      * actually need in UserVotePeer.
897      *
898      * @throws TorqueException Any exceptions caught during processing will be
899      * rethrown wrapped into a TorqueException.
900      */

901     protected static List JavaDoc doSelectJoinScarabUserImpl(Criteria criteria)
902         throws TorqueException
903     {
904         setDbName(criteria);
905
906         UserVotePeer.addSelectColumns(criteria);
907         int offset = numColumns + 1;
908         ScarabUserImplPeer.addSelectColumns(criteria);
909
910
911                         criteria.addJoin(UserVotePeer.USER_ID,
912             ScarabUserImplPeer.USER_ID);
913         
914
915                                                                                 
916         List JavaDoc rows = BasePeer.doSelect(criteria);
917         List JavaDoc results = new ArrayList JavaDoc();
918
919         for (int i = 0; i < rows.size(); i++)
920         {
921             Record row = (Record) rows.get(i);
922
923                             Class JavaDoc omClass = UserVotePeer.getOMClass();
924                     UserVote obj1 = (UserVote) UserVotePeer
925                 .row2Object(row, 1, omClass);
926                      omClass = ScarabUserImplPeer.getOMClass();
927                     ScarabUserImpl obj2 = (ScarabUserImpl)ScarabUserImplPeer
928                 .row2Object(row, offset, omClass);
929
930             boolean newObject = true;
931             for (int j = 0; j < results.size(); j++)
932             {
933                 UserVote temp_obj1 = (UserVote)results.get(j);
934                 ScarabUserImpl temp_obj2 = (ScarabUserImpl)temp_obj1.getScarabUser();
935                 if (temp_obj2.getPrimaryKey().equals(obj2.getPrimaryKey()))
936                 {
937                     newObject = false;
938                               temp_obj2.addUserVote(obj1);
939                               break;
940                 }
941             }
942                       if (newObject)
943             {
944                 obj2.initUserVotes();
945                 obj2.addUserVote(obj1);
946             }
947                       results.add(obj1);
948         }
949         return results;
950     }
951                     
952   
953     
954   
955       /**
956      * Returns the TableMap related to this peer. This method is not
957      * needed for general use but a specific application could have a need.
958      *
959      * @throws TorqueException Any exceptions caught during processing will be
960      * rethrown wrapped into a TorqueException.
961      */

962     protected static TableMap getTableMap()
963         throws TorqueException
964     {
965         return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
966     }
967    
968     private static void setDbName(Criteria crit)
969     {
970         // Set the correct dbName if it has not been overridden
971
// crit.getDbName will return the same object if not set to
972
// another value so == check is okay and faster
973
if (crit.getDbName() == Torque.getDefaultDB())
974         {
975             crit.setDbName(DATABASE_NAME);
976         }
977     }
978 }
979
Popular Tags