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