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 BaseAttributeGroupPeer 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_ATTRIBUTE_GROUP";
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(AttributeGroupMapBuilder.CLASS_NAME);
050: }
051:
052: /** the column name for the ATTRIBUTE_GROUP_ID field */
053: public static final String ATTRIBUTE_GROUP_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 MODULE_ID field */
059: public static final String MODULE_ID;
060: /** the column name for the ISSUE_TYPE_ID field */
061: public static final String ISSUE_TYPE_ID;
062: /** the column name for the ACTIVE field */
063: public static final String ACTIVE;
064: /** the column name for the DEDUPE field */
065: public static final String DEDUPE;
066: /** the column name for the PREFERRED_ORDER field */
067: public static final String PREFERRED_ORDER;
068:
069: static {
070: ATTRIBUTE_GROUP_ID = "SCARAB_ATTRIBUTE_GROUP.ATTRIBUTE_GROUP_ID";
071: NAME = "SCARAB_ATTRIBUTE_GROUP.NAME";
072: DESCRIPTION = "SCARAB_ATTRIBUTE_GROUP.DESCRIPTION";
073: MODULE_ID = "SCARAB_ATTRIBUTE_GROUP.MODULE_ID";
074: ISSUE_TYPE_ID = "SCARAB_ATTRIBUTE_GROUP.ISSUE_TYPE_ID";
075: ACTIVE = "SCARAB_ATTRIBUTE_GROUP.ACTIVE";
076: DEDUPE = "SCARAB_ATTRIBUTE_GROUP.DEDUPE";
077: PREFERRED_ORDER = "SCARAB_ATTRIBUTE_GROUP.PREFERRED_ORDER";
078: if (Torque.isInit()) {
079: try {
080: getMapBuilder(AttributeGroupMapBuilder.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(AttributeGroupMapBuilder.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.AttributeGroup";
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 BaseAttributeGroupPeer.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_GROUP_ID);
205: criteria.addSelectColumn(NAME);
206: criteria.addSelectColumn(DESCRIPTION);
207: criteria.addSelectColumn(MODULE_ID);
208: criteria.addSelectColumn(ISSUE_TYPE_ID);
209: criteria.addSelectColumn(ACTIVE);
210: criteria.addSelectColumn(DEDUPE);
211: criteria.addSelectColumn(PREFERRED_ORDER);
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(DEDUPE)) {
232: Object possibleBoolean = criteria.get(DEDUPE);
233: if (possibleBoolean instanceof Boolean) {
234: criteria.add(DEDUPE, ((Boolean) possibleBoolean)
235: .booleanValue() ? 1 : 0);
236: }
237: }
238: }
239:
240: /**
241: * Create a new object of type cls from a resultset row starting
242: * from a specified offset. This is done so that you can select
243: * other rows than just those needed for this object. You may
244: * for example want to create two objects from the same row.
245: *
246: * @throws TorqueException Any exceptions caught during processing will be
247: * rethrown wrapped into a TorqueException.
248: */
249: public static AttributeGroup row2Object(Record row, int offset,
250: Class cls) throws TorqueException {
251: try {
252: AttributeGroup obj = (AttributeGroup) cls.newInstance();
253: AttributeGroupPeer.populateObject(row, offset, obj);
254: obj.setModified(false);
255: obj.setNew(false);
256:
257: return obj;
258: } catch (InstantiationException e) {
259: throw new TorqueException(e);
260: } catch (IllegalAccessException e) {
261: throw new TorqueException(e);
262: }
263: }
264:
265: /**
266: * Populates an object 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 void populateObject(Record row, int offset,
275: AttributeGroup obj) throws TorqueException {
276: try {
277: obj.setAttributeGroupId(row.getValue(offset + 0)
278: .asIntegerObj());
279: obj.setName(row.getValue(offset + 1).asString());
280: obj.setDescription(row.getValue(offset + 2).asString());
281: obj.setModuleId(row.getValue(offset + 3).asIntegerObj());
282: obj.setIssueTypeId(row.getValue(offset + 4).asIntegerObj());
283: obj.setActive(row.getValue(offset + 5).asBoolean());
284: obj.setDedupe(row.getValue(offset + 6).asBoolean());
285: obj.setOrder(row.getValue(offset + 7).asInt());
286: } catch (DataSetException e) {
287: throw new TorqueException(e);
288: }
289: }
290:
291: /**
292: * Method to do selects.
293: *
294: * @param criteria object used to create the SELECT statement.
295: * @return List of selected Objects
296: * @throws TorqueException Any exceptions caught during processing will be
297: * rethrown wrapped into a TorqueException.
298: */
299: public static List doSelect(Criteria criteria)
300: throws TorqueException {
301: return populateObjects(doSelectVillageRecords(criteria));
302: }
303:
304: /**
305: * Method to do selects within a transaction.
306: *
307: * @param criteria object used to create the SELECT statement.
308: * @param con the connection to use
309: * @return List of selected Objects
310: * @throws TorqueException Any exceptions caught during processing will be
311: * rethrown wrapped into a TorqueException.
312: */
313: public static List doSelect(Criteria criteria, Connection con)
314: throws TorqueException {
315: return populateObjects(doSelectVillageRecords(criteria, con));
316: }
317:
318: /**
319: * Grabs the raw Village records to be formed into objects.
320: * This method handles connections internally. The Record objects
321: * returned by this method should be considered readonly. Do not
322: * alter the data and call save(), your results may vary, but are
323: * certainly likely to result in hard to track MT bugs.
324: *
325: * @throws TorqueException Any exceptions caught during processing will be
326: * rethrown wrapped into a TorqueException.
327: */
328: public static List doSelectVillageRecords(Criteria criteria)
329: throws TorqueException {
330: return BaseAttributeGroupPeer.doSelectVillageRecords(criteria,
331: (Connection) null);
332: }
333:
334: /**
335: * Grabs the raw Village records to be formed into objects.
336: * This method should be used for transactions
337: *
338: * @param criteria object used to create the SELECT statement.
339: * @param con the connection to use
340: * @throws TorqueException Any exceptions caught during processing will be
341: * rethrown wrapped into a TorqueException.
342: */
343: public static List doSelectVillageRecords(Criteria criteria,
344: Connection con) throws TorqueException {
345: if (criteria.getSelectColumns().size() == 0) {
346: addSelectColumns(criteria);
347: }
348: correctBooleans(criteria);
349:
350: setDbName(criteria);
351:
352: // BasePeer returns a List of Value (Village) arrays. The array
353: // order follows the order columns were placed in the Select clause.
354: if (con == null) {
355: return BasePeer.doSelect(criteria);
356: } else {
357: return BasePeer.doSelect(criteria, con);
358: }
359: }
360:
361: /**
362: * The returned List will contain objects of the default type or
363: * objects that inherit from the default.
364: *
365: * @throws TorqueException Any exceptions caught during processing will be
366: * rethrown wrapped into a TorqueException.
367: */
368: public static List populateObjects(List records)
369: throws TorqueException {
370: List results = new ArrayList(records.size());
371:
372: // populate the object(s)
373: for (int i = 0; i < records.size(); i++) {
374: Record row = (Record) records.get(i);
375: results.add(AttributeGroupPeer.row2Object(row, 1,
376: AttributeGroupPeer.getOMClass()));
377: }
378: return results;
379: }
380:
381: /**
382: * The class that the Peer will make instances of.
383: * If the BO is abstract then you must implement this method
384: * in the BO.
385: *
386: * @throws TorqueException Any exceptions caught during processing will be
387: * rethrown wrapped into a TorqueException.
388: */
389: public static Class getOMClass() throws TorqueException {
390: return CLASS_DEFAULT;
391: }
392:
393: /**
394: * Method to do updates.
395: *
396: * @param criteria object containing data that is used to create the UPDATE
397: * statement.
398: * @throws TorqueException Any exceptions caught during processing will be
399: * rethrown wrapped into a TorqueException.
400: */
401: public static void doUpdate(Criteria criteria)
402: throws TorqueException {
403: BaseAttributeGroupPeer.doUpdate(criteria, (Connection) null);
404: }
405:
406: /**
407: * Method to do updates. This method is to be used during a transaction,
408: * otherwise use the doUpdate(Criteria) method. It will take care of
409: * the connection details internally.
410: *
411: * @param criteria object containing data that is used to create the UPDATE
412: * statement.
413: * @param con the connection to use
414: * @throws TorqueException Any exceptions caught during processing will be
415: * rethrown wrapped into a TorqueException.
416: */
417: public static void doUpdate(Criteria criteria, Connection con)
418: throws TorqueException {
419: Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
420: correctBooleans(criteria);
421:
422: selectCriteria.put(ATTRIBUTE_GROUP_ID, criteria
423: .remove(ATTRIBUTE_GROUP_ID));
424:
425: setDbName(criteria);
426:
427: if (con == null) {
428: BasePeer.doUpdate(selectCriteria, criteria);
429: } else {
430: BasePeer.doUpdate(selectCriteria, criteria, con);
431: }
432: }
433:
434: /**
435: * Method to do deletes.
436: *
437: * @param criteria object containing data that is used DELETE from database.
438: * @throws TorqueException Any exceptions caught during processing will be
439: * rethrown wrapped into a TorqueException.
440: */
441: public static void doDelete(Criteria criteria)
442: throws TorqueException {
443: AttributeGroupPeer.doDelete(criteria, (Connection) null);
444: }
445:
446: /**
447: * Method to do deletes. This method is to be used during a transaction,
448: * otherwise use the doDelete(Criteria) method. It will take care of
449: * the connection details internally.
450: *
451: * @param criteria object containing data that is used DELETE from database.
452: * @param con the connection to use
453: * @throws TorqueException Any exceptions caught during processing will be
454: * rethrown wrapped into a TorqueException.
455: */
456: public static void doDelete(Criteria criteria, Connection con)
457: throws TorqueException {
458: correctBooleans(criteria);
459:
460: setDbName(criteria);
461:
462: if (con == null) {
463: BasePeer.doDelete(criteria);
464: } else {
465: BasePeer.doDelete(criteria, con);
466: }
467: }
468:
469: /**
470: * Method to do selects
471: *
472: * @throws TorqueException Any exceptions caught during processing will be
473: * rethrown wrapped into a TorqueException.
474: */
475: public static List doSelect(AttributeGroup obj)
476: throws TorqueException {
477: return doSelect(buildSelectCriteria(obj));
478: }
479:
480: /**
481: * Method to do inserts
482: *
483: * @throws TorqueException Any exceptions caught during processing will be
484: * rethrown wrapped into a TorqueException.
485: */
486: public static void doInsert(AttributeGroup obj)
487: throws TorqueException {
488: obj.setPrimaryKey(doInsert(buildCriteria(obj)));
489: obj.setNew(false);
490: obj.setModified(false);
491: }
492:
493: /**
494: * @param obj the data object to update in the database.
495: * @throws TorqueException Any exceptions caught during processing will be
496: * rethrown wrapped into a TorqueException.
497: */
498: public static void doUpdate(AttributeGroup obj)
499: throws TorqueException {
500: doUpdate(buildCriteria(obj));
501: obj.setModified(false);
502: }
503:
504: /**
505: * @param obj the data object to delete in the database.
506: * @throws TorqueException Any exceptions caught during processing will be
507: * rethrown wrapped into a TorqueException.
508: */
509: public static void doDelete(AttributeGroup obj)
510: throws TorqueException {
511: doDelete(buildSelectCriteria(obj));
512: }
513:
514: /**
515: * Method to do inserts. This method is to be used during a transaction,
516: * otherwise use the doInsert(AttributeGroup) method. It will take
517: * care of the connection details internally.
518: *
519: * @param obj the data object to insert into the database.
520: * @param con the connection to use
521: * @throws TorqueException Any exceptions caught during processing will be
522: * rethrown wrapped into a TorqueException.
523: */
524: public static void doInsert(AttributeGroup obj, Connection con)
525: throws TorqueException {
526: obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
527: obj.setNew(false);
528: obj.setModified(false);
529: }
530:
531: /**
532: * Method to do update. This method is to be used during a transaction,
533: * otherwise use the doUpdate(AttributeGroup) method. It will take
534: * care of the connection details internally.
535: *
536: * @param obj the data object to update in the database.
537: * @param con the connection to use
538: * @throws TorqueException Any exceptions caught during processing will be
539: * rethrown wrapped into a TorqueException.
540: */
541: public static void doUpdate(AttributeGroup obj, Connection con)
542: throws TorqueException {
543: doUpdate(buildCriteria(obj), con);
544: obj.setModified(false);
545: }
546:
547: /**
548: * Method to delete. This method is to be used during a transaction,
549: * otherwise use the doDelete(AttributeGroup) method. It will take
550: * care of the connection details internally.
551: *
552: * @param obj the data object to delete in the database.
553: * @param con the connection to use
554: * @throws TorqueException Any exceptions caught during processing will be
555: * rethrown wrapped into a TorqueException.
556: */
557: public static void doDelete(AttributeGroup obj, Connection con)
558: throws TorqueException {
559: doDelete(buildSelectCriteria(obj), con);
560: }
561:
562: /**
563: * Method to do deletes.
564: *
565: * @param pk ObjectKey that is used DELETE from database.
566: * @throws TorqueException Any exceptions caught during processing will be
567: * rethrown wrapped into a TorqueException.
568: */
569: public static void doDelete(ObjectKey pk) throws TorqueException {
570: BaseAttributeGroupPeer.doDelete(pk, (Connection) null);
571: }
572:
573: /**
574: * Method to delete. This method is to be used during a transaction,
575: * otherwise use the doDelete(ObjectKey) method. It will take
576: * care of the connection details internally.
577: *
578: * @param pk the primary key for the object to delete in the database.
579: * @param con the connection to use
580: * @throws TorqueException Any exceptions caught during processing will be
581: * rethrown wrapped into a TorqueException.
582: */
583: public static void doDelete(ObjectKey pk, Connection con)
584: throws TorqueException {
585: doDelete(buildCriteria(pk), con);
586: }
587:
588: /** Build a Criteria object from an ObjectKey */
589: public static Criteria buildCriteria(ObjectKey pk) {
590: Criteria criteria = new Criteria();
591: criteria.add(ATTRIBUTE_GROUP_ID, pk);
592: return criteria;
593: }
594:
595: /** Build a Criteria object from the data object for this peer */
596: public static Criteria buildCriteria(AttributeGroup obj) {
597: Criteria criteria = new Criteria(DATABASE_NAME);
598: if (!obj.isNew())
599: criteria.add(ATTRIBUTE_GROUP_ID, obj.getAttributeGroupId());
600: criteria.add(NAME, obj.getName());
601: criteria.add(DESCRIPTION, obj.getDescription());
602: criteria.add(MODULE_ID, obj.getModuleId());
603: criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
604: criteria.add(ACTIVE, obj.getActive());
605: criteria.add(DEDUPE, obj.getDedupe());
606: criteria.add(PREFERRED_ORDER, obj.getOrder());
607: return criteria;
608: }
609:
610: /** Build a Criteria object from the data object for this peer, skipping all binary columns */
611: public static Criteria buildSelectCriteria(AttributeGroup obj) {
612: Criteria criteria = new Criteria(DATABASE_NAME);
613: if (!obj.isNew()) {
614: criteria.add(ATTRIBUTE_GROUP_ID, obj.getAttributeGroupId());
615: }
616: criteria.add(NAME, obj.getName());
617: criteria.add(DESCRIPTION, obj.getDescription());
618: criteria.add(MODULE_ID, obj.getModuleId());
619: criteria.add(ISSUE_TYPE_ID, obj.getIssueTypeId());
620: criteria.add(ACTIVE, obj.getActive());
621: criteria.add(DEDUPE, obj.getDedupe());
622: criteria.add(PREFERRED_ORDER, obj.getOrder());
623: return criteria;
624: }
625:
626: /**
627: * Retrieve a single object by pk
628: *
629: * @param pk the primary key
630: * @throws TorqueException Any exceptions caught during processing will be
631: * rethrown wrapped into a TorqueException.
632: * @throws NoRowsException Primary key was not found in database.
633: * @throws TooManyRowsException Primary key was not found in database.
634: */
635: public static AttributeGroup retrieveByPK(Integer pk)
636: throws TorqueException, NoRowsException,
637: TooManyRowsException {
638: return retrieveByPK(SimpleKey.keyFor(pk));
639: }
640:
641: /**
642: * Retrieve a single object by pk
643: *
644: * @param pk the primary key
645: * @param con the connection to use
646: * @throws TorqueException Any exceptions caught during processing will be
647: * rethrown wrapped into a TorqueException.
648: * @throws NoRowsException Primary key was not found in database.
649: * @throws TooManyRowsException Primary key was not found in database.
650: */
651: public static AttributeGroup retrieveByPK(Integer pk, Connection con)
652: throws TorqueException, NoRowsException,
653: TooManyRowsException {
654: return retrieveByPK(SimpleKey.keyFor(pk), con);
655: }
656:
657: /**
658: * Retrieve a single object by pk
659: *
660: * @param pk the primary key
661: * @throws TorqueException Any exceptions caught during processing will be
662: * rethrown wrapped into a TorqueException.
663: * @throws NoRowsException Primary key was not found in database.
664: * @throws TooManyRowsException Primary key was not found in database.
665: */
666: public static AttributeGroup retrieveByPK(ObjectKey pk)
667: throws TorqueException, NoRowsException,
668: TooManyRowsException {
669: Connection db = null;
670: AttributeGroup retVal = null;
671: try {
672: db = Torque.getConnection(DATABASE_NAME);
673: retVal = retrieveByPK(pk, db);
674: } finally {
675: Torque.closeConnection(db);
676: }
677: return retVal;
678: }
679:
680: /**
681: * Retrieve a single object by pk
682: *
683: * @param pk the primary key
684: * @param con the connection to use
685: * @throws TorqueException Any exceptions caught during processing will be
686: * rethrown wrapped into a TorqueException.
687: * @throws NoRowsException Primary key was not found in database.
688: * @throws TooManyRowsException Primary key was not found in database.
689: */
690: public static AttributeGroup retrieveByPK(ObjectKey pk,
691: Connection con) throws TorqueException, NoRowsException,
692: TooManyRowsException {
693: Criteria criteria = buildCriteria(pk);
694: List v = doSelect(criteria, con);
695: if (v.size() == 0) {
696: throw new NoRowsException("Failed to select a row.");
697: } else if (v.size() > 1) {
698: throw new TooManyRowsException(
699: "Failed to select only one row.");
700: } else {
701: return (AttributeGroup) v.get(0);
702: }
703: }
704:
705: /**
706: * Retrieve a multiple objects by pk
707: *
708: * @param pks List of primary keys
709: * @throws TorqueException Any exceptions caught during processing will be
710: * rethrown wrapped into a TorqueException.
711: */
712: public static List retrieveByPKs(List pks) throws TorqueException {
713: Connection db = null;
714: List retVal = null;
715: try {
716: db = Torque.getConnection(DATABASE_NAME);
717: retVal = retrieveByPKs(pks, db);
718: } finally {
719: Torque.closeConnection(db);
720: }
721: return retVal;
722: }
723:
724: /**
725: * Retrieve a multiple objects by pk
726: *
727: * @param pks List of primary keys
728: * @param dbcon the connection to use
729: * @throws TorqueException Any exceptions caught during processing will be
730: * rethrown wrapped into a TorqueException.
731: */
732: public static List retrieveByPKs(List pks, Connection dbcon)
733: throws TorqueException {
734: List objs = null;
735: if (pks == null || pks.size() == 0) {
736: objs = new LinkedList();
737: } else {
738: Criteria criteria = new Criteria();
739: criteria.addIn(ATTRIBUTE_GROUP_ID, pks);
740: objs = doSelect(criteria, dbcon);
741: }
742: return objs;
743: }
744:
745: /**
746: * selects a collection of AttributeGroup objects pre-filled with their
747: * ScarabModule objects.
748: *
749: * This method is protected by default in order to keep the public
750: * api reasonable. You can provide public methods for those you
751: * actually need in AttributeGroupPeer.
752: *
753: * @throws TorqueException Any exceptions caught during processing will be
754: * rethrown wrapped into a TorqueException.
755: */
756: protected static List doSelectJoinScarabModule(Criteria criteria)
757: throws TorqueException {
758: return doSelectJoinScarabModule(criteria, null);
759: }
760:
761: /**
762: * selects a collection of AttributeGroup objects pre-filled with their
763: * ScarabModule objects.
764: *
765: * This method is protected by default in order to keep the public
766: * api reasonable. You can provide public methods for those you
767: * actually need in AttributeGroupPeer.
768: *
769: * @throws TorqueException Any exceptions caught during processing will be
770: * rethrown wrapped into a TorqueException.
771: */
772: protected static List doSelectJoinScarabModule(Criteria criteria,
773: Connection conn) throws TorqueException {
774: setDbName(criteria);
775:
776: AttributeGroupPeer.addSelectColumns(criteria);
777: int offset = numColumns + 1;
778: ScarabModulePeer.addSelectColumns(criteria);
779:
780: criteria.addJoin(AttributeGroupPeer.MODULE_ID,
781: ScarabModulePeer.MODULE_ID);
782:
783: correctBooleans(criteria);
784:
785: List rows;
786: if (conn == null) {
787: rows = BasePeer.doSelect(criteria);
788: } else {
789: rows = BasePeer.doSelect(criteria, conn);
790: }
791:
792: List results = new ArrayList();
793:
794: for (int i = 0; i < rows.size(); i++) {
795: Record row = (Record) rows.get(i);
796:
797: Class omClass = AttributeGroupPeer.getOMClass();
798: AttributeGroup obj1 = (AttributeGroup) AttributeGroupPeer
799: .row2Object(row, 1, omClass);
800: omClass = ScarabModulePeer.getOMClass(row, offset);
801: ScarabModule obj2 = (ScarabModule) ScarabModulePeer
802: .row2Object(row, offset, omClass);
803:
804: boolean newObject = true;
805: for (int j = 0; j < results.size(); j++) {
806: AttributeGroup temp_obj1 = (AttributeGroup) results
807: .get(j);
808: ScarabModule temp_obj2 = (ScarabModule) temp_obj1
809: .getModule();
810: if (temp_obj2.getPrimaryKey().equals(
811: obj2.getPrimaryKey())) {
812: newObject = false;
813: temp_obj2.addAttributeGroup(obj1);
814: break;
815: }
816: }
817: if (newObject) {
818: obj2.initAttributeGroups();
819: obj2.addAttributeGroup(obj1);
820: }
821: results.add(obj1);
822: }
823: return results;
824: }
825:
826: /**
827: * selects a collection of AttributeGroup objects pre-filled with their
828: * IssueType objects.
829: *
830: * This method is protected by default in order to keep the public
831: * api reasonable. You can provide public methods for those you
832: * actually need in AttributeGroupPeer.
833: *
834: * @throws TorqueException Any exceptions caught during processing will be
835: * rethrown wrapped into a TorqueException.
836: */
837: protected static List doSelectJoinIssueType(Criteria criteria)
838: throws TorqueException {
839: return doSelectJoinIssueType(criteria, null);
840: }
841:
842: /**
843: * selects a collection of AttributeGroup objects pre-filled with their
844: * IssueType objects.
845: *
846: * This method is protected by default in order to keep the public
847: * api reasonable. You can provide public methods for those you
848: * actually need in AttributeGroupPeer.
849: *
850: * @throws TorqueException Any exceptions caught during processing will be
851: * rethrown wrapped into a TorqueException.
852: */
853: protected static List doSelectJoinIssueType(Criteria criteria,
854: Connection conn) throws TorqueException {
855: setDbName(criteria);
856:
857: AttributeGroupPeer.addSelectColumns(criteria);
858: int offset = numColumns + 1;
859: IssueTypePeer.addSelectColumns(criteria);
860:
861: criteria.addJoin(AttributeGroupPeer.ISSUE_TYPE_ID,
862: IssueTypePeer.ISSUE_TYPE_ID);
863:
864: correctBooleans(criteria);
865:
866: List rows;
867: if (conn == null) {
868: rows = BasePeer.doSelect(criteria);
869: } else {
870: rows = BasePeer.doSelect(criteria, conn);
871: }
872:
873: List results = new ArrayList();
874:
875: for (int i = 0; i < rows.size(); i++) {
876: Record row = (Record) rows.get(i);
877:
878: Class omClass = AttributeGroupPeer.getOMClass();
879: AttributeGroup obj1 = (AttributeGroup) AttributeGroupPeer
880: .row2Object(row, 1, omClass);
881: omClass = IssueTypePeer.getOMClass();
882: IssueType obj2 = (IssueType) IssueTypePeer.row2Object(row,
883: offset, omClass);
884:
885: boolean newObject = true;
886: for (int j = 0; j < results.size(); j++) {
887: AttributeGroup temp_obj1 = (AttributeGroup) results
888: .get(j);
889: IssueType temp_obj2 = (IssueType) temp_obj1
890: .getIssueType();
891: if (temp_obj2.getPrimaryKey().equals(
892: obj2.getPrimaryKey())) {
893: newObject = false;
894: temp_obj2.addAttributeGroup(obj1);
895: break;
896: }
897: }
898: if (newObject) {
899: obj2.initAttributeGroups();
900: obj2.addAttributeGroup(obj1);
901: }
902: results.add(obj1);
903: }
904: return results;
905: }
906:
907: /**
908: * Returns the TableMap related to this peer. This method is not
909: * needed for general use but a specific application could have a need.
910: *
911: * @throws TorqueException Any exceptions caught during processing will be
912: * rethrown wrapped into a TorqueException.
913: */
914: protected static TableMap getTableMap() throws TorqueException {
915: return Torque.getDatabaseMap(DATABASE_NAME)
916: .getTable(TABLE_NAME);
917: }
918:
919: private static void setDbName(Criteria crit) {
920: // Set the correct dbName if it has not been overridden
921: // crit.getDbName will return the same object if not set to
922: // another value so == check is okay and faster
923: if (crit.getDbName() == Torque.getDefaultDB()) {
924: crit.setDbName(DATABASE_NAME);
925: }
926: }
927: }
|