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