001: package org.tigris.scarab.om;
002:
003: import java.math.BigDecimal;
004: import java.sql.Connection;
005: import java.sql.SQLException;
006: import java.util.ArrayList;
007: import java.util.Date;
008: import java.util.Iterator;
009: import java.util.LinkedList;
010: import java.util.List;
011:
012: import org.apache.torque.NoRowsException;
013: import org.apache.torque.TooManyRowsException;
014: import org.apache.torque.Torque;
015: import org.apache.torque.TorqueException;
016: import org.apache.torque.map.MapBuilder;
017: import org.apache.torque.map.TableMap;
018: import org.apache.torque.om.DateKey;
019: import org.apache.torque.om.NumberKey;
020: import org.apache.torque.om.StringKey;
021: import org.apache.torque.om.ObjectKey;
022: import org.apache.torque.om.SimpleKey;
023: import org.apache.torque.util.BasePeer;
024: import org.apache.torque.util.Criteria;
025:
026: import com.workingdogs.village.DataSetException;
027: import com.workingdogs.village.QueryDataSet;
028: import com.workingdogs.village.Record;
029:
030: // Local classes
031: import org.tigris.scarab.om.map.*;
032:
033: /**
034: */
035: public abstract class BaseUserVotePeer extends BasePeer {
036:
037: /** the default database name for this class */
038: public static final String DATABASE_NAME = "scarab";
039:
040: /** the table name for this class */
041: public static final String TABLE_NAME = "SCARAB_USER_VOTE";
042:
043: /**
044: * @return the map builder for this peer
045: * @throws TorqueException Any exceptions caught during processing will be
046: * rethrown wrapped into a TorqueException.
047: */
048: public static MapBuilder getMapBuilder() throws TorqueException {
049: return getMapBuilder(UserVoteMapBuilder.CLASS_NAME);
050: }
051:
052: /** the column name for the MODULE_ID field */
053: public static final String MODULE_ID;
054: /** the column name for the USER_ID field */
055: public static final String USER_ID;
056: /** the column name for the TOTAL_VOTES field */
057: public static final String TOTAL_VOTES;
058: /** the column name for the USED_VOTES field */
059: public static final String USED_VOTES;
060:
061: static {
062: MODULE_ID = "SCARAB_USER_VOTE.MODULE_ID";
063: USER_ID = "SCARAB_USER_VOTE.USER_ID";
064: TOTAL_VOTES = "SCARAB_USER_VOTE.TOTAL_VOTES";
065: USED_VOTES = "SCARAB_USER_VOTE.USED_VOTES";
066: if (Torque.isInit()) {
067: try {
068: getMapBuilder(UserVoteMapBuilder.CLASS_NAME);
069: } catch (Exception e) {
070: log.error("Could not initialize Peer", e);
071: throw new RuntimeException(e);
072: }
073: } else {
074: Torque.registerMapBuilder(UserVoteMapBuilder.CLASS_NAME);
075: }
076: }
077:
078: /** number of columns for this peer */
079: public static final int numColumns = 4;
080:
081: /** A class that can be returned by this peer. */
082: protected static final String CLASSNAME_DEFAULT = "org.tigris.scarab.om.UserVote";
083:
084: /** A class that can be returned by this peer. */
085: protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
086:
087: /**
088: * Class object initialization method.
089: *
090: * @param className name of the class to initialize
091: * @return the initialized class
092: */
093: private static Class initClass(String className) {
094: Class c = null;
095: try {
096: c = Class.forName(className);
097: } catch (Throwable t) {
098: log
099: .error(
100: "A FATAL ERROR has occurred which should not "
101: + "have happened under any circumstance. Please notify "
102: + "the Torque developers <torque-dev@db.apache.org> "
103: + "and give as many details as possible (including the error "
104: + "stack trace).", t);
105:
106: // Error objects should always be propogated.
107: if (t instanceof Error) {
108: throw (Error) t.fillInStackTrace();
109: }
110: }
111: return c;
112: }
113:
114: /**
115: * Get the list of objects for a ResultSet. Please not that your
116: * resultset MUST return columns in the right order. You can use
117: * getFieldNames() in BaseObject to get the correct sequence.
118: *
119: * @param results the ResultSet
120: * @return the list of objects
121: * @throws TorqueException Any exceptions caught during processing will be
122: * rethrown wrapped into a TorqueException.
123: */
124: public static List resultSet2Objects(java.sql.ResultSet results)
125: throws TorqueException {
126: try {
127: QueryDataSet qds = null;
128: List rows = null;
129: try {
130: qds = new QueryDataSet(results);
131: rows = getSelectResults(qds);
132: } finally {
133: if (qds != null) {
134: qds.close();
135: }
136: }
137:
138: return populateObjects(rows);
139: } catch (SQLException e) {
140: throw new TorqueException(e);
141: } catch (DataSetException e) {
142: throw new TorqueException(e);
143: }
144: }
145:
146: /**
147: * Method to do inserts.
148: *
149: * @param criteria object used to create the INSERT statement.
150: * @throws TorqueException Any exceptions caught during processing will be
151: * rethrown wrapped into a TorqueException.
152: */
153: public static ObjectKey doInsert(Criteria criteria)
154: throws TorqueException {
155: return BaseUserVotePeer.doInsert(criteria, (Connection) null);
156: }
157:
158: /**
159: * Method to do inserts. This method is to be used during a transaction,
160: * otherwise use the doInsert(Criteria) method. It will take care of
161: * the connection details internally.
162: *
163: * @param criteria object used to create the INSERT statement.
164: * @param con the connection to use
165: * @throws TorqueException Any exceptions caught during processing will be
166: * rethrown wrapped into a TorqueException.
167: */
168: public static ObjectKey doInsert(Criteria criteria, Connection con)
169: throws TorqueException {
170: correctBooleans(criteria);
171:
172: setDbName(criteria);
173:
174: if (con == null) {
175: return BasePeer.doInsert(criteria);
176: } else {
177: return BasePeer.doInsert(criteria, con);
178: }
179: }
180:
181: /**
182: * Add all the columns needed to create a new object.
183: *
184: * @param criteria object containing the columns to add.
185: * @throws TorqueException Any exceptions caught during processing will be
186: * rethrown wrapped into a TorqueException.
187: */
188: public static void addSelectColumns(Criteria criteria)
189: throws TorqueException {
190: criteria.addSelectColumn(MODULE_ID);
191: criteria.addSelectColumn(USER_ID);
192: criteria.addSelectColumn(TOTAL_VOTES);
193: criteria.addSelectColumn(USED_VOTES);
194: }
195:
196: /**
197: * changes the boolean values in the criteria to the appropriate type,
198: * whenever a booleanchar or booleanint column is involved.
199: * This enables the user to create criteria using Boolean values
200: * for booleanchar or booleanint columns
201: * @param criteria the criteria in which the boolean values should be corrected
202: */
203: public static void correctBooleans(Criteria criteria) {
204: }
205:
206: /**
207: * Create a new object of type cls from a resultset row starting
208: * from a specified offset. This is done so that you can select
209: * other rows than just those needed for this object. You may
210: * for example want to create two objects from the same row.
211: *
212: * @throws TorqueException Any exceptions caught during processing will be
213: * rethrown wrapped into a TorqueException.
214: */
215: public static UserVote row2Object(Record row, int offset, Class cls)
216: throws TorqueException {
217: try {
218: UserVote obj = (UserVote) cls.newInstance();
219: UserVotePeer.populateObject(row, offset, obj);
220: obj.setModified(false);
221: obj.setNew(false);
222:
223: return obj;
224: } catch (InstantiationException e) {
225: throw new TorqueException(e);
226: } catch (IllegalAccessException e) {
227: throw new TorqueException(e);
228: }
229: }
230:
231: /**
232: * Populates an object 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 void populateObject(Record row, int offset,
241: UserVote obj) throws TorqueException {
242: try {
243: obj.setModuleId(row.getValue(offset + 0).asIntegerObj());
244: obj.setUserId(row.getValue(offset + 1).asIntegerObj());
245: obj.setTotalVotes(row.getValue(offset + 2).asInt());
246: obj.setUsedVotes(row.getValue(offset + 3).asInt());
247: } catch (DataSetException e) {
248: throw new TorqueException(e);
249: }
250: }
251:
252: /**
253: * Method to do selects.
254: *
255: * @param criteria object used to create the SELECT statement.
256: * @return List of selected Objects
257: * @throws TorqueException Any exceptions caught during processing will be
258: * rethrown wrapped into a TorqueException.
259: */
260: public static List doSelect(Criteria criteria)
261: throws TorqueException {
262: return populateObjects(doSelectVillageRecords(criteria));
263: }
264:
265: /**
266: * Method to do selects within a transaction.
267: *
268: * @param criteria object used to create the SELECT statement.
269: * @param con the connection to use
270: * @return List of selected Objects
271: * @throws TorqueException Any exceptions caught during processing will be
272: * rethrown wrapped into a TorqueException.
273: */
274: public static List doSelect(Criteria criteria, Connection con)
275: throws TorqueException {
276: return populateObjects(doSelectVillageRecords(criteria, con));
277: }
278:
279: /**
280: * Grabs the raw Village records to be formed into objects.
281: * This method handles connections internally. The Record objects
282: * returned by this method should be considered readonly. Do not
283: * alter the data and call save(), your results may vary, but are
284: * certainly likely to result in hard to track MT bugs.
285: *
286: * @throws TorqueException Any exceptions caught during processing will be
287: * rethrown wrapped into a TorqueException.
288: */
289: public static List doSelectVillageRecords(Criteria criteria)
290: throws TorqueException {
291: return BaseUserVotePeer.doSelectVillageRecords(criteria,
292: (Connection) null);
293: }
294:
295: /**
296: * Grabs the raw Village records to be formed into objects.
297: * This method should be used for transactions
298: *
299: * @param criteria object used to create the SELECT statement.
300: * @param con the connection to use
301: * @throws TorqueException Any exceptions caught during processing will be
302: * rethrown wrapped into a TorqueException.
303: */
304: public static List doSelectVillageRecords(Criteria criteria,
305: Connection con) throws TorqueException {
306: if (criteria.getSelectColumns().size() == 0) {
307: addSelectColumns(criteria);
308: }
309: correctBooleans(criteria);
310:
311: setDbName(criteria);
312:
313: // BasePeer returns a List of Value (Village) arrays. The array
314: // order follows the order columns were placed in the Select clause.
315: if (con == null) {
316: return BasePeer.doSelect(criteria);
317: } else {
318: return BasePeer.doSelect(criteria, con);
319: }
320: }
321:
322: /**
323: * The returned List will contain objects of the default type or
324: * objects that inherit from the default.
325: *
326: * @throws TorqueException Any exceptions caught during processing will be
327: * rethrown wrapped into a TorqueException.
328: */
329: public static List populateObjects(List records)
330: throws TorqueException {
331: List results = new ArrayList(records.size());
332:
333: // populate the object(s)
334: for (int i = 0; i < records.size(); i++) {
335: Record row = (Record) records.get(i);
336: results.add(UserVotePeer.row2Object(row, 1, UserVotePeer
337: .getOMClass()));
338: }
339: return results;
340: }
341:
342: /**
343: * The class that the Peer will make instances of.
344: * If the BO is abstract then you must implement this method
345: * in the BO.
346: *
347: * @throws TorqueException Any exceptions caught during processing will be
348: * rethrown wrapped into a TorqueException.
349: */
350: public static Class getOMClass() throws TorqueException {
351: return CLASS_DEFAULT;
352: }
353:
354: /**
355: * Method to do updates.
356: *
357: * @param criteria object containing data that is used to create the UPDATE
358: * statement.
359: * @throws TorqueException Any exceptions caught during processing will be
360: * rethrown wrapped into a TorqueException.
361: */
362: public static void doUpdate(Criteria criteria)
363: throws TorqueException {
364: BaseUserVotePeer.doUpdate(criteria, (Connection) null);
365: }
366:
367: /**
368: * Method to do updates. This method is to be used during a transaction,
369: * otherwise use the doUpdate(Criteria) method. It will take care of
370: * the connection details internally.
371: *
372: * @param criteria object containing data that is used to create the UPDATE
373: * statement.
374: * @param con the connection to use
375: * @throws TorqueException Any exceptions caught during processing will be
376: * rethrown wrapped into a TorqueException.
377: */
378: public static void doUpdate(Criteria criteria, Connection con)
379: throws TorqueException {
380: Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
381: correctBooleans(criteria);
382:
383: selectCriteria.put(MODULE_ID, criteria.remove(MODULE_ID));
384:
385: selectCriteria.put(USER_ID, criteria.remove(USER_ID));
386:
387: setDbName(criteria);
388:
389: if (con == null) {
390: BasePeer.doUpdate(selectCriteria, criteria);
391: } else {
392: BasePeer.doUpdate(selectCriteria, criteria, con);
393: }
394: }
395:
396: /**
397: * Method to do deletes.
398: *
399: * @param criteria object containing data that is used DELETE from database.
400: * @throws TorqueException Any exceptions caught during processing will be
401: * rethrown wrapped into a TorqueException.
402: */
403: public static void doDelete(Criteria criteria)
404: throws TorqueException {
405: UserVotePeer.doDelete(criteria, (Connection) null);
406: }
407:
408: /**
409: * Method to do deletes. This method is to be used during a transaction,
410: * otherwise use the doDelete(Criteria) method. It will take care of
411: * the connection details internally.
412: *
413: * @param criteria object containing data that is used DELETE from database.
414: * @param con the connection to use
415: * @throws TorqueException Any exceptions caught during processing will be
416: * rethrown wrapped into a TorqueException.
417: */
418: public static void doDelete(Criteria criteria, Connection con)
419: throws TorqueException {
420: correctBooleans(criteria);
421:
422: setDbName(criteria);
423:
424: if (con == null) {
425: BasePeer.doDelete(criteria);
426: } else {
427: BasePeer.doDelete(criteria, con);
428: }
429: }
430:
431: /**
432: * Method to do selects
433: *
434: * @throws TorqueException Any exceptions caught during processing will be
435: * rethrown wrapped into a TorqueException.
436: */
437: public static List doSelect(UserVote obj) throws TorqueException {
438: return doSelect(buildSelectCriteria(obj));
439: }
440:
441: /**
442: * Method to do inserts
443: *
444: * @throws TorqueException Any exceptions caught during processing will be
445: * rethrown wrapped into a TorqueException.
446: */
447: public static void doInsert(UserVote obj) throws TorqueException {
448: doInsert(buildCriteria(obj));
449: obj.setNew(false);
450: obj.setModified(false);
451: }
452:
453: /**
454: * @param obj the data object to update in the database.
455: * @throws TorqueException Any exceptions caught during processing will be
456: * rethrown wrapped into a TorqueException.
457: */
458: public static void doUpdate(UserVote obj) throws TorqueException {
459: doUpdate(buildCriteria(obj));
460: obj.setModified(false);
461: }
462:
463: /**
464: * @param obj the data object to delete in the database.
465: * @throws TorqueException Any exceptions caught during processing will be
466: * rethrown wrapped into a TorqueException.
467: */
468: public static void doDelete(UserVote obj) throws TorqueException {
469: doDelete(buildSelectCriteria(obj));
470: }
471:
472: /**
473: * Method to do inserts. This method is to be used during a transaction,
474: * otherwise use the doInsert(UserVote) method. It will take
475: * care of the connection details internally.
476: *
477: * @param obj the data object to insert into the database.
478: * @param con the connection to use
479: * @throws TorqueException Any exceptions caught during processing will be
480: * rethrown wrapped into a TorqueException.
481: */
482: public static void doInsert(UserVote obj, Connection con)
483: throws TorqueException {
484: doInsert(buildCriteria(obj), con);
485: obj.setNew(false);
486: obj.setModified(false);
487: }
488:
489: /**
490: * Method to do update. This method is to be used during a transaction,
491: * otherwise use the doUpdate(UserVote) method. It will take
492: * care of the connection details internally.
493: *
494: * @param obj the data object to update in the database.
495: * @param con the connection to use
496: * @throws TorqueException Any exceptions caught during processing will be
497: * rethrown wrapped into a TorqueException.
498: */
499: public static void doUpdate(UserVote obj, Connection con)
500: throws TorqueException {
501: doUpdate(buildCriteria(obj), con);
502: obj.setModified(false);
503: }
504:
505: /**
506: * Method to delete. This method is to be used during a transaction,
507: * otherwise use the doDelete(UserVote) method. It will take
508: * care of the connection details internally.
509: *
510: * @param obj the data object to delete in the database.
511: * @param con the connection to use
512: * @throws TorqueException Any exceptions caught during processing will be
513: * rethrown wrapped into a TorqueException.
514: */
515: public static void doDelete(UserVote obj, Connection con)
516: throws TorqueException {
517: doDelete(buildSelectCriteria(obj), con);
518: }
519:
520: /**
521: * Method to do deletes.
522: *
523: * @param pk ObjectKey that is used DELETE from database.
524: * @throws TorqueException Any exceptions caught during processing will be
525: * rethrown wrapped into a TorqueException.
526: */
527: public static void doDelete(ObjectKey pk) throws TorqueException {
528: BaseUserVotePeer.doDelete(pk, (Connection) null);
529: }
530:
531: /**
532: * Method to delete. This method is to be used during a transaction,
533: * otherwise use the doDelete(ObjectKey) method. It will take
534: * care of the connection details internally.
535: *
536: * @param pk the primary key for the object to delete in the database.
537: * @param con the connection to use
538: * @throws TorqueException Any exceptions caught during processing will be
539: * rethrown wrapped into a TorqueException.
540: */
541: public static void doDelete(ObjectKey pk, Connection con)
542: throws TorqueException {
543: doDelete(buildCriteria(pk), con);
544: }
545:
546: /** Build a Criteria object from an ObjectKey */
547: public static Criteria buildCriteria(ObjectKey pk) {
548: Criteria criteria = new Criteria();
549: SimpleKey[] keys = (SimpleKey[]) pk.getValue();
550: criteria.add(MODULE_ID, keys[0]);
551: criteria.add(USER_ID, keys[1]);
552: return criteria;
553: }
554:
555: /** Build a Criteria object from the data object for this peer */
556: public static Criteria buildCriteria(UserVote obj) {
557: Criteria criteria = new Criteria(DATABASE_NAME);
558: criteria.add(MODULE_ID, obj.getModuleId());
559: criteria.add(USER_ID, obj.getUserId());
560: criteria.add(TOTAL_VOTES, obj.getTotalVotes());
561: criteria.add(USED_VOTES, obj.getUsedVotes());
562: return criteria;
563: }
564:
565: /** Build a Criteria object from the data object for this peer, skipping all binary columns */
566: public static Criteria buildSelectCriteria(UserVote obj) {
567: Criteria criteria = new Criteria(DATABASE_NAME);
568: criteria.add(MODULE_ID, obj.getModuleId());
569: criteria.add(USER_ID, obj.getUserId());
570: criteria.add(TOTAL_VOTES, obj.getTotalVotes());
571: criteria.add(USED_VOTES, obj.getUsedVotes());
572: return criteria;
573: }
574:
575: /**
576: * Retrieve a single object by pk
577: *
578: * @param pk the primary key
579: * @throws TorqueException Any exceptions caught during processing will be
580: * rethrown wrapped into a TorqueException.
581: * @throws NoRowsException Primary key was not found in database.
582: * @throws TooManyRowsException Primary key was not found in database.
583: */
584: public static UserVote retrieveByPK(ObjectKey pk)
585: throws TorqueException, NoRowsException,
586: TooManyRowsException {
587: Connection db = null;
588: UserVote retVal = null;
589: try {
590: db = Torque.getConnection(DATABASE_NAME);
591: retVal = retrieveByPK(pk, db);
592: } finally {
593: Torque.closeConnection(db);
594: }
595: return retVal;
596: }
597:
598: /**
599: * Retrieve a single object by pk
600: *
601: * @param pk the primary key
602: * @param con the connection to use
603: * @throws TorqueException Any exceptions caught during processing will be
604: * rethrown wrapped into a TorqueException.
605: * @throws NoRowsException Primary key was not found in database.
606: * @throws TooManyRowsException Primary key was not found in database.
607: */
608: public static UserVote retrieveByPK(ObjectKey pk, Connection con)
609: throws TorqueException, NoRowsException,
610: TooManyRowsException {
611: Criteria criteria = buildCriteria(pk);
612: List v = doSelect(criteria, con);
613: if (v.size() == 0) {
614: throw new NoRowsException("Failed to select a row.");
615: } else if (v.size() > 1) {
616: throw new TooManyRowsException(
617: "Failed to select only one row.");
618: } else {
619: return (UserVote) v.get(0);
620: }
621: }
622:
623: /**
624: * Retrieve a multiple objects by pk
625: *
626: * @param pks List of primary keys
627: * @throws TorqueException Any exceptions caught during processing will be
628: * rethrown wrapped into a TorqueException.
629: */
630: public static List retrieveByPKs(List pks) throws TorqueException {
631: Connection db = null;
632: List retVal = null;
633: try {
634: db = Torque.getConnection(DATABASE_NAME);
635: retVal = retrieveByPKs(pks, db);
636: } finally {
637: Torque.closeConnection(db);
638: }
639: return retVal;
640: }
641:
642: /**
643: * Retrieve a multiple objects by pk
644: *
645: * @param pks List of primary keys
646: * @param dbcon the connection to use
647: * @throws TorqueException Any exceptions caught during processing will be
648: * rethrown wrapped into a TorqueException.
649: */
650: public static List retrieveByPKs(List pks, Connection dbcon)
651: throws TorqueException {
652: List objs = null;
653: if (pks == null || pks.size() == 0) {
654: objs = new LinkedList();
655: } else {
656: Criteria criteria = new Criteria();
657: Iterator iter = pks.iterator();
658: while (iter.hasNext()) {
659: ObjectKey pk = (ObjectKey) iter.next();
660: SimpleKey[] keys = (SimpleKey[]) pk.getValue();
661: Criteria.Criterion c0 = criteria.getNewCriterion(
662: MODULE_ID, keys[0], Criteria.EQUAL);
663: Criteria.Criterion c1 = criteria.getNewCriterion(
664: USER_ID, keys[1], Criteria.EQUAL);
665: c0.and(c1);
666: criteria.or(c0);
667: }
668: objs = doSelect(criteria, dbcon);
669: }
670: return objs;
671: }
672:
673: /**
674: * retrieve object using using pk values.
675: *
676: * @param module_id Integer
677: * @param user_id Integer
678: */
679: public static UserVote retrieveByPK(Integer module_id,
680: Integer user_id) throws TorqueException {
681: Connection db = null;
682: UserVote retVal = null;
683: try {
684: db = Torque.getConnection(DATABASE_NAME);
685: retVal = retrieveByPK(module_id, user_id, db);
686: } finally {
687: Torque.closeConnection(db);
688: }
689: return retVal;
690: }
691:
692: /**
693: * retrieve object using using pk values.
694: *
695: * @param module_id Integer
696: * @param user_id Integer
697: * @param con Connection
698: */
699: public static UserVote retrieveByPK(Integer module_id,
700: Integer user_id, Connection con) throws TorqueException {
701:
702: Criteria criteria = new Criteria(5);
703: criteria.add(MODULE_ID, module_id);
704: criteria.add(USER_ID, user_id);
705: List v = doSelect(criteria, con);
706: if (v.size() == 1) {
707: return (UserVote) v.get(0);
708: } else {
709: throw new TorqueException(
710: "Failed to select one and only one row.");
711: }
712: }
713:
714: /**
715: * selects a collection of UserVote objects pre-filled with their
716: * ScarabModule objects.
717: *
718: * This method is protected by default in order to keep the public
719: * api reasonable. You can provide public methods for those you
720: * actually need in UserVotePeer.
721: *
722: * @throws TorqueException Any exceptions caught during processing will be
723: * rethrown wrapped into a TorqueException.
724: */
725: protected static List doSelectJoinScarabModule(Criteria criteria)
726: throws TorqueException {
727: return doSelectJoinScarabModule(criteria, null);
728: }
729:
730: /**
731: * selects a collection of UserVote objects pre-filled with their
732: * ScarabModule objects.
733: *
734: * This method is protected by default in order to keep the public
735: * api reasonable. You can provide public methods for those you
736: * actually need in UserVotePeer.
737: *
738: * @throws TorqueException Any exceptions caught during processing will be
739: * rethrown wrapped into a TorqueException.
740: */
741: protected static List doSelectJoinScarabModule(Criteria criteria,
742: Connection conn) throws TorqueException {
743: setDbName(criteria);
744:
745: UserVotePeer.addSelectColumns(criteria);
746: int offset = numColumns + 1;
747: ScarabModulePeer.addSelectColumns(criteria);
748:
749: criteria.addJoin(UserVotePeer.MODULE_ID,
750: ScarabModulePeer.MODULE_ID);
751:
752: correctBooleans(criteria);
753:
754: List rows;
755: if (conn == null) {
756: rows = BasePeer.doSelect(criteria);
757: } else {
758: rows = BasePeer.doSelect(criteria, conn);
759: }
760:
761: List results = new ArrayList();
762:
763: for (int i = 0; i < rows.size(); i++) {
764: Record row = (Record) rows.get(i);
765:
766: Class omClass = UserVotePeer.getOMClass();
767: UserVote obj1 = (UserVote) UserVotePeer.row2Object(row, 1,
768: omClass);
769: omClass = ScarabModulePeer.getOMClass(row, offset);
770: ScarabModule obj2 = (ScarabModule) ScarabModulePeer
771: .row2Object(row, offset, omClass);
772:
773: boolean newObject = true;
774: for (int j = 0; j < results.size(); j++) {
775: UserVote temp_obj1 = (UserVote) results.get(j);
776: ScarabModule temp_obj2 = (ScarabModule) temp_obj1
777: .getModule();
778: if (temp_obj2.getPrimaryKey().equals(
779: obj2.getPrimaryKey())) {
780: newObject = false;
781: temp_obj2.addUserVote(obj1);
782: break;
783: }
784: }
785: if (newObject) {
786: obj2.initUserVotes();
787: obj2.addUserVote(obj1);
788: }
789: results.add(obj1);
790: }
791: return results;
792: }
793:
794: /**
795: * selects a collection of UserVote objects pre-filled with their
796: * ScarabUserImpl objects.
797: *
798: * This method is protected by default in order to keep the public
799: * api reasonable. You can provide public methods for those you
800: * actually need in UserVotePeer.
801: *
802: * @throws TorqueException Any exceptions caught during processing will be
803: * rethrown wrapped into a TorqueException.
804: */
805: protected static List doSelectJoinScarabUserImpl(Criteria criteria)
806: throws TorqueException {
807: return doSelectJoinScarabUserImpl(criteria, null);
808: }
809:
810: /**
811: * selects a collection of UserVote objects pre-filled with their
812: * ScarabUserImpl objects.
813: *
814: * This method is protected by default in order to keep the public
815: * api reasonable. You can provide public methods for those you
816: * actually need in UserVotePeer.
817: *
818: * @throws TorqueException Any exceptions caught during processing will be
819: * rethrown wrapped into a TorqueException.
820: */
821: protected static List doSelectJoinScarabUserImpl(Criteria criteria,
822: Connection conn) throws TorqueException {
823: setDbName(criteria);
824:
825: UserVotePeer.addSelectColumns(criteria);
826: int offset = numColumns + 1;
827: ScarabUserImplPeer.addSelectColumns(criteria);
828:
829: criteria.addJoin(UserVotePeer.USER_ID,
830: ScarabUserImplPeer.USER_ID);
831:
832: correctBooleans(criteria);
833:
834: List rows;
835: if (conn == null) {
836: rows = BasePeer.doSelect(criteria);
837: } else {
838: rows = BasePeer.doSelect(criteria, conn);
839: }
840:
841: List results = new ArrayList();
842:
843: for (int i = 0; i < rows.size(); i++) {
844: Record row = (Record) rows.get(i);
845:
846: Class omClass = UserVotePeer.getOMClass();
847: UserVote obj1 = (UserVote) UserVotePeer.row2Object(row, 1,
848: omClass);
849: omClass = ScarabUserImplPeer.getOMClass();
850: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
851: .row2Object(row, offset, omClass);
852:
853: boolean newObject = true;
854: for (int j = 0; j < results.size(); j++) {
855: UserVote temp_obj1 = (UserVote) results.get(j);
856: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
857: .getScarabUser();
858: if (temp_obj2.getPrimaryKey().equals(
859: obj2.getPrimaryKey())) {
860: newObject = false;
861: temp_obj2.addUserVote(obj1);
862: break;
863: }
864: }
865: if (newObject) {
866: obj2.initUserVotes();
867: obj2.addUserVote(obj1);
868: }
869: results.add(obj1);
870: }
871: return results;
872: }
873:
874: /**
875: * Returns the TableMap related to this peer. This method is not
876: * needed for general use but a specific application could have a need.
877: *
878: * @throws TorqueException Any exceptions caught during processing will be
879: * rethrown wrapped into a TorqueException.
880: */
881: protected static TableMap getTableMap() throws TorqueException {
882: return Torque.getDatabaseMap(DATABASE_NAME)
883: .getTable(TABLE_NAME);
884: }
885:
886: private static void setDbName(Criteria crit) {
887: // Set the correct dbName if it has not been overridden
888: // crit.getDbName will return the same object if not set to
889: // another value so == check is okay and faster
890: if (crit.getDbName() == Torque.getDefaultDB()) {
891: crit.setDbName(DATABASE_NAME);
892: }
893: }
894: }
|