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