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