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