0001: package org.tigris.scarab.om;
0002:
0003: import java.math.BigDecimal;
0004: import java.sql.Connection;
0005: import java.sql.SQLException;
0006: import java.util.ArrayList;
0007: import java.util.Date;
0008: import java.util.Iterator;
0009: import java.util.LinkedList;
0010: import java.util.List;
0011:
0012: import org.apache.torque.NoRowsException;
0013: import org.apache.torque.TooManyRowsException;
0014: import org.apache.torque.Torque;
0015: import org.apache.torque.TorqueException;
0016: import org.apache.torque.map.MapBuilder;
0017: import org.apache.torque.map.TableMap;
0018: import org.apache.torque.om.DateKey;
0019: import org.apache.torque.om.NumberKey;
0020: import org.apache.torque.om.StringKey;
0021: import org.apache.torque.om.ObjectKey;
0022: import org.apache.torque.om.SimpleKey;
0023: import org.apache.torque.util.BasePeer;
0024: import org.apache.torque.util.Criteria;
0025:
0026: import com.workingdogs.village.DataSetException;
0027: import com.workingdogs.village.QueryDataSet;
0028: import com.workingdogs.village.Record;
0029:
0030: // Local classes
0031: import org.tigris.scarab.om.map.*;
0032:
0033: /**
0034: */
0035: public abstract class BaseActivitySetPeer extends BasePeer {
0036:
0037: /** the default database name for this class */
0038: public static final String DATABASE_NAME = "scarab";
0039:
0040: /** the table name for this class */
0041: public static final String TABLE_NAME = "SCARAB_TRANSACTION";
0042:
0043: /**
0044: * @return the map builder for this peer
0045: * @throws TorqueException Any exceptions caught during processing will be
0046: * rethrown wrapped into a TorqueException.
0047: */
0048: public static MapBuilder getMapBuilder() throws TorqueException {
0049: return getMapBuilder(ActivitySetMapBuilder.CLASS_NAME);
0050: }
0051:
0052: /** the column name for the TRANSACTION_ID field */
0053: public static final String TRANSACTION_ID;
0054: /** the column name for the TYPE_ID field */
0055: public static final String TYPE_ID;
0056: /** the column name for the ATTACHMENT_ID field */
0057: public static final String ATTACHMENT_ID;
0058: /** the column name for the CREATED_BY field */
0059: public static final String CREATED_BY;
0060: /** the column name for the CREATED_DATE field */
0061: public static final String CREATED_DATE;
0062:
0063: static {
0064: TRANSACTION_ID = "SCARAB_TRANSACTION.TRANSACTION_ID";
0065: TYPE_ID = "SCARAB_TRANSACTION.TYPE_ID";
0066: ATTACHMENT_ID = "SCARAB_TRANSACTION.ATTACHMENT_ID";
0067: CREATED_BY = "SCARAB_TRANSACTION.CREATED_BY";
0068: CREATED_DATE = "SCARAB_TRANSACTION.CREATED_DATE";
0069: if (Torque.isInit()) {
0070: try {
0071: getMapBuilder(ActivitySetMapBuilder.CLASS_NAME);
0072: } catch (Exception e) {
0073: log.error("Could not initialize Peer", e);
0074: throw new RuntimeException(e);
0075: }
0076: } else {
0077: Torque.registerMapBuilder(ActivitySetMapBuilder.CLASS_NAME);
0078: }
0079: }
0080:
0081: /** number of columns for this peer */
0082: public static final int numColumns = 5;
0083:
0084: /** A class that can be returned by this peer. */
0085: protected static final String CLASSNAME_DEFAULT = "org.tigris.scarab.om.ActivitySet";
0086:
0087: /** A class that can be returned by this peer. */
0088: protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
0089:
0090: /**
0091: * Class object initialization method.
0092: *
0093: * @param className name of the class to initialize
0094: * @return the initialized class
0095: */
0096: private static Class initClass(String className) {
0097: Class c = null;
0098: try {
0099: c = Class.forName(className);
0100: } catch (Throwable t) {
0101: log
0102: .error(
0103: "A FATAL ERROR has occurred which should not "
0104: + "have happened under any circumstance. Please notify "
0105: + "the Torque developers <torque-dev@db.apache.org> "
0106: + "and give as many details as possible (including the error "
0107: + "stack trace).", t);
0108:
0109: // Error objects should always be propogated.
0110: if (t instanceof Error) {
0111: throw (Error) t.fillInStackTrace();
0112: }
0113: }
0114: return c;
0115: }
0116:
0117: /**
0118: * Get the list of objects for a ResultSet. Please not that your
0119: * resultset MUST return columns in the right order. You can use
0120: * getFieldNames() in BaseObject to get the correct sequence.
0121: *
0122: * @param results the ResultSet
0123: * @return the list of objects
0124: * @throws TorqueException Any exceptions caught during processing will be
0125: * rethrown wrapped into a TorqueException.
0126: */
0127: public static List resultSet2Objects(java.sql.ResultSet results)
0128: throws TorqueException {
0129: try {
0130: QueryDataSet qds = null;
0131: List rows = null;
0132: try {
0133: qds = new QueryDataSet(results);
0134: rows = getSelectResults(qds);
0135: } finally {
0136: if (qds != null) {
0137: qds.close();
0138: }
0139: }
0140:
0141: return populateObjects(rows);
0142: } catch (SQLException e) {
0143: throw new TorqueException(e);
0144: } catch (DataSetException e) {
0145: throw new TorqueException(e);
0146: }
0147: }
0148:
0149: /**
0150: * Method to do inserts.
0151: *
0152: * @param criteria object used to create the INSERT statement.
0153: * @throws TorqueException Any exceptions caught during processing will be
0154: * rethrown wrapped into a TorqueException.
0155: */
0156: public static ObjectKey doInsert(Criteria criteria)
0157: throws TorqueException {
0158: return BaseActivitySetPeer
0159: .doInsert(criteria, (Connection) null);
0160: }
0161:
0162: /**
0163: * Method to do inserts. This method is to be used during a transaction,
0164: * otherwise use the doInsert(Criteria) method. It will take care of
0165: * the connection details internally.
0166: *
0167: * @param criteria object used to create the INSERT statement.
0168: * @param con the connection to use
0169: * @throws TorqueException Any exceptions caught during processing will be
0170: * rethrown wrapped into a TorqueException.
0171: */
0172: public static ObjectKey doInsert(Criteria criteria, Connection con)
0173: throws TorqueException {
0174: correctBooleans(criteria);
0175:
0176: setDbName(criteria);
0177:
0178: if (con == null) {
0179: return BasePeer.doInsert(criteria);
0180: } else {
0181: return BasePeer.doInsert(criteria, con);
0182: }
0183: }
0184:
0185: /**
0186: * Add all the columns needed to create a new object.
0187: *
0188: * @param criteria object containing the columns to add.
0189: * @throws TorqueException Any exceptions caught during processing will be
0190: * rethrown wrapped into a TorqueException.
0191: */
0192: public static void addSelectColumns(Criteria criteria)
0193: throws TorqueException {
0194: criteria.addSelectColumn(TRANSACTION_ID);
0195: criteria.addSelectColumn(TYPE_ID);
0196: criteria.addSelectColumn(ATTACHMENT_ID);
0197: criteria.addSelectColumn(CREATED_BY);
0198: criteria.addSelectColumn(CREATED_DATE);
0199: }
0200:
0201: /**
0202: * changes the boolean values in the criteria to the appropriate type,
0203: * whenever a booleanchar or booleanint column is involved.
0204: * This enables the user to create criteria using Boolean values
0205: * for booleanchar or booleanint columns
0206: * @param criteria the criteria in which the boolean values should be corrected
0207: */
0208: public static void correctBooleans(Criteria criteria) {
0209: }
0210:
0211: /**
0212: * Create a new object of type cls from a resultset row starting
0213: * from a specified offset. This is done so that you can select
0214: * other rows than just those needed for this object. You may
0215: * for example want to create two objects from the same row.
0216: *
0217: * @throws TorqueException Any exceptions caught during processing will be
0218: * rethrown wrapped into a TorqueException.
0219: */
0220: public static ActivitySet row2Object(Record row, int offset,
0221: Class cls) throws TorqueException {
0222: try {
0223: ActivitySet obj = (ActivitySet) cls.newInstance();
0224: ActivitySetPeer.populateObject(row, offset, obj);
0225: obj.setModified(false);
0226: obj.setNew(false);
0227:
0228: return obj;
0229: } catch (InstantiationException e) {
0230: throw new TorqueException(e);
0231: } catch (IllegalAccessException e) {
0232: throw new TorqueException(e);
0233: }
0234: }
0235:
0236: /**
0237: * Populates an object from a resultset row starting
0238: * from a specified offset. This is done so that you can select
0239: * other rows than just those needed for this object. You may
0240: * for example want to create two objects from the same row.
0241: *
0242: * @throws TorqueException Any exceptions caught during processing will be
0243: * rethrown wrapped into a TorqueException.
0244: */
0245: public static void populateObject(Record row, int offset,
0246: ActivitySet obj) throws TorqueException {
0247: try {
0248: obj.setActivitySetId(row.getValue(offset + 0).asLongObj());
0249: obj.setTypeId(row.getValue(offset + 1).asIntegerObj());
0250: obj.setAttachmentId(row.getValue(offset + 2).asLongObj());
0251: obj.setCreatedBy(row.getValue(offset + 3).asIntegerObj());
0252: obj.setCreatedDate(row.getValue(offset + 4).asUtilDate());
0253: } catch (DataSetException e) {
0254: throw new TorqueException(e);
0255: }
0256: }
0257:
0258: /**
0259: * Method to do selects.
0260: *
0261: * @param criteria object used to create the SELECT statement.
0262: * @return List of selected Objects
0263: * @throws TorqueException Any exceptions caught during processing will be
0264: * rethrown wrapped into a TorqueException.
0265: */
0266: public static List doSelect(Criteria criteria)
0267: throws TorqueException {
0268: return populateObjects(doSelectVillageRecords(criteria));
0269: }
0270:
0271: /**
0272: * Method to do selects within a transaction.
0273: *
0274: * @param criteria object used to create the SELECT statement.
0275: * @param con the connection to use
0276: * @return List of selected Objects
0277: * @throws TorqueException Any exceptions caught during processing will be
0278: * rethrown wrapped into a TorqueException.
0279: */
0280: public static List doSelect(Criteria criteria, Connection con)
0281: throws TorqueException {
0282: return populateObjects(doSelectVillageRecords(criteria, con));
0283: }
0284:
0285: /**
0286: * Grabs the raw Village records to be formed into objects.
0287: * This method handles connections internally. The Record objects
0288: * returned by this method should be considered readonly. Do not
0289: * alter the data and call save(), your results may vary, but are
0290: * certainly likely to result in hard to track MT bugs.
0291: *
0292: * @throws TorqueException Any exceptions caught during processing will be
0293: * rethrown wrapped into a TorqueException.
0294: */
0295: public static List doSelectVillageRecords(Criteria criteria)
0296: throws TorqueException {
0297: return BaseActivitySetPeer.doSelectVillageRecords(criteria,
0298: (Connection) null);
0299: }
0300:
0301: /**
0302: * Grabs the raw Village records to be formed into objects.
0303: * This method should be used for transactions
0304: *
0305: * @param criteria object used to create the SELECT statement.
0306: * @param con the connection to use
0307: * @throws TorqueException Any exceptions caught during processing will be
0308: * rethrown wrapped into a TorqueException.
0309: */
0310: public static List doSelectVillageRecords(Criteria criteria,
0311: Connection con) throws TorqueException {
0312: if (criteria.getSelectColumns().size() == 0) {
0313: addSelectColumns(criteria);
0314: }
0315: correctBooleans(criteria);
0316:
0317: setDbName(criteria);
0318:
0319: // BasePeer returns a List of Value (Village) arrays. The array
0320: // order follows the order columns were placed in the Select clause.
0321: if (con == null) {
0322: return BasePeer.doSelect(criteria);
0323: } else {
0324: return BasePeer.doSelect(criteria, con);
0325: }
0326: }
0327:
0328: /**
0329: * The returned List will contain objects of the default type or
0330: * objects that inherit from the default.
0331: *
0332: * @throws TorqueException Any exceptions caught during processing will be
0333: * rethrown wrapped into a TorqueException.
0334: */
0335: public static List populateObjects(List records)
0336: throws TorqueException {
0337: List results = new ArrayList(records.size());
0338:
0339: // populate the object(s)
0340: for (int i = 0; i < records.size(); i++) {
0341: Record row = (Record) records.get(i);
0342: results.add(ActivitySetPeer.row2Object(row, 1,
0343: ActivitySetPeer.getOMClass()));
0344: }
0345: return results;
0346: }
0347:
0348: /**
0349: * The class that the Peer will make instances of.
0350: * If the BO is abstract then you must implement this method
0351: * in the BO.
0352: *
0353: * @throws TorqueException Any exceptions caught during processing will be
0354: * rethrown wrapped into a TorqueException.
0355: */
0356: public static Class getOMClass() throws TorqueException {
0357: return CLASS_DEFAULT;
0358: }
0359:
0360: /**
0361: * Method to do updates.
0362: *
0363: * @param criteria object containing data that is used to create the UPDATE
0364: * statement.
0365: * @throws TorqueException Any exceptions caught during processing will be
0366: * rethrown wrapped into a TorqueException.
0367: */
0368: public static void doUpdate(Criteria criteria)
0369: throws TorqueException {
0370: BaseActivitySetPeer.doUpdate(criteria, (Connection) null);
0371: }
0372:
0373: /**
0374: * Method to do updates. This method is to be used during a transaction,
0375: * otherwise use the doUpdate(Criteria) method. It will take care of
0376: * the connection details internally.
0377: *
0378: * @param criteria object containing data that is used to create the UPDATE
0379: * statement.
0380: * @param con the connection to use
0381: * @throws TorqueException Any exceptions caught during processing will be
0382: * rethrown wrapped into a TorqueException.
0383: */
0384: public static void doUpdate(Criteria criteria, Connection con)
0385: throws TorqueException {
0386: Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
0387: correctBooleans(criteria);
0388:
0389: selectCriteria.put(TRANSACTION_ID, criteria
0390: .remove(TRANSACTION_ID));
0391:
0392: setDbName(criteria);
0393:
0394: if (con == null) {
0395: BasePeer.doUpdate(selectCriteria, criteria);
0396: } else {
0397: BasePeer.doUpdate(selectCriteria, criteria, con);
0398: }
0399: }
0400:
0401: /**
0402: * Method to do deletes.
0403: *
0404: * @param criteria object containing data that is used DELETE from database.
0405: * @throws TorqueException Any exceptions caught during processing will be
0406: * rethrown wrapped into a TorqueException.
0407: */
0408: public static void doDelete(Criteria criteria)
0409: throws TorqueException {
0410: ActivitySetPeer.doDelete(criteria, (Connection) null);
0411: }
0412:
0413: /**
0414: * Method to do deletes. This method is to be used during a transaction,
0415: * otherwise use the doDelete(Criteria) method. It will take care of
0416: * the connection details internally.
0417: *
0418: * @param criteria object containing data that is used DELETE from database.
0419: * @param con the connection to use
0420: * @throws TorqueException Any exceptions caught during processing will be
0421: * rethrown wrapped into a TorqueException.
0422: */
0423: public static void doDelete(Criteria criteria, Connection con)
0424: throws TorqueException {
0425: correctBooleans(criteria);
0426:
0427: setDbName(criteria);
0428:
0429: if (con == null) {
0430: BasePeer.doDelete(criteria);
0431: } else {
0432: BasePeer.doDelete(criteria, con);
0433: }
0434: }
0435:
0436: /**
0437: * Method to do selects
0438: *
0439: * @throws TorqueException Any exceptions caught during processing will be
0440: * rethrown wrapped into a TorqueException.
0441: */
0442: public static List doSelect(ActivitySet obj) throws TorqueException {
0443: return doSelect(buildSelectCriteria(obj));
0444: }
0445:
0446: /**
0447: * Method to do inserts
0448: *
0449: * @throws TorqueException Any exceptions caught during processing will be
0450: * rethrown wrapped into a TorqueException.
0451: */
0452: public static void doInsert(ActivitySet obj) throws TorqueException {
0453: obj.setPrimaryKey(doInsert(buildCriteria(obj)));
0454: obj.setNew(false);
0455: obj.setModified(false);
0456: }
0457:
0458: /**
0459: * @param obj the data object to update in the database.
0460: * @throws TorqueException Any exceptions caught during processing will be
0461: * rethrown wrapped into a TorqueException.
0462: */
0463: public static void doUpdate(ActivitySet obj) throws TorqueException {
0464: doUpdate(buildCriteria(obj));
0465: obj.setModified(false);
0466: }
0467:
0468: /**
0469: * @param obj the data object to delete in the database.
0470: * @throws TorqueException Any exceptions caught during processing will be
0471: * rethrown wrapped into a TorqueException.
0472: */
0473: public static void doDelete(ActivitySet obj) throws TorqueException {
0474: doDelete(buildSelectCriteria(obj));
0475: }
0476:
0477: /**
0478: * Method to do inserts. This method is to be used during a transaction,
0479: * otherwise use the doInsert(ActivitySet) method. It will take
0480: * care of the connection details internally.
0481: *
0482: * @param obj the data object to insert into the database.
0483: * @param con the connection to use
0484: * @throws TorqueException Any exceptions caught during processing will be
0485: * rethrown wrapped into a TorqueException.
0486: */
0487: public static void doInsert(ActivitySet obj, Connection con)
0488: throws TorqueException {
0489: obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
0490: obj.setNew(false);
0491: obj.setModified(false);
0492: }
0493:
0494: /**
0495: * Method to do update. This method is to be used during a transaction,
0496: * otherwise use the doUpdate(ActivitySet) method. It will take
0497: * care of the connection details internally.
0498: *
0499: * @param obj the data object to update in the database.
0500: * @param con the connection to use
0501: * @throws TorqueException Any exceptions caught during processing will be
0502: * rethrown wrapped into a TorqueException.
0503: */
0504: public static void doUpdate(ActivitySet obj, Connection con)
0505: throws TorqueException {
0506: doUpdate(buildCriteria(obj), con);
0507: obj.setModified(false);
0508: }
0509:
0510: /**
0511: * Method to delete. This method is to be used during a transaction,
0512: * otherwise use the doDelete(ActivitySet) method. It will take
0513: * care of the connection details internally.
0514: *
0515: * @param obj the data object to delete in the database.
0516: * @param con the connection to use
0517: * @throws TorqueException Any exceptions caught during processing will be
0518: * rethrown wrapped into a TorqueException.
0519: */
0520: public static void doDelete(ActivitySet obj, Connection con)
0521: throws TorqueException {
0522: doDelete(buildSelectCriteria(obj), con);
0523: }
0524:
0525: /**
0526: * Method to do deletes.
0527: *
0528: * @param pk ObjectKey that is used DELETE from database.
0529: * @throws TorqueException Any exceptions caught during processing will be
0530: * rethrown wrapped into a TorqueException.
0531: */
0532: public static void doDelete(ObjectKey pk) throws TorqueException {
0533: BaseActivitySetPeer.doDelete(pk, (Connection) null);
0534: }
0535:
0536: /**
0537: * Method to delete. This method is to be used during a transaction,
0538: * otherwise use the doDelete(ObjectKey) method. It will take
0539: * care of the connection details internally.
0540: *
0541: * @param pk the primary key for the object to delete in the database.
0542: * @param con the connection to use
0543: * @throws TorqueException Any exceptions caught during processing will be
0544: * rethrown wrapped into a TorqueException.
0545: */
0546: public static void doDelete(ObjectKey pk, Connection con)
0547: throws TorqueException {
0548: doDelete(buildCriteria(pk), con);
0549: }
0550:
0551: /** Build a Criteria object from an ObjectKey */
0552: public static Criteria buildCriteria(ObjectKey pk) {
0553: Criteria criteria = new Criteria();
0554: criteria.add(TRANSACTION_ID, pk);
0555: return criteria;
0556: }
0557:
0558: /** Build a Criteria object from the data object for this peer */
0559: public static Criteria buildCriteria(ActivitySet obj) {
0560: Criteria criteria = new Criteria(DATABASE_NAME);
0561: if (!obj.isNew())
0562: criteria.add(TRANSACTION_ID, obj.getActivitySetId());
0563: criteria.add(TYPE_ID, obj.getTypeId());
0564: criteria.add(ATTACHMENT_ID, obj.getAttachmentId());
0565: criteria.add(CREATED_BY, obj.getCreatedBy());
0566: criteria.add(CREATED_DATE, obj.getCreatedDate());
0567: return criteria;
0568: }
0569:
0570: /** Build a Criteria object from the data object for this peer, skipping all binary columns */
0571: public static Criteria buildSelectCriteria(ActivitySet obj) {
0572: Criteria criteria = new Criteria(DATABASE_NAME);
0573: if (!obj.isNew()) {
0574: criteria.add(TRANSACTION_ID, obj.getActivitySetId());
0575: }
0576: criteria.add(TYPE_ID, obj.getTypeId());
0577: criteria.add(ATTACHMENT_ID, obj.getAttachmentId());
0578: criteria.add(CREATED_BY, obj.getCreatedBy());
0579: criteria.add(CREATED_DATE, obj.getCreatedDate());
0580: return criteria;
0581: }
0582:
0583: /**
0584: * Retrieve a single object by pk
0585: *
0586: * @param pk the primary key
0587: * @throws TorqueException Any exceptions caught during processing will be
0588: * rethrown wrapped into a TorqueException.
0589: * @throws NoRowsException Primary key was not found in database.
0590: * @throws TooManyRowsException Primary key was not found in database.
0591: */
0592: public static ActivitySet retrieveByPK(Long pk)
0593: throws TorqueException, NoRowsException,
0594: TooManyRowsException {
0595: return retrieveByPK(SimpleKey.keyFor(pk));
0596: }
0597:
0598: /**
0599: * Retrieve a single object by pk
0600: *
0601: * @param pk the primary key
0602: * @param con the connection to use
0603: * @throws TorqueException Any exceptions caught during processing will be
0604: * rethrown wrapped into a TorqueException.
0605: * @throws NoRowsException Primary key was not found in database.
0606: * @throws TooManyRowsException Primary key was not found in database.
0607: */
0608: public static ActivitySet retrieveByPK(Long pk, Connection con)
0609: throws TorqueException, NoRowsException,
0610: TooManyRowsException {
0611: return retrieveByPK(SimpleKey.keyFor(pk), con);
0612: }
0613:
0614: /**
0615: * Retrieve a single object by pk
0616: *
0617: * @param pk the primary key
0618: * @throws TorqueException Any exceptions caught during processing will be
0619: * rethrown wrapped into a TorqueException.
0620: * @throws NoRowsException Primary key was not found in database.
0621: * @throws TooManyRowsException Primary key was not found in database.
0622: */
0623: public static ActivitySet retrieveByPK(ObjectKey pk)
0624: throws TorqueException, NoRowsException,
0625: TooManyRowsException {
0626: Connection db = null;
0627: ActivitySet retVal = null;
0628: try {
0629: db = Torque.getConnection(DATABASE_NAME);
0630: retVal = retrieveByPK(pk, db);
0631: } finally {
0632: Torque.closeConnection(db);
0633: }
0634: return retVal;
0635: }
0636:
0637: /**
0638: * Retrieve a single object by pk
0639: *
0640: * @param pk the primary key
0641: * @param con the connection to use
0642: * @throws TorqueException Any exceptions caught during processing will be
0643: * rethrown wrapped into a TorqueException.
0644: * @throws NoRowsException Primary key was not found in database.
0645: * @throws TooManyRowsException Primary key was not found in database.
0646: */
0647: public static ActivitySet retrieveByPK(ObjectKey pk, Connection con)
0648: throws TorqueException, NoRowsException,
0649: TooManyRowsException {
0650: Criteria criteria = buildCriteria(pk);
0651: List v = doSelect(criteria, con);
0652: if (v.size() == 0) {
0653: throw new NoRowsException("Failed to select a row.");
0654: } else if (v.size() > 1) {
0655: throw new TooManyRowsException(
0656: "Failed to select only one row.");
0657: } else {
0658: return (ActivitySet) v.get(0);
0659: }
0660: }
0661:
0662: /**
0663: * Retrieve a multiple objects by pk
0664: *
0665: * @param pks List of primary keys
0666: * @throws TorqueException Any exceptions caught during processing will be
0667: * rethrown wrapped into a TorqueException.
0668: */
0669: public static List retrieveByPKs(List pks) throws TorqueException {
0670: Connection db = null;
0671: List retVal = null;
0672: try {
0673: db = Torque.getConnection(DATABASE_NAME);
0674: retVal = retrieveByPKs(pks, db);
0675: } finally {
0676: Torque.closeConnection(db);
0677: }
0678: return retVal;
0679: }
0680:
0681: /**
0682: * Retrieve a multiple objects by pk
0683: *
0684: * @param pks List of primary keys
0685: * @param dbcon the connection to use
0686: * @throws TorqueException Any exceptions caught during processing will be
0687: * rethrown wrapped into a TorqueException.
0688: */
0689: public static List retrieveByPKs(List pks, Connection dbcon)
0690: throws TorqueException {
0691: List objs = null;
0692: if (pks == null || pks.size() == 0) {
0693: objs = new LinkedList();
0694: } else {
0695: Criteria criteria = new Criteria();
0696: criteria.addIn(TRANSACTION_ID, pks);
0697: objs = doSelect(criteria, dbcon);
0698: }
0699: return objs;
0700: }
0701:
0702: /**
0703: * selects a collection of ActivitySet objects pre-filled with their
0704: * ScarabUserImpl objects.
0705: *
0706: * This method is protected by default in order to keep the public
0707: * api reasonable. You can provide public methods for those you
0708: * actually need in ActivitySetPeer.
0709: *
0710: * @throws TorqueException Any exceptions caught during processing will be
0711: * rethrown wrapped into a TorqueException.
0712: */
0713: protected static List doSelectJoinScarabUserImpl(Criteria criteria)
0714: throws TorqueException {
0715: return doSelectJoinScarabUserImpl(criteria, null);
0716: }
0717:
0718: /**
0719: * selects a collection of ActivitySet objects pre-filled with their
0720: * ScarabUserImpl objects.
0721: *
0722: * This method is protected by default in order to keep the public
0723: * api reasonable. You can provide public methods for those you
0724: * actually need in ActivitySetPeer.
0725: *
0726: * @throws TorqueException Any exceptions caught during processing will be
0727: * rethrown wrapped into a TorqueException.
0728: */
0729: protected static List doSelectJoinScarabUserImpl(Criteria criteria,
0730: Connection conn) throws TorqueException {
0731: setDbName(criteria);
0732:
0733: ActivitySetPeer.addSelectColumns(criteria);
0734: int offset = numColumns + 1;
0735: ScarabUserImplPeer.addSelectColumns(criteria);
0736:
0737: criteria.addJoin(ActivitySetPeer.CREATED_BY,
0738: ScarabUserImplPeer.USER_ID);
0739:
0740: correctBooleans(criteria);
0741:
0742: List rows;
0743: if (conn == null) {
0744: rows = BasePeer.doSelect(criteria);
0745: } else {
0746: rows = BasePeer.doSelect(criteria, conn);
0747: }
0748:
0749: List results = new ArrayList();
0750:
0751: for (int i = 0; i < rows.size(); i++) {
0752: Record row = (Record) rows.get(i);
0753:
0754: Class omClass = ActivitySetPeer.getOMClass();
0755: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
0756: .row2Object(row, 1, omClass);
0757: omClass = ScarabUserImplPeer.getOMClass();
0758: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
0759: .row2Object(row, offset, omClass);
0760:
0761: boolean newObject = true;
0762: for (int j = 0; j < results.size(); j++) {
0763: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
0764: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
0765: .getScarabUser();
0766: if (temp_obj2.getPrimaryKey().equals(
0767: obj2.getPrimaryKey())) {
0768: newObject = false;
0769: temp_obj2.addActivitySet(obj1);
0770: break;
0771: }
0772: }
0773: if (newObject) {
0774: obj2.initActivitySets();
0775: obj2.addActivitySet(obj1);
0776: }
0777: results.add(obj1);
0778: }
0779: return results;
0780: }
0781:
0782: /**
0783: * selects a collection of ActivitySet objects pre-filled with their
0784: * ActivitySetType objects.
0785: *
0786: * This method is protected by default in order to keep the public
0787: * api reasonable. You can provide public methods for those you
0788: * actually need in ActivitySetPeer.
0789: *
0790: * @throws TorqueException Any exceptions caught during processing will be
0791: * rethrown wrapped into a TorqueException.
0792: */
0793: protected static List doSelectJoinActivitySetType(Criteria criteria)
0794: throws TorqueException {
0795: return doSelectJoinActivitySetType(criteria, null);
0796: }
0797:
0798: /**
0799: * selects a collection of ActivitySet objects pre-filled with their
0800: * ActivitySetType objects.
0801: *
0802: * This method is protected by default in order to keep the public
0803: * api reasonable. You can provide public methods for those you
0804: * actually need in ActivitySetPeer.
0805: *
0806: * @throws TorqueException Any exceptions caught during processing will be
0807: * rethrown wrapped into a TorqueException.
0808: */
0809: protected static List doSelectJoinActivitySetType(
0810: Criteria criteria, Connection conn) throws TorqueException {
0811: setDbName(criteria);
0812:
0813: ActivitySetPeer.addSelectColumns(criteria);
0814: int offset = numColumns + 1;
0815: ActivitySetTypePeer.addSelectColumns(criteria);
0816:
0817: criteria.addJoin(ActivitySetPeer.TYPE_ID,
0818: ActivitySetTypePeer.TYPE_ID);
0819:
0820: correctBooleans(criteria);
0821:
0822: List rows;
0823: if (conn == null) {
0824: rows = BasePeer.doSelect(criteria);
0825: } else {
0826: rows = BasePeer.doSelect(criteria, conn);
0827: }
0828:
0829: List results = new ArrayList();
0830:
0831: for (int i = 0; i < rows.size(); i++) {
0832: Record row = (Record) rows.get(i);
0833:
0834: Class omClass = ActivitySetPeer.getOMClass();
0835: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
0836: .row2Object(row, 1, omClass);
0837: omClass = ActivitySetTypePeer.getOMClass();
0838: ActivitySetType obj2 = (ActivitySetType) ActivitySetTypePeer
0839: .row2Object(row, offset, omClass);
0840:
0841: boolean newObject = true;
0842: for (int j = 0; j < results.size(); j++) {
0843: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
0844: ActivitySetType temp_obj2 = (ActivitySetType) temp_obj1
0845: .getActivitySetType();
0846: if (temp_obj2.getPrimaryKey().equals(
0847: obj2.getPrimaryKey())) {
0848: newObject = false;
0849: temp_obj2.addActivitySet(obj1);
0850: break;
0851: }
0852: }
0853: if (newObject) {
0854: obj2.initActivitySets();
0855: obj2.addActivitySet(obj1);
0856: }
0857: results.add(obj1);
0858: }
0859: return results;
0860: }
0861:
0862: /**
0863: * selects a collection of ActivitySet objects pre-filled with their
0864: * Attachment objects.
0865: *
0866: * This method is protected by default in order to keep the public
0867: * api reasonable. You can provide public methods for those you
0868: * actually need in ActivitySetPeer.
0869: *
0870: * @throws TorqueException Any exceptions caught during processing will be
0871: * rethrown wrapped into a TorqueException.
0872: */
0873: protected static List doSelectJoinAttachment(Criteria criteria)
0874: throws TorqueException {
0875: return doSelectJoinAttachment(criteria, null);
0876: }
0877:
0878: /**
0879: * selects a collection of ActivitySet objects pre-filled with their
0880: * Attachment objects.
0881: *
0882: * This method is protected by default in order to keep the public
0883: * api reasonable. You can provide public methods for those you
0884: * actually need in ActivitySetPeer.
0885: *
0886: * @throws TorqueException Any exceptions caught during processing will be
0887: * rethrown wrapped into a TorqueException.
0888: */
0889: protected static List doSelectJoinAttachment(Criteria criteria,
0890: Connection conn) throws TorqueException {
0891: setDbName(criteria);
0892:
0893: ActivitySetPeer.addSelectColumns(criteria);
0894: int offset = numColumns + 1;
0895: AttachmentPeer.addSelectColumns(criteria);
0896:
0897: criteria.addJoin(ActivitySetPeer.ATTACHMENT_ID,
0898: AttachmentPeer.ATTACHMENT_ID);
0899:
0900: correctBooleans(criteria);
0901:
0902: List rows;
0903: if (conn == null) {
0904: rows = BasePeer.doSelect(criteria);
0905: } else {
0906: rows = BasePeer.doSelect(criteria, conn);
0907: }
0908:
0909: List results = new ArrayList();
0910:
0911: for (int i = 0; i < rows.size(); i++) {
0912: Record row = (Record) rows.get(i);
0913:
0914: Class omClass = ActivitySetPeer.getOMClass();
0915: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
0916: .row2Object(row, 1, omClass);
0917: omClass = AttachmentPeer.getOMClass();
0918: Attachment obj2 = (Attachment) AttachmentPeer.row2Object(
0919: row, offset, omClass);
0920:
0921: boolean newObject = true;
0922: for (int j = 0; j < results.size(); j++) {
0923: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
0924: Attachment temp_obj2 = (Attachment) temp_obj1
0925: .getAttachment();
0926: if (temp_obj2.getPrimaryKey().equals(
0927: obj2.getPrimaryKey())) {
0928: newObject = false;
0929: temp_obj2.addActivitySet(obj1);
0930: break;
0931: }
0932: }
0933: if (newObject) {
0934: obj2.initActivitySets();
0935: obj2.addActivitySet(obj1);
0936: }
0937: results.add(obj1);
0938: }
0939: return results;
0940: }
0941:
0942: /**
0943: * selects a collection of ActivitySet objects pre-filled with
0944: * all related objects.
0945: *
0946: * This method is protected by default in order to keep the public
0947: * api reasonable. You can provide public methods for those you
0948: * actually need in ActivitySetPeer.
0949: *
0950: * @throws TorqueException Any exceptions caught during processing will be
0951: * rethrown wrapped into a TorqueException.
0952: */
0953: protected static List doSelectJoinAllExceptScarabUserImpl(
0954: Criteria criteria) throws TorqueException {
0955: return doSelectJoinAllExceptScarabUserImpl(criteria, null);
0956: }
0957:
0958: /**
0959: * selects a collection of ActivitySet objects pre-filled with
0960: * all related objects.
0961: *
0962: * This method is protected by default in order to keep the public
0963: * api reasonable. You can provide public methods for those you
0964: * actually need in ActivitySetPeer.
0965: *
0966: * @throws TorqueException Any exceptions caught during processing will be
0967: * rethrown wrapped into a TorqueException.
0968: */
0969: protected static List doSelectJoinAllExceptScarabUserImpl(
0970: Criteria criteria, Connection conn) throws TorqueException {
0971: setDbName(criteria);
0972:
0973: addSelectColumns(criteria);
0974: int offset2 = numColumns + 1;
0975:
0976: ActivitySetTypePeer.addSelectColumns(criteria);
0977: criteria.addJoin(ActivitySetPeer.TYPE_ID,
0978: ActivitySetTypePeer.TYPE_ID);
0979: int offset3 = offset2 + ActivitySetTypePeer.numColumns;
0980:
0981: AttachmentPeer.addSelectColumns(criteria);
0982: criteria.addJoin(ActivitySetPeer.ATTACHMENT_ID,
0983: AttachmentPeer.ATTACHMENT_ID);
0984:
0985: correctBooleans(criteria);
0986:
0987: List rows;
0988: if (conn == null) {
0989: rows = BasePeer.doSelect(criteria);
0990: } else {
0991: rows = BasePeer.doSelect(criteria, conn);
0992: }
0993:
0994: List results = new ArrayList();
0995:
0996: for (int i = 0; i < rows.size(); i++) {
0997: Record row = (Record) rows.get(i);
0998:
0999: Class omClass = ActivitySetPeer.getOMClass();
1000: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
1001: .row2Object(row, 1, omClass);
1002:
1003: omClass = ActivitySetTypePeer.getOMClass();
1004: ActivitySetType obj2 = (ActivitySetType) ActivitySetTypePeer
1005: .row2Object(row, offset2, omClass);
1006:
1007: boolean newObject = true;
1008: for (int j = 0; j < results.size(); j++) {
1009: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1010: ActivitySetType temp_obj2 = (ActivitySetType) temp_obj1
1011: .getActivitySetType();
1012: if (temp_obj2.getPrimaryKey().equals(
1013: obj2.getPrimaryKey())) {
1014: newObject = false;
1015: temp_obj2.addActivitySet(obj1);
1016: break;
1017: }
1018: }
1019: if (newObject) {
1020: obj2.initActivitySets();
1021: obj2.addActivitySet(obj1);
1022: }
1023:
1024: omClass = AttachmentPeer.getOMClass();
1025: Attachment obj3 = (Attachment) AttachmentPeer.row2Object(
1026: row, offset3, omClass);
1027:
1028: newObject = true;
1029: for (int j = 0; j < results.size(); j++) {
1030: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1031: Attachment temp_obj3 = (Attachment) temp_obj1
1032: .getAttachment();
1033: if (temp_obj3.getPrimaryKey().equals(
1034: obj3.getPrimaryKey())) {
1035: newObject = false;
1036: temp_obj3.addActivitySet(obj1);
1037: break;
1038: }
1039: }
1040: if (newObject) {
1041: obj3.initActivitySets();
1042: obj3.addActivitySet(obj1);
1043: }
1044: results.add(obj1);
1045: }
1046: return results;
1047: }
1048:
1049: /**
1050: * selects a collection of ActivitySet objects pre-filled with
1051: * all related objects.
1052: *
1053: * This method is protected by default in order to keep the public
1054: * api reasonable. You can provide public methods for those you
1055: * actually need in ActivitySetPeer.
1056: *
1057: * @throws TorqueException Any exceptions caught during processing will be
1058: * rethrown wrapped into a TorqueException.
1059: */
1060: protected static List doSelectJoinAllExceptActivitySetType(
1061: Criteria criteria) throws TorqueException {
1062: return doSelectJoinAllExceptActivitySetType(criteria, null);
1063: }
1064:
1065: /**
1066: * selects a collection of ActivitySet objects pre-filled with
1067: * all related objects.
1068: *
1069: * This method is protected by default in order to keep the public
1070: * api reasonable. You can provide public methods for those you
1071: * actually need in ActivitySetPeer.
1072: *
1073: * @throws TorqueException Any exceptions caught during processing will be
1074: * rethrown wrapped into a TorqueException.
1075: */
1076: protected static List doSelectJoinAllExceptActivitySetType(
1077: Criteria criteria, Connection conn) throws TorqueException {
1078: setDbName(criteria);
1079:
1080: addSelectColumns(criteria);
1081: int offset2 = numColumns + 1;
1082:
1083: ScarabUserImplPeer.addSelectColumns(criteria);
1084: criteria.addJoin(ActivitySetPeer.CREATED_BY,
1085: ScarabUserImplPeer.USER_ID);
1086: int offset3 = offset2 + ScarabUserImplPeer.numColumns;
1087:
1088: AttachmentPeer.addSelectColumns(criteria);
1089: criteria.addJoin(ActivitySetPeer.ATTACHMENT_ID,
1090: AttachmentPeer.ATTACHMENT_ID);
1091:
1092: correctBooleans(criteria);
1093:
1094: List rows;
1095: if (conn == null) {
1096: rows = BasePeer.doSelect(criteria);
1097: } else {
1098: rows = BasePeer.doSelect(criteria, conn);
1099: }
1100:
1101: List results = new ArrayList();
1102:
1103: for (int i = 0; i < rows.size(); i++) {
1104: Record row = (Record) rows.get(i);
1105:
1106: Class omClass = ActivitySetPeer.getOMClass();
1107: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
1108: .row2Object(row, 1, omClass);
1109:
1110: omClass = ScarabUserImplPeer.getOMClass();
1111: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
1112: .row2Object(row, offset2, omClass);
1113:
1114: boolean newObject = true;
1115: for (int j = 0; j < results.size(); j++) {
1116: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1117: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
1118: .getScarabUser();
1119: if (temp_obj2.getPrimaryKey().equals(
1120: obj2.getPrimaryKey())) {
1121: newObject = false;
1122: temp_obj2.addActivitySet(obj1);
1123: break;
1124: }
1125: }
1126: if (newObject) {
1127: obj2.initActivitySets();
1128: obj2.addActivitySet(obj1);
1129: }
1130:
1131: omClass = AttachmentPeer.getOMClass();
1132: Attachment obj3 = (Attachment) AttachmentPeer.row2Object(
1133: row, offset3, omClass);
1134:
1135: newObject = true;
1136: for (int j = 0; j < results.size(); j++) {
1137: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1138: Attachment temp_obj3 = (Attachment) temp_obj1
1139: .getAttachment();
1140: if (temp_obj3.getPrimaryKey().equals(
1141: obj3.getPrimaryKey())) {
1142: newObject = false;
1143: temp_obj3.addActivitySet(obj1);
1144: break;
1145: }
1146: }
1147: if (newObject) {
1148: obj3.initActivitySets();
1149: obj3.addActivitySet(obj1);
1150: }
1151: results.add(obj1);
1152: }
1153: return results;
1154: }
1155:
1156: /**
1157: * selects a collection of ActivitySet objects pre-filled with
1158: * all related objects.
1159: *
1160: * This method is protected by default in order to keep the public
1161: * api reasonable. You can provide public methods for those you
1162: * actually need in ActivitySetPeer.
1163: *
1164: * @throws TorqueException Any exceptions caught during processing will be
1165: * rethrown wrapped into a TorqueException.
1166: */
1167: protected static List doSelectJoinAllExceptAttachment(
1168: Criteria criteria) throws TorqueException {
1169: return doSelectJoinAllExceptAttachment(criteria, null);
1170: }
1171:
1172: /**
1173: * selects a collection of ActivitySet objects pre-filled with
1174: * all related objects.
1175: *
1176: * This method is protected by default in order to keep the public
1177: * api reasonable. You can provide public methods for those you
1178: * actually need in ActivitySetPeer.
1179: *
1180: * @throws TorqueException Any exceptions caught during processing will be
1181: * rethrown wrapped into a TorqueException.
1182: */
1183: protected static List doSelectJoinAllExceptAttachment(
1184: Criteria criteria, Connection conn) throws TorqueException {
1185: setDbName(criteria);
1186:
1187: addSelectColumns(criteria);
1188: int offset2 = numColumns + 1;
1189:
1190: ScarabUserImplPeer.addSelectColumns(criteria);
1191: criteria.addJoin(ActivitySetPeer.CREATED_BY,
1192: ScarabUserImplPeer.USER_ID);
1193: int offset3 = offset2 + ScarabUserImplPeer.numColumns;
1194:
1195: ActivitySetTypePeer.addSelectColumns(criteria);
1196: criteria.addJoin(ActivitySetPeer.TYPE_ID,
1197: ActivitySetTypePeer.TYPE_ID);
1198:
1199: correctBooleans(criteria);
1200:
1201: List rows;
1202: if (conn == null) {
1203: rows = BasePeer.doSelect(criteria);
1204: } else {
1205: rows = BasePeer.doSelect(criteria, conn);
1206: }
1207:
1208: List results = new ArrayList();
1209:
1210: for (int i = 0; i < rows.size(); i++) {
1211: Record row = (Record) rows.get(i);
1212:
1213: Class omClass = ActivitySetPeer.getOMClass();
1214: ActivitySet obj1 = (ActivitySet) ActivitySetPeer
1215: .row2Object(row, 1, omClass);
1216:
1217: omClass = ScarabUserImplPeer.getOMClass();
1218: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
1219: .row2Object(row, offset2, omClass);
1220:
1221: boolean newObject = true;
1222: for (int j = 0; j < results.size(); j++) {
1223: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1224: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
1225: .getScarabUser();
1226: if (temp_obj2.getPrimaryKey().equals(
1227: obj2.getPrimaryKey())) {
1228: newObject = false;
1229: temp_obj2.addActivitySet(obj1);
1230: break;
1231: }
1232: }
1233: if (newObject) {
1234: obj2.initActivitySets();
1235: obj2.addActivitySet(obj1);
1236: }
1237:
1238: omClass = ActivitySetTypePeer.getOMClass();
1239: ActivitySetType obj3 = (ActivitySetType) ActivitySetTypePeer
1240: .row2Object(row, offset3, omClass);
1241:
1242: newObject = true;
1243: for (int j = 0; j < results.size(); j++) {
1244: ActivitySet temp_obj1 = (ActivitySet) results.get(j);
1245: ActivitySetType temp_obj3 = (ActivitySetType) temp_obj1
1246: .getActivitySetType();
1247: if (temp_obj3.getPrimaryKey().equals(
1248: obj3.getPrimaryKey())) {
1249: newObject = false;
1250: temp_obj3.addActivitySet(obj1);
1251: break;
1252: }
1253: }
1254: if (newObject) {
1255: obj3.initActivitySets();
1256: obj3.addActivitySet(obj1);
1257: }
1258:
1259: results.add(obj1);
1260: }
1261: return results;
1262: }
1263:
1264: /**
1265: * Returns the TableMap related to this peer. This method is not
1266: * needed for general use but a specific application could have a need.
1267: *
1268: * @throws TorqueException Any exceptions caught during processing will be
1269: * rethrown wrapped into a TorqueException.
1270: */
1271: protected static TableMap getTableMap() throws TorqueException {
1272: return Torque.getDatabaseMap(DATABASE_NAME)
1273: .getTable(TABLE_NAME);
1274: }
1275:
1276: private static void setDbName(Criteria crit) {
1277: // Set the correct dbName if it has not been overridden
1278: // crit.getDbName will return the same object if not set to
1279: // another value so == check is okay and faster
1280: if (crit.getDbName() == Torque.getDefaultDB()) {
1281: crit.setDbName(DATABASE_NAME);
1282: }
1283: }
1284: }
|