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