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 BaseAttachmentPeer 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_ATTACHMENT";
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(AttachmentMapBuilder.CLASS_NAME);
0050: }
0051:
0052: /** the column name for the ATTACHMENT_ID field */
0053: public static final String ATTACHMENT_ID;
0054: /** the column name for the ISSUE_ID field */
0055: public static final String ISSUE_ID;
0056: /** the column name for the ATTACHMENT_TYPE_ID field */
0057: public static final String ATTACHMENT_TYPE_ID;
0058: /** the column name for the ATTACHMENT_NAME field */
0059: public static final String ATTACHMENT_NAME;
0060: /** the column name for the ATTACHMENT_DATA field */
0061: public static final String ATTACHMENT_DATA;
0062: /** the column name for the ATTACHMENT_FILE_PATH field */
0063: public static final String ATTACHMENT_FILE_PATH;
0064: /** the column name for the ATTACHMENT_MIME_TYPE field */
0065: public static final String ATTACHMENT_MIME_TYPE;
0066: /** the column name for the MODIFIED_BY field */
0067: public static final String MODIFIED_BY;
0068: /** the column name for the CREATED_BY field */
0069: public static final String CREATED_BY;
0070: /** the column name for the MODIFIED_DATE field */
0071: public static final String MODIFIED_DATE;
0072: /** the column name for the CREATED_DATE field */
0073: public static final String CREATED_DATE;
0074: /** the column name for the DELETED field */
0075: public static final String DELETED;
0076:
0077: static {
0078: ATTACHMENT_ID = "SCARAB_ATTACHMENT.ATTACHMENT_ID";
0079: ISSUE_ID = "SCARAB_ATTACHMENT.ISSUE_ID";
0080: ATTACHMENT_TYPE_ID = "SCARAB_ATTACHMENT.ATTACHMENT_TYPE_ID";
0081: ATTACHMENT_NAME = "SCARAB_ATTACHMENT.ATTACHMENT_NAME";
0082: ATTACHMENT_DATA = "SCARAB_ATTACHMENT.ATTACHMENT_DATA";
0083: ATTACHMENT_FILE_PATH = "SCARAB_ATTACHMENT.ATTACHMENT_FILE_PATH";
0084: ATTACHMENT_MIME_TYPE = "SCARAB_ATTACHMENT.ATTACHMENT_MIME_TYPE";
0085: MODIFIED_BY = "SCARAB_ATTACHMENT.MODIFIED_BY";
0086: CREATED_BY = "SCARAB_ATTACHMENT.CREATED_BY";
0087: MODIFIED_DATE = "SCARAB_ATTACHMENT.MODIFIED_DATE";
0088: CREATED_DATE = "SCARAB_ATTACHMENT.CREATED_DATE";
0089: DELETED = "SCARAB_ATTACHMENT.DELETED";
0090: if (Torque.isInit()) {
0091: try {
0092: getMapBuilder(AttachmentMapBuilder.CLASS_NAME);
0093: } catch (Exception e) {
0094: log.error("Could not initialize Peer", e);
0095: throw new RuntimeException(e);
0096: }
0097: } else {
0098: Torque.registerMapBuilder(AttachmentMapBuilder.CLASS_NAME);
0099: }
0100: }
0101:
0102: /** number of columns for this peer */
0103: public static final int numColumns = 12;
0104:
0105: /** A class that can be returned by this peer. */
0106: protected static final String CLASSNAME_DEFAULT = "org.tigris.scarab.om.Attachment";
0107:
0108: /** A class that can be returned by this peer. */
0109: protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
0110:
0111: /**
0112: * Class object initialization method.
0113: *
0114: * @param className name of the class to initialize
0115: * @return the initialized class
0116: */
0117: private static Class initClass(String className) {
0118: Class c = null;
0119: try {
0120: c = Class.forName(className);
0121: } catch (Throwable t) {
0122: log
0123: .error(
0124: "A FATAL ERROR has occurred which should not "
0125: + "have happened under any circumstance. Please notify "
0126: + "the Torque developers <torque-dev@db.apache.org> "
0127: + "and give as many details as possible (including the error "
0128: + "stack trace).", t);
0129:
0130: // Error objects should always be propogated.
0131: if (t instanceof Error) {
0132: throw (Error) t.fillInStackTrace();
0133: }
0134: }
0135: return c;
0136: }
0137:
0138: /**
0139: * Get the list of objects for a ResultSet. Please not that your
0140: * resultset MUST return columns in the right order. You can use
0141: * getFieldNames() in BaseObject to get the correct sequence.
0142: *
0143: * @param results the ResultSet
0144: * @return the list of objects
0145: * @throws TorqueException Any exceptions caught during processing will be
0146: * rethrown wrapped into a TorqueException.
0147: */
0148: public static List resultSet2Objects(java.sql.ResultSet results)
0149: throws TorqueException {
0150: try {
0151: QueryDataSet qds = null;
0152: List rows = null;
0153: try {
0154: qds = new QueryDataSet(results);
0155: rows = getSelectResults(qds);
0156: } finally {
0157: if (qds != null) {
0158: qds.close();
0159: }
0160: }
0161:
0162: return populateObjects(rows);
0163: } catch (SQLException e) {
0164: throw new TorqueException(e);
0165: } catch (DataSetException e) {
0166: throw new TorqueException(e);
0167: }
0168: }
0169:
0170: /**
0171: * Method to do inserts.
0172: *
0173: * @param criteria object used to create the INSERT statement.
0174: * @throws TorqueException Any exceptions caught during processing will be
0175: * rethrown wrapped into a TorqueException.
0176: */
0177: public static ObjectKey doInsert(Criteria criteria)
0178: throws TorqueException {
0179: return BaseAttachmentPeer.doInsert(criteria, (Connection) null);
0180: }
0181:
0182: /**
0183: * Method to do inserts. This method is to be used during a transaction,
0184: * otherwise use the doInsert(Criteria) method. It will take care of
0185: * the connection details internally.
0186: *
0187: * @param criteria object used to create the INSERT statement.
0188: * @param con the connection to use
0189: * @throws TorqueException Any exceptions caught during processing will be
0190: * rethrown wrapped into a TorqueException.
0191: */
0192: public static ObjectKey doInsert(Criteria criteria, Connection con)
0193: throws TorqueException {
0194: correctBooleans(criteria);
0195:
0196: setDbName(criteria);
0197:
0198: if (con == null) {
0199: return BasePeer.doInsert(criteria);
0200: } else {
0201: return BasePeer.doInsert(criteria, con);
0202: }
0203: }
0204:
0205: /**
0206: * Add all the columns needed to create a new object.
0207: *
0208: * @param criteria object containing the columns to add.
0209: * @throws TorqueException Any exceptions caught during processing will be
0210: * rethrown wrapped into a TorqueException.
0211: */
0212: public static void addSelectColumns(Criteria criteria)
0213: throws TorqueException {
0214: criteria.addSelectColumn(ATTACHMENT_ID);
0215: criteria.addSelectColumn(ISSUE_ID);
0216: criteria.addSelectColumn(ATTACHMENT_TYPE_ID);
0217: criteria.addSelectColumn(ATTACHMENT_NAME);
0218: criteria.addSelectColumn(ATTACHMENT_DATA);
0219: criteria.addSelectColumn(ATTACHMENT_FILE_PATH);
0220: criteria.addSelectColumn(ATTACHMENT_MIME_TYPE);
0221: criteria.addSelectColumn(MODIFIED_BY);
0222: criteria.addSelectColumn(CREATED_BY);
0223: criteria.addSelectColumn(MODIFIED_DATE);
0224: criteria.addSelectColumn(CREATED_DATE);
0225: criteria.addSelectColumn(DELETED);
0226: }
0227:
0228: /**
0229: * changes the boolean values in the criteria to the appropriate type,
0230: * whenever a booleanchar or booleanint column is involved.
0231: * This enables the user to create criteria using Boolean values
0232: * for booleanchar or booleanint columns
0233: * @param criteria the criteria in which the boolean values should be corrected
0234: */
0235: public static void correctBooleans(Criteria criteria) {
0236: // check for conversion from boolean to int
0237: if (criteria.containsKey(DELETED)) {
0238: Object possibleBoolean = criteria.get(DELETED);
0239: if (possibleBoolean instanceof Boolean) {
0240: criteria.add(DELETED, ((Boolean) possibleBoolean)
0241: .booleanValue() ? 1 : 0);
0242: }
0243: }
0244: }
0245:
0246: /**
0247: * Create a new object of type cls from a resultset row starting
0248: * from a specified offset. This is done so that you can select
0249: * other rows than just those needed for this object. You may
0250: * for example want to create two objects from the same row.
0251: *
0252: * @throws TorqueException Any exceptions caught during processing will be
0253: * rethrown wrapped into a TorqueException.
0254: */
0255: public static Attachment row2Object(Record row, int offset,
0256: Class cls) throws TorqueException {
0257: try {
0258: Attachment obj = (Attachment) cls.newInstance();
0259: AttachmentPeer.populateObject(row, offset, obj);
0260: obj.setModified(false);
0261: obj.setNew(false);
0262:
0263: return obj;
0264: } catch (InstantiationException e) {
0265: throw new TorqueException(e);
0266: } catch (IllegalAccessException e) {
0267: throw new TorqueException(e);
0268: }
0269: }
0270:
0271: /**
0272: * Populates an object from a resultset row starting
0273: * from a specified offset. This is done so that you can select
0274: * other rows than just those needed for this object. You may
0275: * for example want to create two objects from the same row.
0276: *
0277: * @throws TorqueException Any exceptions caught during processing will be
0278: * rethrown wrapped into a TorqueException.
0279: */
0280: public static void populateObject(Record row, int offset,
0281: Attachment obj) throws TorqueException {
0282: try {
0283: obj.setAttachmentId(row.getValue(offset + 0).asLongObj());
0284: obj.setIssueId(row.getValue(offset + 1).asLongObj());
0285: obj.setTypeId(row.getValue(offset + 2).asIntegerObj());
0286: obj.setName(row.getValue(offset + 3).asString());
0287: obj.setData(row.getValue(offset + 4).asString());
0288: obj.setFileName(row.getValue(offset + 5).asString());
0289: obj.setMimeType(row.getValue(offset + 6).asString());
0290: obj.setModifiedBy(row.getValue(offset + 7).asIntegerObj());
0291: obj.setCreatedBy(row.getValue(offset + 8).asIntegerObj());
0292: obj.setModifiedDate(row.getValue(offset + 9).asUtilDate());
0293: obj.setCreatedDate(row.getValue(offset + 10).asUtilDate());
0294: obj.setDeleted(row.getValue(offset + 11).asBoolean());
0295: } catch (DataSetException e) {
0296: throw new TorqueException(e);
0297: }
0298: }
0299:
0300: /**
0301: * Method to do selects.
0302: *
0303: * @param criteria object used to create the SELECT statement.
0304: * @return List of selected Objects
0305: * @throws TorqueException Any exceptions caught during processing will be
0306: * rethrown wrapped into a TorqueException.
0307: */
0308: public static List doSelect(Criteria criteria)
0309: throws TorqueException {
0310: return populateObjects(doSelectVillageRecords(criteria));
0311: }
0312:
0313: /**
0314: * Method to do selects within a transaction.
0315: *
0316: * @param criteria object used to create the SELECT statement.
0317: * @param con the connection to use
0318: * @return List of selected Objects
0319: * @throws TorqueException Any exceptions caught during processing will be
0320: * rethrown wrapped into a TorqueException.
0321: */
0322: public static List doSelect(Criteria criteria, Connection con)
0323: throws TorqueException {
0324: return populateObjects(doSelectVillageRecords(criteria, con));
0325: }
0326:
0327: /**
0328: * Grabs the raw Village records to be formed into objects.
0329: * This method handles connections internally. The Record objects
0330: * returned by this method should be considered readonly. Do not
0331: * alter the data and call save(), your results may vary, but are
0332: * certainly likely to result in hard to track MT bugs.
0333: *
0334: * @throws TorqueException Any exceptions caught during processing will be
0335: * rethrown wrapped into a TorqueException.
0336: */
0337: public static List doSelectVillageRecords(Criteria criteria)
0338: throws TorqueException {
0339: return BaseAttachmentPeer.doSelectVillageRecords(criteria,
0340: (Connection) null);
0341: }
0342:
0343: /**
0344: * Grabs the raw Village records to be formed into objects.
0345: * This method should be used for transactions
0346: *
0347: * @param criteria object used to create the SELECT statement.
0348: * @param con the connection to use
0349: * @throws TorqueException Any exceptions caught during processing will be
0350: * rethrown wrapped into a TorqueException.
0351: */
0352: public static List doSelectVillageRecords(Criteria criteria,
0353: Connection con) throws TorqueException {
0354: if (criteria.getSelectColumns().size() == 0) {
0355: addSelectColumns(criteria);
0356: }
0357: correctBooleans(criteria);
0358:
0359: setDbName(criteria);
0360:
0361: // BasePeer returns a List of Value (Village) arrays. The array
0362: // order follows the order columns were placed in the Select clause.
0363: if (con == null) {
0364: return BasePeer.doSelect(criteria);
0365: } else {
0366: return BasePeer.doSelect(criteria, con);
0367: }
0368: }
0369:
0370: /**
0371: * The returned List will contain objects of the default type or
0372: * objects that inherit from the default.
0373: *
0374: * @throws TorqueException Any exceptions caught during processing will be
0375: * rethrown wrapped into a TorqueException.
0376: */
0377: public static List populateObjects(List records)
0378: throws TorqueException {
0379: List results = new ArrayList(records.size());
0380:
0381: // populate the object(s)
0382: for (int i = 0; i < records.size(); i++) {
0383: Record row = (Record) records.get(i);
0384: results.add(AttachmentPeer.row2Object(row, 1,
0385: AttachmentPeer.getOMClass()));
0386: }
0387: return results;
0388: }
0389:
0390: /**
0391: * The class that the Peer will make instances of.
0392: * If the BO is abstract then you must implement this method
0393: * in the BO.
0394: *
0395: * @throws TorqueException Any exceptions caught during processing will be
0396: * rethrown wrapped into a TorqueException.
0397: */
0398: public static Class getOMClass() throws TorqueException {
0399: return CLASS_DEFAULT;
0400: }
0401:
0402: /**
0403: * Method to do updates.
0404: *
0405: * @param criteria object containing data that is used to create the UPDATE
0406: * statement.
0407: * @throws TorqueException Any exceptions caught during processing will be
0408: * rethrown wrapped into a TorqueException.
0409: */
0410: public static void doUpdate(Criteria criteria)
0411: throws TorqueException {
0412: BaseAttachmentPeer.doUpdate(criteria, (Connection) null);
0413: }
0414:
0415: /**
0416: * Method to do updates. This method is to be used during a transaction,
0417: * otherwise use the doUpdate(Criteria) method. It will take care of
0418: * the connection details internally.
0419: *
0420: * @param criteria object containing data that is used to create the UPDATE
0421: * statement.
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 doUpdate(Criteria criteria, Connection con)
0427: throws TorqueException {
0428: Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
0429: correctBooleans(criteria);
0430:
0431: selectCriteria.put(ATTACHMENT_ID, criteria
0432: .remove(ATTACHMENT_ID));
0433:
0434: setDbName(criteria);
0435:
0436: if (con == null) {
0437: BasePeer.doUpdate(selectCriteria, criteria);
0438: } else {
0439: BasePeer.doUpdate(selectCriteria, criteria, con);
0440: }
0441: }
0442:
0443: /**
0444: * Method to do deletes.
0445: *
0446: * @param criteria object containing data that is used DELETE from database.
0447: * @throws TorqueException Any exceptions caught during processing will be
0448: * rethrown wrapped into a TorqueException.
0449: */
0450: public static void doDelete(Criteria criteria)
0451: throws TorqueException {
0452: AttachmentPeer.doDelete(criteria, (Connection) null);
0453: }
0454:
0455: /**
0456: * Method to do deletes. This method is to be used during a transaction,
0457: * otherwise use the doDelete(Criteria) method. It will take care of
0458: * the connection details internally.
0459: *
0460: * @param criteria object containing data that is used DELETE from database.
0461: * @param con the connection to use
0462: * @throws TorqueException Any exceptions caught during processing will be
0463: * rethrown wrapped into a TorqueException.
0464: */
0465: public static void doDelete(Criteria criteria, Connection con)
0466: throws TorqueException {
0467: correctBooleans(criteria);
0468:
0469: setDbName(criteria);
0470:
0471: if (con == null) {
0472: BasePeer.doDelete(criteria);
0473: } else {
0474: BasePeer.doDelete(criteria, con);
0475: }
0476: }
0477:
0478: /**
0479: * Method to do selects
0480: *
0481: * @throws TorqueException Any exceptions caught during processing will be
0482: * rethrown wrapped into a TorqueException.
0483: */
0484: public static List doSelect(Attachment obj) throws TorqueException {
0485: return doSelect(buildSelectCriteria(obj));
0486: }
0487:
0488: /**
0489: * Method to do inserts
0490: *
0491: * @throws TorqueException Any exceptions caught during processing will be
0492: * rethrown wrapped into a TorqueException.
0493: */
0494: public static void doInsert(Attachment obj) throws TorqueException {
0495: obj.setPrimaryKey(doInsert(buildCriteria(obj)));
0496: obj.setNew(false);
0497: obj.setModified(false);
0498: }
0499:
0500: /**
0501: * @param obj the data object to update in the database.
0502: * @throws TorqueException Any exceptions caught during processing will be
0503: * rethrown wrapped into a TorqueException.
0504: */
0505: public static void doUpdate(Attachment obj) throws TorqueException {
0506: doUpdate(buildCriteria(obj));
0507: obj.setModified(false);
0508: }
0509:
0510: /**
0511: * @param obj the data object to delete in the database.
0512: * @throws TorqueException Any exceptions caught during processing will be
0513: * rethrown wrapped into a TorqueException.
0514: */
0515: public static void doDelete(Attachment obj) throws TorqueException {
0516: doDelete(buildSelectCriteria(obj));
0517: }
0518:
0519: /**
0520: * Method to do inserts. This method is to be used during a transaction,
0521: * otherwise use the doInsert(Attachment) method. It will take
0522: * care of the connection details internally.
0523: *
0524: * @param obj the data object to insert into the database.
0525: * @param con the connection to use
0526: * @throws TorqueException Any exceptions caught during processing will be
0527: * rethrown wrapped into a TorqueException.
0528: */
0529: public static void doInsert(Attachment obj, Connection con)
0530: throws TorqueException {
0531: obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
0532: obj.setNew(false);
0533: obj.setModified(false);
0534: }
0535:
0536: /**
0537: * Method to do update. This method is to be used during a transaction,
0538: * otherwise use the doUpdate(Attachment) method. It will take
0539: * care of the connection details internally.
0540: *
0541: * @param obj the data object to update 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 doUpdate(Attachment obj, Connection con)
0547: throws TorqueException {
0548: doUpdate(buildCriteria(obj), con);
0549: obj.setModified(false);
0550: }
0551:
0552: /**
0553: * Method to delete. This method is to be used during a transaction,
0554: * otherwise use the doDelete(Attachment) method. It will take
0555: * care of the connection details internally.
0556: *
0557: * @param obj the data object to delete in the database.
0558: * @param con the connection to use
0559: * @throws TorqueException Any exceptions caught during processing will be
0560: * rethrown wrapped into a TorqueException.
0561: */
0562: public static void doDelete(Attachment obj, Connection con)
0563: throws TorqueException {
0564: doDelete(buildSelectCriteria(obj), con);
0565: }
0566:
0567: /**
0568: * Method to do deletes.
0569: *
0570: * @param pk ObjectKey that is used DELETE from database.
0571: * @throws TorqueException Any exceptions caught during processing will be
0572: * rethrown wrapped into a TorqueException.
0573: */
0574: public static void doDelete(ObjectKey pk) throws TorqueException {
0575: BaseAttachmentPeer.doDelete(pk, (Connection) null);
0576: }
0577:
0578: /**
0579: * Method to delete. This method is to be used during a transaction,
0580: * otherwise use the doDelete(ObjectKey) method. It will take
0581: * care of the connection details internally.
0582: *
0583: * @param pk the primary key for the object to delete in the database.
0584: * @param con the connection to use
0585: * @throws TorqueException Any exceptions caught during processing will be
0586: * rethrown wrapped into a TorqueException.
0587: */
0588: public static void doDelete(ObjectKey pk, Connection con)
0589: throws TorqueException {
0590: doDelete(buildCriteria(pk), con);
0591: }
0592:
0593: /** Build a Criteria object from an ObjectKey */
0594: public static Criteria buildCriteria(ObjectKey pk) {
0595: Criteria criteria = new Criteria();
0596: criteria.add(ATTACHMENT_ID, pk);
0597: return criteria;
0598: }
0599:
0600: /** Build a Criteria object from the data object for this peer */
0601: public static Criteria buildCriteria(Attachment obj) {
0602: Criteria criteria = new Criteria(DATABASE_NAME);
0603: if (!obj.isNew())
0604: criteria.add(ATTACHMENT_ID, obj.getAttachmentId());
0605: criteria.add(ISSUE_ID, obj.getIssueId());
0606: criteria.add(ATTACHMENT_TYPE_ID, obj.getTypeId());
0607: criteria.add(ATTACHMENT_NAME, obj.getName());
0608: criteria.add(ATTACHMENT_DATA, obj.getData());
0609: criteria.add(ATTACHMENT_FILE_PATH, obj.getFileName());
0610: criteria.add(ATTACHMENT_MIME_TYPE, obj.getMimeType());
0611: criteria.add(MODIFIED_BY, obj.getModifiedBy());
0612: criteria.add(CREATED_BY, obj.getCreatedBy());
0613: criteria.add(MODIFIED_DATE, obj.getModifiedDate());
0614: criteria.add(CREATED_DATE, obj.getCreatedDate());
0615: criteria.add(DELETED, obj.getDeleted());
0616: return criteria;
0617: }
0618:
0619: /** Build a Criteria object from the data object for this peer, skipping all binary columns */
0620: public static Criteria buildSelectCriteria(Attachment obj) {
0621: Criteria criteria = new Criteria(DATABASE_NAME);
0622: if (!obj.isNew()) {
0623: criteria.add(ATTACHMENT_ID, obj.getAttachmentId());
0624: }
0625: criteria.add(ISSUE_ID, obj.getIssueId());
0626: criteria.add(ATTACHMENT_TYPE_ID, obj.getTypeId());
0627: criteria.add(ATTACHMENT_NAME, obj.getName());
0628: criteria.add(ATTACHMENT_DATA, obj.getData());
0629: criteria.add(ATTACHMENT_FILE_PATH, obj.getFileName());
0630: criteria.add(ATTACHMENT_MIME_TYPE, obj.getMimeType());
0631: criteria.add(MODIFIED_BY, obj.getModifiedBy());
0632: criteria.add(CREATED_BY, obj.getCreatedBy());
0633: criteria.add(MODIFIED_DATE, obj.getModifiedDate());
0634: criteria.add(CREATED_DATE, obj.getCreatedDate());
0635: criteria.add(DELETED, obj.getDeleted());
0636: return criteria;
0637: }
0638:
0639: /**
0640: * Retrieve a single object by pk
0641: *
0642: * @param pk the primary key
0643: * @throws TorqueException Any exceptions caught during processing will be
0644: * rethrown wrapped into a TorqueException.
0645: * @throws NoRowsException Primary key was not found in database.
0646: * @throws TooManyRowsException Primary key was not found in database.
0647: */
0648: public static Attachment retrieveByPK(Long pk)
0649: throws TorqueException, NoRowsException,
0650: TooManyRowsException {
0651: return retrieveByPK(SimpleKey.keyFor(pk));
0652: }
0653:
0654: /**
0655: * Retrieve a single object by pk
0656: *
0657: * @param pk the primary key
0658: * @param con the connection to use
0659: * @throws TorqueException Any exceptions caught during processing will be
0660: * rethrown wrapped into a TorqueException.
0661: * @throws NoRowsException Primary key was not found in database.
0662: * @throws TooManyRowsException Primary key was not found in database.
0663: */
0664: public static Attachment retrieveByPK(Long pk, Connection con)
0665: throws TorqueException, NoRowsException,
0666: TooManyRowsException {
0667: return retrieveByPK(SimpleKey.keyFor(pk), con);
0668: }
0669:
0670: /**
0671: * Retrieve a single object by pk
0672: *
0673: * @param pk the primary key
0674: * @throws TorqueException Any exceptions caught during processing will be
0675: * rethrown wrapped into a TorqueException.
0676: * @throws NoRowsException Primary key was not found in database.
0677: * @throws TooManyRowsException Primary key was not found in database.
0678: */
0679: public static Attachment retrieveByPK(ObjectKey pk)
0680: throws TorqueException, NoRowsException,
0681: TooManyRowsException {
0682: Connection db = null;
0683: Attachment retVal = null;
0684: try {
0685: db = Torque.getConnection(DATABASE_NAME);
0686: retVal = retrieveByPK(pk, db);
0687: } finally {
0688: Torque.closeConnection(db);
0689: }
0690: return retVal;
0691: }
0692:
0693: /**
0694: * Retrieve a single object by pk
0695: *
0696: * @param pk the primary key
0697: * @param con the connection to use
0698: * @throws TorqueException Any exceptions caught during processing will be
0699: * rethrown wrapped into a TorqueException.
0700: * @throws NoRowsException Primary key was not found in database.
0701: * @throws TooManyRowsException Primary key was not found in database.
0702: */
0703: public static Attachment retrieveByPK(ObjectKey pk, Connection con)
0704: throws TorqueException, NoRowsException,
0705: TooManyRowsException {
0706: Criteria criteria = buildCriteria(pk);
0707: List v = doSelect(criteria, con);
0708: if (v.size() == 0) {
0709: throw new NoRowsException("Failed to select a row.");
0710: } else if (v.size() > 1) {
0711: throw new TooManyRowsException(
0712: "Failed to select only one row.");
0713: } else {
0714: return (Attachment) v.get(0);
0715: }
0716: }
0717:
0718: /**
0719: * Retrieve a multiple objects by pk
0720: *
0721: * @param pks List of primary keys
0722: * @throws TorqueException Any exceptions caught during processing will be
0723: * rethrown wrapped into a TorqueException.
0724: */
0725: public static List retrieveByPKs(List pks) throws TorqueException {
0726: Connection db = null;
0727: List retVal = null;
0728: try {
0729: db = Torque.getConnection(DATABASE_NAME);
0730: retVal = retrieveByPKs(pks, db);
0731: } finally {
0732: Torque.closeConnection(db);
0733: }
0734: return retVal;
0735: }
0736:
0737: /**
0738: * Retrieve a multiple objects by pk
0739: *
0740: * @param pks List of primary keys
0741: * @param dbcon the connection to use
0742: * @throws TorqueException Any exceptions caught during processing will be
0743: * rethrown wrapped into a TorqueException.
0744: */
0745: public static List retrieveByPKs(List pks, Connection dbcon)
0746: throws TorqueException {
0747: List objs = null;
0748: if (pks == null || pks.size() == 0) {
0749: objs = new LinkedList();
0750: } else {
0751: Criteria criteria = new Criteria();
0752: criteria.addIn(ATTACHMENT_ID, pks);
0753: objs = doSelect(criteria, dbcon);
0754: }
0755: return objs;
0756: }
0757:
0758: /**
0759: * selects a collection of Attachment objects pre-filled with their
0760: * Issue objects.
0761: *
0762: * This method is protected by default in order to keep the public
0763: * api reasonable. You can provide public methods for those you
0764: * actually need in AttachmentPeer.
0765: *
0766: * @throws TorqueException Any exceptions caught during processing will be
0767: * rethrown wrapped into a TorqueException.
0768: */
0769: protected static List doSelectJoinIssue(Criteria criteria)
0770: throws TorqueException {
0771: return doSelectJoinIssue(criteria, null);
0772: }
0773:
0774: /**
0775: * selects a collection of Attachment objects pre-filled with their
0776: * Issue objects.
0777: *
0778: * This method is protected by default in order to keep the public
0779: * api reasonable. You can provide public methods for those you
0780: * actually need in AttachmentPeer.
0781: *
0782: * @throws TorqueException Any exceptions caught during processing will be
0783: * rethrown wrapped into a TorqueException.
0784: */
0785: protected static List doSelectJoinIssue(Criteria criteria,
0786: Connection conn) throws TorqueException {
0787: setDbName(criteria);
0788:
0789: AttachmentPeer.addSelectColumns(criteria);
0790: int offset = numColumns + 1;
0791: IssuePeer.addSelectColumns(criteria);
0792:
0793: criteria.addJoin(AttachmentPeer.ISSUE_ID, IssuePeer.ISSUE_ID);
0794:
0795: correctBooleans(criteria);
0796:
0797: List rows;
0798: if (conn == null) {
0799: rows = BasePeer.doSelect(criteria);
0800: } else {
0801: rows = BasePeer.doSelect(criteria, conn);
0802: }
0803:
0804: List results = new ArrayList();
0805:
0806: for (int i = 0; i < rows.size(); i++) {
0807: Record row = (Record) rows.get(i);
0808:
0809: Class omClass = AttachmentPeer.getOMClass();
0810: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
0811: row, 1, omClass);
0812: omClass = IssuePeer.getOMClass();
0813: Issue obj2 = (Issue) IssuePeer.row2Object(row, offset,
0814: omClass);
0815:
0816: boolean newObject = true;
0817: for (int j = 0; j < results.size(); j++) {
0818: Attachment temp_obj1 = (Attachment) results.get(j);
0819: Issue temp_obj2 = (Issue) temp_obj1.getIssue();
0820: if (temp_obj2.getPrimaryKey().equals(
0821: obj2.getPrimaryKey())) {
0822: newObject = false;
0823: temp_obj2.addAttachment(obj1);
0824: break;
0825: }
0826: }
0827: if (newObject) {
0828: obj2.initAttachments();
0829: obj2.addAttachment(obj1);
0830: }
0831: results.add(obj1);
0832: }
0833: return results;
0834: }
0835:
0836: /**
0837: * selects a collection of Attachment objects pre-filled with their
0838: * AttachmentType objects.
0839: *
0840: * This method is protected by default in order to keep the public
0841: * api reasonable. You can provide public methods for those you
0842: * actually need in AttachmentPeer.
0843: *
0844: * @throws TorqueException Any exceptions caught during processing will be
0845: * rethrown wrapped into a TorqueException.
0846: */
0847: protected static List doSelectJoinAttachmentType(Criteria criteria)
0848: throws TorqueException {
0849: return doSelectJoinAttachmentType(criteria, null);
0850: }
0851:
0852: /**
0853: * selects a collection of Attachment objects pre-filled with their
0854: * AttachmentType objects.
0855: *
0856: * This method is protected by default in order to keep the public
0857: * api reasonable. You can provide public methods for those you
0858: * actually need in AttachmentPeer.
0859: *
0860: * @throws TorqueException Any exceptions caught during processing will be
0861: * rethrown wrapped into a TorqueException.
0862: */
0863: protected static List doSelectJoinAttachmentType(Criteria criteria,
0864: Connection conn) throws TorqueException {
0865: setDbName(criteria);
0866:
0867: AttachmentPeer.addSelectColumns(criteria);
0868: int offset = numColumns + 1;
0869: AttachmentTypePeer.addSelectColumns(criteria);
0870:
0871: criteria.addJoin(AttachmentPeer.ATTACHMENT_TYPE_ID,
0872: AttachmentTypePeer.ATTACHMENT_TYPE_ID);
0873:
0874: correctBooleans(criteria);
0875:
0876: List rows;
0877: if (conn == null) {
0878: rows = BasePeer.doSelect(criteria);
0879: } else {
0880: rows = BasePeer.doSelect(criteria, conn);
0881: }
0882:
0883: List results = new ArrayList();
0884:
0885: for (int i = 0; i < rows.size(); i++) {
0886: Record row = (Record) rows.get(i);
0887:
0888: Class omClass = AttachmentPeer.getOMClass();
0889: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
0890: row, 1, omClass);
0891: omClass = AttachmentTypePeer.getOMClass();
0892: AttachmentType obj2 = (AttachmentType) AttachmentTypePeer
0893: .row2Object(row, offset, omClass);
0894:
0895: boolean newObject = true;
0896: for (int j = 0; j < results.size(); j++) {
0897: Attachment temp_obj1 = (Attachment) results.get(j);
0898: AttachmentType temp_obj2 = (AttachmentType) temp_obj1
0899: .getAttachmentType();
0900: if (temp_obj2.getPrimaryKey().equals(
0901: obj2.getPrimaryKey())) {
0902: newObject = false;
0903: temp_obj2.addAttachment(obj1);
0904: break;
0905: }
0906: }
0907: if (newObject) {
0908: obj2.initAttachments();
0909: obj2.addAttachment(obj1);
0910: }
0911: results.add(obj1);
0912: }
0913: return results;
0914: }
0915:
0916: /**
0917: * selects a collection of Attachment objects pre-filled with their
0918: * ScarabUserImpl objects.
0919: *
0920: * This method is protected by default in order to keep the public
0921: * api reasonable. You can provide public methods for those you
0922: * actually need in AttachmentPeer.
0923: *
0924: * @throws TorqueException Any exceptions caught during processing will be
0925: * rethrown wrapped into a TorqueException.
0926: */
0927: protected static List doSelectJoinScarabUserImplRelatedByCreatedBy(
0928: Criteria criteria) throws TorqueException {
0929: return doSelectJoinScarabUserImplRelatedByCreatedBy(criteria,
0930: null);
0931: }
0932:
0933: /**
0934: * selects a collection of Attachment objects pre-filled with their
0935: * ScarabUserImpl objects.
0936: *
0937: * This method is protected by default in order to keep the public
0938: * api reasonable. You can provide public methods for those you
0939: * actually need in AttachmentPeer.
0940: *
0941: * @throws TorqueException Any exceptions caught during processing will be
0942: * rethrown wrapped into a TorqueException.
0943: */
0944: protected static List doSelectJoinScarabUserImplRelatedByCreatedBy(
0945: Criteria criteria, Connection conn) throws TorqueException {
0946: setDbName(criteria);
0947:
0948: AttachmentPeer.addSelectColumns(criteria);
0949: int offset = numColumns + 1;
0950: ScarabUserImplPeer.addSelectColumns(criteria);
0951:
0952: criteria.addJoin(AttachmentPeer.CREATED_BY,
0953: ScarabUserImplPeer.USER_ID);
0954:
0955: correctBooleans(criteria);
0956:
0957: List rows;
0958: if (conn == null) {
0959: rows = BasePeer.doSelect(criteria);
0960: } else {
0961: rows = BasePeer.doSelect(criteria, conn);
0962: }
0963:
0964: List results = new ArrayList();
0965:
0966: for (int i = 0; i < rows.size(); i++) {
0967: Record row = (Record) rows.get(i);
0968:
0969: Class omClass = AttachmentPeer.getOMClass();
0970: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
0971: row, 1, omClass);
0972: omClass = ScarabUserImplPeer.getOMClass();
0973: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
0974: .row2Object(row, offset, omClass);
0975:
0976: boolean newObject = true;
0977: for (int j = 0; j < results.size(); j++) {
0978: Attachment temp_obj1 = (Attachment) results.get(j);
0979: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
0980: .getScarabUserRelatedByCreatedBy();
0981: if (temp_obj2.getPrimaryKey().equals(
0982: obj2.getPrimaryKey())) {
0983: newObject = false;
0984: temp_obj2.addAttachmentRelatedByCreatedBy(obj1);
0985: break;
0986: }
0987: }
0988: if (newObject) {
0989: obj2.initAttachmentsRelatedByCreatedBy();
0990: obj2.addAttachmentRelatedByCreatedBy(obj1);
0991: }
0992: results.add(obj1);
0993: }
0994: return results;
0995: }
0996:
0997: /**
0998: * selects a collection of Attachment objects pre-filled with their
0999: * ScarabUserImpl objects.
1000: *
1001: * This method is protected by default in order to keep the public
1002: * api reasonable. You can provide public methods for those you
1003: * actually need in AttachmentPeer.
1004: *
1005: * @throws TorqueException Any exceptions caught during processing will be
1006: * rethrown wrapped into a TorqueException.
1007: */
1008: protected static List doSelectJoinScarabUserImplRelatedByModifiedBy(
1009: Criteria criteria) throws TorqueException {
1010: return doSelectJoinScarabUserImplRelatedByModifiedBy(criteria,
1011: null);
1012: }
1013:
1014: /**
1015: * selects a collection of Attachment objects pre-filled with their
1016: * ScarabUserImpl objects.
1017: *
1018: * This method is protected by default in order to keep the public
1019: * api reasonable. You can provide public methods for those you
1020: * actually need in AttachmentPeer.
1021: *
1022: * @throws TorqueException Any exceptions caught during processing will be
1023: * rethrown wrapped into a TorqueException.
1024: */
1025: protected static List doSelectJoinScarabUserImplRelatedByModifiedBy(
1026: Criteria criteria, Connection conn) throws TorqueException {
1027: setDbName(criteria);
1028:
1029: AttachmentPeer.addSelectColumns(criteria);
1030: int offset = numColumns + 1;
1031: ScarabUserImplPeer.addSelectColumns(criteria);
1032:
1033: criteria.addJoin(AttachmentPeer.MODIFIED_BY,
1034: ScarabUserImplPeer.USER_ID);
1035:
1036: correctBooleans(criteria);
1037:
1038: List rows;
1039: if (conn == null) {
1040: rows = BasePeer.doSelect(criteria);
1041: } else {
1042: rows = BasePeer.doSelect(criteria, conn);
1043: }
1044:
1045: List results = new ArrayList();
1046:
1047: for (int i = 0; i < rows.size(); i++) {
1048: Record row = (Record) rows.get(i);
1049:
1050: Class omClass = AttachmentPeer.getOMClass();
1051: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
1052: row, 1, omClass);
1053: omClass = ScarabUserImplPeer.getOMClass();
1054: ScarabUserImpl obj2 = (ScarabUserImpl) ScarabUserImplPeer
1055: .row2Object(row, offset, omClass);
1056:
1057: boolean newObject = true;
1058: for (int j = 0; j < results.size(); j++) {
1059: Attachment temp_obj1 = (Attachment) results.get(j);
1060: ScarabUserImpl temp_obj2 = (ScarabUserImpl) temp_obj1
1061: .getScarabUserRelatedByModifiedBy();
1062: if (temp_obj2.getPrimaryKey().equals(
1063: obj2.getPrimaryKey())) {
1064: newObject = false;
1065: temp_obj2.addAttachmentRelatedByModifiedBy(obj1);
1066: break;
1067: }
1068: }
1069: if (newObject) {
1070: obj2.initAttachmentsRelatedByModifiedBy();
1071: obj2.addAttachmentRelatedByModifiedBy(obj1);
1072: }
1073: results.add(obj1);
1074: }
1075: return results;
1076: }
1077:
1078: /**
1079: * selects a collection of Attachment objects pre-filled with
1080: * all related objects.
1081: *
1082: * This method is protected by default in order to keep the public
1083: * api reasonable. You can provide public methods for those you
1084: * actually need in AttachmentPeer.
1085: *
1086: * @throws TorqueException Any exceptions caught during processing will be
1087: * rethrown wrapped into a TorqueException.
1088: */
1089: protected static List doSelectJoinAllExceptIssue(Criteria criteria)
1090: throws TorqueException {
1091: return doSelectJoinAllExceptIssue(criteria, null);
1092: }
1093:
1094: /**
1095: * selects a collection of Attachment objects pre-filled with
1096: * all related objects.
1097: *
1098: * This method is protected by default in order to keep the public
1099: * api reasonable. You can provide public methods for those you
1100: * actually need in AttachmentPeer.
1101: *
1102: * @throws TorqueException Any exceptions caught during processing will be
1103: * rethrown wrapped into a TorqueException.
1104: */
1105: protected static List doSelectJoinAllExceptIssue(Criteria criteria,
1106: Connection conn) throws TorqueException {
1107: setDbName(criteria);
1108:
1109: addSelectColumns(criteria);
1110: int offset2 = numColumns + 1;
1111:
1112: AttachmentTypePeer.addSelectColumns(criteria);
1113: criteria.addJoin(AttachmentPeer.ATTACHMENT_TYPE_ID,
1114: AttachmentTypePeer.ATTACHMENT_TYPE_ID);
1115: int offset3 = offset2 + AttachmentTypePeer.numColumns;
1116:
1117: ScarabUserImplPeer.addSelectColumns(criteria);
1118: criteria.addJoin(AttachmentPeer.CREATED_BY,
1119: ScarabUserImplPeer.USER_ID);
1120: int offset4 = offset3 + ScarabUserImplPeer.numColumns;
1121:
1122: ScarabUserImplPeer.addSelectColumns(criteria);
1123: criteria.addJoin(AttachmentPeer.MODIFIED_BY,
1124: ScarabUserImplPeer.USER_ID);
1125:
1126: correctBooleans(criteria);
1127:
1128: List rows;
1129: if (conn == null) {
1130: rows = BasePeer.doSelect(criteria);
1131: } else {
1132: rows = BasePeer.doSelect(criteria, conn);
1133: }
1134:
1135: List results = new ArrayList();
1136:
1137: for (int i = 0; i < rows.size(); i++) {
1138: Record row = (Record) rows.get(i);
1139:
1140: Class omClass = AttachmentPeer.getOMClass();
1141: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
1142: row, 1, omClass);
1143:
1144: omClass = AttachmentTypePeer.getOMClass();
1145: AttachmentType obj2 = (AttachmentType) AttachmentTypePeer
1146: .row2Object(row, offset2, omClass);
1147:
1148: boolean newObject = true;
1149: for (int j = 0; j < results.size(); j++) {
1150: Attachment temp_obj1 = (Attachment) results.get(j);
1151: AttachmentType temp_obj2 = (AttachmentType) temp_obj1
1152: .getAttachmentType();
1153: if (temp_obj2.getPrimaryKey().equals(
1154: obj2.getPrimaryKey())) {
1155: newObject = false;
1156: temp_obj2.addAttachment(obj1);
1157: break;
1158: }
1159: }
1160: if (newObject) {
1161: obj2.initAttachments();
1162: obj2.addAttachment(obj1);
1163: }
1164:
1165: omClass = ScarabUserImplPeer.getOMClass();
1166: ScarabUserImpl obj3 = (ScarabUserImpl) ScarabUserImplPeer
1167: .row2Object(row, offset3, omClass);
1168:
1169: newObject = true;
1170: for (int j = 0; j < results.size(); j++) {
1171: Attachment temp_obj1 = (Attachment) results.get(j);
1172: ScarabUserImpl temp_obj3 = (ScarabUserImpl) temp_obj1
1173: .getScarabUserRelatedByCreatedBy();
1174: if (temp_obj3.getPrimaryKey().equals(
1175: obj3.getPrimaryKey())) {
1176: newObject = false;
1177: temp_obj3.addAttachmentRelatedByCreatedBy(obj1);
1178: break;
1179: }
1180: }
1181: if (newObject) {
1182: obj3.initAttachmentsRelatedByCreatedBy();
1183: obj3.addAttachmentRelatedByCreatedBy(obj1);
1184: }
1185:
1186: omClass = ScarabUserImplPeer.getOMClass();
1187: ScarabUserImpl obj4 = (ScarabUserImpl) ScarabUserImplPeer
1188: .row2Object(row, offset4, omClass);
1189:
1190: newObject = true;
1191: for (int j = 0; j < results.size(); j++) {
1192: Attachment temp_obj1 = (Attachment) results.get(j);
1193: ScarabUserImpl temp_obj4 = (ScarabUserImpl) temp_obj1
1194: .getScarabUserRelatedByModifiedBy();
1195: if (temp_obj4.getPrimaryKey().equals(
1196: obj4.getPrimaryKey())) {
1197: newObject = false;
1198: temp_obj4.addAttachmentRelatedByModifiedBy(obj1);
1199: break;
1200: }
1201: }
1202: if (newObject) {
1203: obj4.initAttachmentsRelatedByModifiedBy();
1204: obj4.addAttachmentRelatedByModifiedBy(obj1);
1205: }
1206: results.add(obj1);
1207: }
1208: return results;
1209: }
1210:
1211: /**
1212: * selects a collection of Attachment objects pre-filled with
1213: * all related objects.
1214: *
1215: * This method is protected by default in order to keep the public
1216: * api reasonable. You can provide public methods for those you
1217: * actually need in AttachmentPeer.
1218: *
1219: * @throws TorqueException Any exceptions caught during processing will be
1220: * rethrown wrapped into a TorqueException.
1221: */
1222: protected static List doSelectJoinAllExceptAttachmentType(
1223: Criteria criteria) throws TorqueException {
1224: return doSelectJoinAllExceptAttachmentType(criteria, null);
1225: }
1226:
1227: /**
1228: * selects a collection of Attachment objects pre-filled with
1229: * all related objects.
1230: *
1231: * This method is protected by default in order to keep the public
1232: * api reasonable. You can provide public methods for those you
1233: * actually need in AttachmentPeer.
1234: *
1235: * @throws TorqueException Any exceptions caught during processing will be
1236: * rethrown wrapped into a TorqueException.
1237: */
1238: protected static List doSelectJoinAllExceptAttachmentType(
1239: Criteria criteria, Connection conn) throws TorqueException {
1240: setDbName(criteria);
1241:
1242: addSelectColumns(criteria);
1243: int offset2 = numColumns + 1;
1244:
1245: IssuePeer.addSelectColumns(criteria);
1246: criteria.addJoin(AttachmentPeer.ISSUE_ID, IssuePeer.ISSUE_ID);
1247: int offset3 = offset2 + IssuePeer.numColumns;
1248:
1249: ScarabUserImplPeer.addSelectColumns(criteria);
1250: criteria.addJoin(AttachmentPeer.CREATED_BY,
1251: ScarabUserImplPeer.USER_ID);
1252: int offset4 = offset3 + ScarabUserImplPeer.numColumns;
1253:
1254: ScarabUserImplPeer.addSelectColumns(criteria);
1255: criteria.addJoin(AttachmentPeer.MODIFIED_BY,
1256: ScarabUserImplPeer.USER_ID);
1257:
1258: correctBooleans(criteria);
1259:
1260: List rows;
1261: if (conn == null) {
1262: rows = BasePeer.doSelect(criteria);
1263: } else {
1264: rows = BasePeer.doSelect(criteria, conn);
1265: }
1266:
1267: List results = new ArrayList();
1268:
1269: for (int i = 0; i < rows.size(); i++) {
1270: Record row = (Record) rows.get(i);
1271:
1272: Class omClass = AttachmentPeer.getOMClass();
1273: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
1274: row, 1, omClass);
1275:
1276: omClass = IssuePeer.getOMClass();
1277: Issue obj2 = (Issue) IssuePeer.row2Object(row, offset2,
1278: omClass);
1279:
1280: boolean newObject = true;
1281: for (int j = 0; j < results.size(); j++) {
1282: Attachment temp_obj1 = (Attachment) results.get(j);
1283: Issue temp_obj2 = (Issue) temp_obj1.getIssue();
1284: if (temp_obj2.getPrimaryKey().equals(
1285: obj2.getPrimaryKey())) {
1286: newObject = false;
1287: temp_obj2.addAttachment(obj1);
1288: break;
1289: }
1290: }
1291: if (newObject) {
1292: obj2.initAttachments();
1293: obj2.addAttachment(obj1);
1294: }
1295:
1296: omClass = ScarabUserImplPeer.getOMClass();
1297: ScarabUserImpl obj3 = (ScarabUserImpl) ScarabUserImplPeer
1298: .row2Object(row, offset3, omClass);
1299:
1300: newObject = true;
1301: for (int j = 0; j < results.size(); j++) {
1302: Attachment temp_obj1 = (Attachment) results.get(j);
1303: ScarabUserImpl temp_obj3 = (ScarabUserImpl) temp_obj1
1304: .getScarabUserRelatedByCreatedBy();
1305: if (temp_obj3.getPrimaryKey().equals(
1306: obj3.getPrimaryKey())) {
1307: newObject = false;
1308: temp_obj3.addAttachmentRelatedByCreatedBy(obj1);
1309: break;
1310: }
1311: }
1312: if (newObject) {
1313: obj3.initAttachmentsRelatedByCreatedBy();
1314: obj3.addAttachmentRelatedByCreatedBy(obj1);
1315: }
1316:
1317: omClass = ScarabUserImplPeer.getOMClass();
1318: ScarabUserImpl obj4 = (ScarabUserImpl) ScarabUserImplPeer
1319: .row2Object(row, offset4, omClass);
1320:
1321: newObject = true;
1322: for (int j = 0; j < results.size(); j++) {
1323: Attachment temp_obj1 = (Attachment) results.get(j);
1324: ScarabUserImpl temp_obj4 = (ScarabUserImpl) temp_obj1
1325: .getScarabUserRelatedByModifiedBy();
1326: if (temp_obj4.getPrimaryKey().equals(
1327: obj4.getPrimaryKey())) {
1328: newObject = false;
1329: temp_obj4.addAttachmentRelatedByModifiedBy(obj1);
1330: break;
1331: }
1332: }
1333: if (newObject) {
1334: obj4.initAttachmentsRelatedByModifiedBy();
1335: obj4.addAttachmentRelatedByModifiedBy(obj1);
1336: }
1337: results.add(obj1);
1338: }
1339: return results;
1340: }
1341:
1342: /**
1343: * selects a collection of Attachment objects pre-filled with
1344: * all related objects.
1345: *
1346: * This method is protected by default in order to keep the public
1347: * api reasonable. You can provide public methods for those you
1348: * actually need in AttachmentPeer.
1349: *
1350: * @throws TorqueException Any exceptions caught during processing will be
1351: * rethrown wrapped into a TorqueException.
1352: */
1353: protected static List doSelectJoinAllExceptScarabUserImplRelatedByCreatedBy(
1354: Criteria criteria) throws TorqueException {
1355: return doSelectJoinAllExceptScarabUserImplRelatedByCreatedBy(
1356: criteria, null);
1357: }
1358:
1359: /**
1360: * selects a collection of Attachment objects pre-filled with
1361: * all related objects.
1362: *
1363: * This method is protected by default in order to keep the public
1364: * api reasonable. You can provide public methods for those you
1365: * actually need in AttachmentPeer.
1366: *
1367: * @throws TorqueException Any exceptions caught during processing will be
1368: * rethrown wrapped into a TorqueException.
1369: */
1370: protected static List doSelectJoinAllExceptScarabUserImplRelatedByCreatedBy(
1371: Criteria criteria, Connection conn) throws TorqueException {
1372: setDbName(criteria);
1373:
1374: addSelectColumns(criteria);
1375: int offset2 = numColumns + 1;
1376:
1377: IssuePeer.addSelectColumns(criteria);
1378: criteria.addJoin(AttachmentPeer.ISSUE_ID, IssuePeer.ISSUE_ID);
1379: int offset3 = offset2 + IssuePeer.numColumns;
1380:
1381: AttachmentTypePeer.addSelectColumns(criteria);
1382: criteria.addJoin(AttachmentPeer.ATTACHMENT_TYPE_ID,
1383: AttachmentTypePeer.ATTACHMENT_TYPE_ID);
1384: int offset4 = offset3 + AttachmentTypePeer.numColumns;
1385:
1386: correctBooleans(criteria);
1387:
1388: List rows;
1389: if (conn == null) {
1390: rows = BasePeer.doSelect(criteria);
1391: } else {
1392: rows = BasePeer.doSelect(criteria, conn);
1393: }
1394:
1395: List results = new ArrayList();
1396:
1397: for (int i = 0; i < rows.size(); i++) {
1398: Record row = (Record) rows.get(i);
1399:
1400: Class omClass = AttachmentPeer.getOMClass();
1401: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
1402: row, 1, omClass);
1403:
1404: omClass = IssuePeer.getOMClass();
1405: Issue obj2 = (Issue) IssuePeer.row2Object(row, offset2,
1406: omClass);
1407:
1408: boolean newObject = true;
1409: for (int j = 0; j < results.size(); j++) {
1410: Attachment temp_obj1 = (Attachment) results.get(j);
1411: Issue temp_obj2 = (Issue) temp_obj1.getIssue();
1412: if (temp_obj2.getPrimaryKey().equals(
1413: obj2.getPrimaryKey())) {
1414: newObject = false;
1415: temp_obj2.addAttachment(obj1);
1416: break;
1417: }
1418: }
1419: if (newObject) {
1420: obj2.initAttachments();
1421: obj2.addAttachment(obj1);
1422: }
1423:
1424: omClass = AttachmentTypePeer.getOMClass();
1425: AttachmentType obj3 = (AttachmentType) AttachmentTypePeer
1426: .row2Object(row, offset3, omClass);
1427:
1428: newObject = true;
1429: for (int j = 0; j < results.size(); j++) {
1430: Attachment temp_obj1 = (Attachment) results.get(j);
1431: AttachmentType temp_obj3 = (AttachmentType) temp_obj1
1432: .getAttachmentType();
1433: if (temp_obj3.getPrimaryKey().equals(
1434: obj3.getPrimaryKey())) {
1435: newObject = false;
1436: temp_obj3.addAttachment(obj1);
1437: break;
1438: }
1439: }
1440: if (newObject) {
1441: obj3.initAttachments();
1442: obj3.addAttachment(obj1);
1443: }
1444:
1445: results.add(obj1);
1446: }
1447: return results;
1448: }
1449:
1450: /**
1451: * selects a collection of Attachment objects pre-filled with
1452: * all related objects.
1453: *
1454: * This method is protected by default in order to keep the public
1455: * api reasonable. You can provide public methods for those you
1456: * actually need in AttachmentPeer.
1457: *
1458: * @throws TorqueException Any exceptions caught during processing will be
1459: * rethrown wrapped into a TorqueException.
1460: */
1461: protected static List doSelectJoinAllExceptScarabUserImplRelatedByModifiedBy(
1462: Criteria criteria) throws TorqueException {
1463: return doSelectJoinAllExceptScarabUserImplRelatedByModifiedBy(
1464: criteria, null);
1465: }
1466:
1467: /**
1468: * selects a collection of Attachment objects pre-filled with
1469: * all related objects.
1470: *
1471: * This method is protected by default in order to keep the public
1472: * api reasonable. You can provide public methods for those you
1473: * actually need in AttachmentPeer.
1474: *
1475: * @throws TorqueException Any exceptions caught during processing will be
1476: * rethrown wrapped into a TorqueException.
1477: */
1478: protected static List doSelectJoinAllExceptScarabUserImplRelatedByModifiedBy(
1479: Criteria criteria, Connection conn) throws TorqueException {
1480: setDbName(criteria);
1481:
1482: addSelectColumns(criteria);
1483: int offset2 = numColumns + 1;
1484:
1485: IssuePeer.addSelectColumns(criteria);
1486: criteria.addJoin(AttachmentPeer.ISSUE_ID, IssuePeer.ISSUE_ID);
1487: int offset3 = offset2 + IssuePeer.numColumns;
1488:
1489: AttachmentTypePeer.addSelectColumns(criteria);
1490: criteria.addJoin(AttachmentPeer.ATTACHMENT_TYPE_ID,
1491: AttachmentTypePeer.ATTACHMENT_TYPE_ID);
1492: int offset4 = offset3 + AttachmentTypePeer.numColumns;
1493:
1494: correctBooleans(criteria);
1495:
1496: List rows;
1497: if (conn == null) {
1498: rows = BasePeer.doSelect(criteria);
1499: } else {
1500: rows = BasePeer.doSelect(criteria, conn);
1501: }
1502:
1503: List results = new ArrayList();
1504:
1505: for (int i = 0; i < rows.size(); i++) {
1506: Record row = (Record) rows.get(i);
1507:
1508: Class omClass = AttachmentPeer.getOMClass();
1509: Attachment obj1 = (Attachment) AttachmentPeer.row2Object(
1510: row, 1, omClass);
1511:
1512: omClass = IssuePeer.getOMClass();
1513: Issue obj2 = (Issue) IssuePeer.row2Object(row, offset2,
1514: omClass);
1515:
1516: boolean newObject = true;
1517: for (int j = 0; j < results.size(); j++) {
1518: Attachment temp_obj1 = (Attachment) results.get(j);
1519: Issue temp_obj2 = (Issue) temp_obj1.getIssue();
1520: if (temp_obj2.getPrimaryKey().equals(
1521: obj2.getPrimaryKey())) {
1522: newObject = false;
1523: temp_obj2.addAttachment(obj1);
1524: break;
1525: }
1526: }
1527: if (newObject) {
1528: obj2.initAttachments();
1529: obj2.addAttachment(obj1);
1530: }
1531:
1532: omClass = AttachmentTypePeer.getOMClass();
1533: AttachmentType obj3 = (AttachmentType) AttachmentTypePeer
1534: .row2Object(row, offset3, omClass);
1535:
1536: newObject = true;
1537: for (int j = 0; j < results.size(); j++) {
1538: Attachment temp_obj1 = (Attachment) results.get(j);
1539: AttachmentType temp_obj3 = (AttachmentType) temp_obj1
1540: .getAttachmentType();
1541: if (temp_obj3.getPrimaryKey().equals(
1542: obj3.getPrimaryKey())) {
1543: newObject = false;
1544: temp_obj3.addAttachment(obj1);
1545: break;
1546: }
1547: }
1548: if (newObject) {
1549: obj3.initAttachments();
1550: obj3.addAttachment(obj1);
1551: }
1552:
1553: results.add(obj1);
1554: }
1555: return results;
1556: }
1557:
1558: /**
1559: * Returns the TableMap related to this peer. This method is not
1560: * needed for general use but a specific application could have a need.
1561: *
1562: * @throws TorqueException Any exceptions caught during processing will be
1563: * rethrown wrapped into a TorqueException.
1564: */
1565: protected static TableMap getTableMap() throws TorqueException {
1566: return Torque.getDatabaseMap(DATABASE_NAME)
1567: .getTable(TABLE_NAME);
1568: }
1569:
1570: private static void setDbName(Criteria crit) {
1571: // Set the correct dbName if it has not been overridden
1572: // crit.getDbName will return the same object if not set to
1573: // another value so == check is okay and faster
1574: if (crit.getDbName() == Torque.getDefaultDB()) {
1575: crit.setDbName(DATABASE_NAME);
1576: }
1577: }
1578: }
|