    001    package org.apache.turbine.services.schedule;
    002
    003    import java.math.BigDecimal;
    004    import java.sql.Connection;
    005    import java.sql.SQLException;
    006    import java.util.ArrayList;
    007    import java.util.Date;
    008    import java.util.Iterator;
    009    import java.util.LinkedList;
    010    import java.util.List;
    011
    012    import org.apache.torque.NoRowsException;
    013    import org.apache.torque.TooManyRowsException;
    014    import org.apache.torque.Torque;
    015    import org.apache.torque.TorqueException;
    016    import org.apache.torque.TorqueRuntimeException;
    017    import org.apache.torque.map.MapBuilder;
    018    import org.apache.torque.map.TableMap;
    019    import org.apache.torque.om.DateKey;
    020    import org.apache.torque.om.NumberKey;
    021    import org.apache.torque.om.StringKey;
    022    import org.apache.torque.om.ObjectKey;
    023    import org.apache.torque.om.SimpleKey;
    024    import org.apache.torque.util.BasePeer;
    025    import org.apache.torque.util.Criteria;
    026
    027    import com.workingdogs.village.DataSetException;
    028    import com.workingdogs.village.QueryDataSet;
    029    import com.workingdogs.village.Record;
    030
    031    // Local classes
    032    import org.apache.turbine.services.schedule.map.*;
    033
    034
    035
    036
    037    /**
    038     * This class was autogenerated by Torque on:
    039     *
    040     * [Thu Jun 23 17:25:46 CEST 2011]
    041     *
    042     */
    043    public abstract class BaseJobEntryPeer
    044        extends BasePeer
    045    {
    046        /** Serial version */
    047        private static final long serialVersionUID = 1308842746584L;
    048
    049
    050        /** the default database name for this class */
    051        public static final String DATABASE_NAME;
    052
    053         /** the table name for this class */
    054        public static final String TABLE_NAME;
    055
    056        /**
    057         * @return the map builder for this peer
    058         * @throws TorqueException Any exceptions caught during processing will be
    059         *         rethrown wrapped into a TorqueException.
    060         * @deprecated Torque.getMapBuilder(JobEntryMapBuilder.CLASS_NAME) instead
    061         */
    062        public static MapBuilder getMapBuilder()
    063            throws TorqueException
    064        {
    065            return Torque.getMapBuilder(JobEntryMapBuilder.CLASS_NAME);
    066        }
    067
    068        /** the column name for the JOB_ID field */
    069        public static final String JOB_ID;
    070        /** the column name for the SECOND field */
    071        public static final String SECOND;
    072        /** the column name for the MINUTE field */
    073        public static final String MINUTE;
    074        /** the column name for the HOUR field */
    075        public static final String HOUR;
    076        /** the column name for the WEEK_DAY field */
    077        public static final String WEEK_DAY;
    078        /** the column name for the DAY_OF_MONTH field */
    079        public static final String DAY_OF_MONTH;
    080        /** the column name for the TASK field */
    081        public static final String TASK;
    082        /** the column name for the EMAIL field */
    083        public static final String EMAIL;
    084        /** the column name for the PROPERTY field */
    085        public static final String PROPERTY;
    086
    087        static
    088        {
    089            DATABASE_NAME = "default";
    090            TABLE_NAME = "TURBINE_SCHEDULED_JOB";
    091
    092            JOB_ID = "TURBINE_SCHEDULED_JOB.JOB_ID";
    093            SECOND = "TURBINE_SCHEDULED_JOB.SECOND";
    094            MINUTE = "TURBINE_SCHEDULED_JOB.MINUTE";
    095            HOUR = "TURBINE_SCHEDULED_JOB.HOUR";
    096            WEEK_DAY = "TURBINE_SCHEDULED_JOB.WEEK_DAY";
    097            DAY_OF_MONTH = "TURBINE_SCHEDULED_JOB.DAY_OF_MONTH";
    098            TASK = "TURBINE_SCHEDULED_JOB.TASK";
    099            EMAIL = "TURBINE_SCHEDULED_JOB.EMAIL";
    100            PROPERTY = "TURBINE_SCHEDULED_JOB.PROPERTY";
    101            if (Torque.isInit())
    102            {
    103                try
    104                {
    105                    Torque.getMapBuilder(JobEntryMapBuilder.CLASS_NAME);
    106                }
    107                catch (TorqueException e)
    108                {
    109                    log.error("Could not initialize Peer", e);
    110                    throw new TorqueRuntimeException(e);
    111                }
    112            }
    113            else
    114            {
    115                Torque.registerMapBuilder(JobEntryMapBuilder.CLASS_NAME);
    116            }
    117        }
    118
    119        /** number of columns for this peer */
    120        public static final int numColumns =  9;
    121
    122        /** A class that can be returned by this peer. */
    123        protected static final String CLASSNAME_DEFAULT =
    124            "org.apache.turbine.services.schedule.JobEntry";
    125
    126        /** A class that can be returned by this peer. */
    127        protected static final Class CLASS_DEFAULT = initClass(CLASSNAME_DEFAULT);
    128
    129        /**
    130         * Class object initialization method.
    131         *
    132         * @param className name of the class to initialize
    133         * @return the initialized class
    134         */
    135        private static Class initClass(String className)
    136        {
    137            Class c = null;
    138            try
    139            {
    140                c = Class.forName(className);
    141            }
    142            catch (Throwable t)
    143            {
    144                log.error("A FATAL ERROR has occurred which should not "
    145                    + "have happened under any circumstance.  Please notify "
    146                    + "the Torque developers <torque-dev@db.apache.org> "
    147                    + "and give as many details as possible (including the error "
    148                    + "stack trace).", t);
    149
    150                // Error objects should always be propagated.
    151                if (t instanceof Error)
    152                {
    153                    throw (Error) t.fillInStackTrace();
    154                }
    155            }
    156            return c;
    157        }
    158
    159        /**
    160         * Get the list of objects for a ResultSet.  Please not that your
    161         * resultset MUST return columns in the right order.  You can use
    162         * getFieldNames() in BaseObject to get the correct sequence.
    163         *
    164         * @param results the ResultSet
    165         * @return the list of objects
    166         * @throws TorqueException Any exceptions caught during processing will be
    167         *         rethrown wrapped into a TorqueException.
    168         */
    169        public static List<JobEntry> resultSet2Objects(java.sql.ResultSet results)
    170                throws TorqueException
    171        {
    172            try
    173            {
    174                QueryDataSet qds = null;
    175                List<Record> rows = null;
    176                try
    177                {
    178                    qds = new QueryDataSet(results);
    179                    rows = getSelectResults(qds);
    180                }
    181                finally
    182                {
    183                    if (qds != null)
    184                    {
    185                        qds.close();
    186                    }
    187                }
    188
    189                return populateObjects(rows);
    190            }
    191            catch (SQLException e)
    192            {
    193                throw new TorqueException(e);
    194            }
    195            catch (DataSetException e)
    196            {
    197                throw new TorqueException(e);
    198            }
    199        }
    200
    201
    202
    203        /**
    204         * Method to do inserts.
    205         *
    206         * @param criteria object used to create the INSERT statement.
    207         * @throws TorqueException Any exceptions caught during processing will be
    208         *         rethrown wrapped into a TorqueException.
    209         */
    210        public static ObjectKey doInsert(Criteria criteria)
    211            throws TorqueException
    212        {
    213            return BaseJobEntryPeer
    214                .doInsert(criteria, (Connection) null);
    215        }
    216
    217        /**
    218         * Method to do inserts.  This method is to be used during a transaction,
    219         * otherwise use the doInsert(Criteria) method.  It will take care of
    220         * the connection details internally.
    221         *
    222         * @param criteria object used to create the INSERT statement.
    223         * @param con the connection to use
    224         * @throws TorqueException Any exceptions caught during processing will be
    225         *         rethrown wrapped into a TorqueException.
    226         */
    227        public static ObjectKey doInsert(Criteria criteria, Connection con)
    228            throws TorqueException
    229        {
    230            correctBooleans(criteria);
    231
    232            setDbName(criteria);
    233
    234            if (con == null)
    235            {
    236                return BasePeer.doInsert(criteria);
    237            }
    238            else
    239            {
    240                return BasePeer.doInsert(criteria, con);
    241            }
    242        }
    243
    244        /**
    245         * Add all the columns needed to create a new object.
    246         *
    247         * @param criteria object containing the columns to add.
    248         * @throws TorqueException Any exceptions caught during processing will be
    249         *         rethrown wrapped into a TorqueException.
    250         */
    251        public static void addSelectColumns(Criteria criteria)
    252                throws TorqueException
    253        {
    254            criteria.addSelectColumn(JOB_ID);
    255            criteria.addSelectColumn(SECOND);
    256            criteria.addSelectColumn(MINUTE);
    257            criteria.addSelectColumn(HOUR);
    258            criteria.addSelectColumn(WEEK_DAY);
    259            criteria.addSelectColumn(DAY_OF_MONTH);
    260            criteria.addSelectColumn(TASK);
    261            criteria.addSelectColumn(EMAIL);
    262            criteria.addSelectColumn(PROPERTY);
    263        }
    264
    265        /**
    266         * changes the boolean values in the criteria to the appropriate type,
    267         * whenever a booleanchar or booleanint column is involved.
    268         * This enables the user to create criteria using Boolean values
    269         * for booleanchar or booleanint columns
    270         * @param criteria the criteria in which the boolean values should be corrected
    271         * @throws TorqueException if the database map for the criteria cannot be
    272                   obtained.
    273         */
    274        public static void correctBooleans(Criteria criteria) throws TorqueException
    275        {
    276            correctBooleans(criteria, getTableMap());
    277        }
    278
    279        /**
    280         * Create a new object of type cls from a resultset row starting
    281         * from a specified offset.  This is done so that you can select
    282         * other rows than just those needed for this object.  You may
    283         * for example want to create two objects from the same row.
    284         *
    285         * @throws TorqueException Any exceptions caught during processing will be
    286         *         rethrown wrapped into a TorqueException.
    287         */
    288        public static JobEntry row2Object(Record row,
    289                                                 int offset,
    290                                                 Class cls)
    291            throws TorqueException
    292        {
    293            try
    294            {
    295                JobEntry obj = (JobEntry) cls.newInstance();
    296                JobEntryPeer.populateObject(row, offset, obj);
    297                    obj.setModified(false);
    298                obj.setNew(false);
    299
    300                return obj;
    301            }
    302            catch (InstantiationException e)
    303            {
    304                throw new TorqueException(e);
    305            }
    306            catch (IllegalAccessException e)
    307            {
    308                throw new TorqueException(e);
    309            }
    310        }
    311
    312        /**
    313         * Populates an object from a resultset row starting
    314         * from a specified offset.  This is done so that you can select
    315         * other rows than just those needed for this object.  You may
    316         * for example want to create two objects from the same row.
    317         *
    318         * @throws TorqueException Any exceptions caught during processing will be
    319         *         rethrown wrapped into a TorqueException.
    320         */
    321        public static void populateObject(Record row,
    322                                          int offset,
    323                                          JobEntry obj)
    324            throws TorqueException
    325        {
    326            try
    327            {
    328                obj.setJobId(row.getValue(offset + 0).asInt());
    329                obj.setSecond(row.getValue(offset + 1).asInt());
    330                obj.setMinute(row.getValue(offset + 2).asInt());
    331                obj.setHour(row.getValue(offset + 3).asInt());
    332                obj.setWeekDay(row.getValue(offset + 4).asInt());
    333                obj.setDayOfMonth(row.getValue(offset + 5).asInt());
    334                obj.setTask(row.getValue(offset + 6).asString());
    335                obj.setEmail(row.getValue(offset + 7).asString());
    336                obj.setProperty(row.getValue(offset + 8).asBytes());
    337            }
    338            catch (DataSetException e)
    339            {
    340                throw new TorqueException(e);
    341            }
    342        }
    343
    344        /**
    345         * Method to do selects.
    346         *
    347         * @param criteria object used to create the SELECT statement.
    348         * @return List of selected Objects
    349         * @throws TorqueException Any exceptions caught during processing will be
    350         *         rethrown wrapped into a TorqueException.
    351         */
    352        public static List<JobEntry> doSelect(Criteria criteria) throws TorqueException
    353        {
    354            return populateObjects(doSelectVillageRecords(criteria));
    355        }
    356
    357        /**
    358         * Method to do selects within a transaction.
    359         *
    360         * @param criteria object used to create the SELECT statement.
    361         * @param con the connection to use
    362         * @return List of selected Objects
    363         * @throws TorqueException Any exceptions caught during processing will be
    364         *         rethrown wrapped into a TorqueException.
    365         */
    366        public static List<JobEntry> doSelect(Criteria criteria, Connection con)
    367            throws TorqueException
    368        {
    369            return populateObjects(doSelectVillageRecords(criteria, con));
    370        }
    371
    372        /**
    373         * Grabs the raw Village records to be formed into objects.
    374         * This method handles connections internally.  The Record objects
    375         * returned by this method should be considered readonly.  Do not
    376         * alter the data and call save(), your results may vary, but are
    377         * certainly likely to result in hard to track MT bugs.
    378         *
    379         * @throws TorqueException Any exceptions caught during processing will be
    380         *         rethrown wrapped into a TorqueException.
    381         */
    382        public static List<Record> doSelectVillageRecords(Criteria criteria)
    383            throws TorqueException
    384        {
    385            return BaseJobEntryPeer
    386                .doSelectVillageRecords(criteria, (Connection) null);
    387        }
    388
    389        /**
    390         * Grabs the raw Village records to be formed into objects.
    391         * This method should be used for transactions
    392         *
    393         * @param criteria object used to create the SELECT statement.
    394         * @param con the connection to use
    395         * @throws TorqueException Any exceptions caught during processing will be
    396         *         rethrown wrapped into a TorqueException.
    397         */
    398        public static List<Record> doSelectVillageRecords(Criteria criteria, Connection con)
    399            throws TorqueException
    400        {
    401            if (criteria.getSelectColumns().size() == 0)
    402            {
    403                addSelectColumns(criteria);
    404            }
    405            correctBooleans(criteria);
    406
    407            setDbName(criteria);
    408
    409            // BasePeer returns a List of Value (Village) arrays.  The array
    410            // order follows the order columns were placed in the Select clause.
    411            if (con == null)
    412            {
    413                return BasePeer.doSelect(criteria);
    414            }
    415            else
    416            {
    417                return BasePeer.doSelect(criteria, con);
    418            }
    419        }
    420
    421        /**
    422         * The returned List will contain objects of the default type or
    423         * objects that inherit from the default.
    424         *
    425         * @throws TorqueException Any exceptions caught during processing will be
    426         *         rethrown wrapped into a TorqueException.
    427         */
    428        public static List<JobEntry> populateObjects(List<Record> records)
    429            throws TorqueException
    430        {
    431            List<JobEntry> results = new ArrayList<JobEntry>(records.size());
    432
    433            // populate the object(s)
    434            for (int i = 0; i < records.size(); i++)
    435            {
    436                Record row =  records.get(i);
    437                results.add(JobEntryPeer.row2Object(row, 1,
    438                    JobEntryPeer.getOMClass()));
    439            }
    440            return results;
    441        }
    442
    443
    444        /**
    445         * The class that the Peer will make instances of.
    446         * If the BO is abstract then you must implement this method
    447         * in the BO.
    448         *
    449         * @throws TorqueException Any exceptions caught during processing will be
    450         *         rethrown wrapped into a TorqueException.
    451         */
    452        public static Class getOMClass()
    453            throws TorqueException
    454        {
    455            return CLASS_DEFAULT;
    456        }
    457
    458        /**
    459         * Method to do updates.
    460         *
    461         * @param criteria object containing data that is used to create the UPDATE
    462         *        statement.
    463         * @throws TorqueException Any exceptions caught during processing will be
    464         *         rethrown wrapped into a TorqueException.
    465         */
    466        public static void doUpdate(Criteria criteria) throws TorqueException
    467        {
    468             BaseJobEntryPeer
    469                .doUpdate(criteria, (Connection) null);
    470        }
    471
    472        /**
    473         * Method to do updates.  This method is to be used during a transaction,
    474         * otherwise use the doUpdate(Criteria) method.  It will take care of
    475         * the connection details internally.
    476         *
    477         * @param criteria object containing data that is used to create the UPDATE
    478         *        statement.
    479         * @param con the connection to use
    480         * @throws TorqueException Any exceptions caught during processing will be
    481         *         rethrown wrapped into a TorqueException.
    482         */
    483        public static void doUpdate(Criteria criteria, Connection con)
    484            throws TorqueException
    485        {
    486            Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
    487            correctBooleans(criteria);
    488
    489
    490             selectCriteria.put(JOB_ID, criteria.remove(JOB_ID));
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500            setDbName(criteria);
    501
    502            if (con == null)
    503            {
    504                BasePeer.doUpdate(selectCriteria, criteria);
    505            }
    506            else
    507            {
    508                BasePeer.doUpdate(selectCriteria, criteria, con);
    509            }
    510        }
    511
    512        /**
    513         * Method to do deletes.
    514         *
    515         * @param criteria object containing data that is used DELETE from database.
    516         * @throws TorqueException Any exceptions caught during processing will be
    517         *         rethrown wrapped into a TorqueException.
    518         */
    519         public static void doDelete(Criteria criteria) throws TorqueException
    520         {
    521             JobEntryPeer
    522                .doDelete(criteria, (Connection) null);
    523         }
    524
    525        /**
    526         * Method to do deletes.  This method is to be used during a transaction,
    527         * otherwise use the doDelete(Criteria) method.  It will take care of
    528         * the connection details internally.
    529         *
    530         * @param criteria object containing data that is used DELETE from database.
    531         * @param con the connection to use
    532         * @throws TorqueException Any exceptions caught during processing will be
    533         *         rethrown wrapped into a TorqueException.
    534         */
    535         public static void doDelete(Criteria criteria, Connection con)
    536            throws TorqueException
    537         {
    538            correctBooleans(criteria);
    539
    540            setDbName(criteria);
    541
    542            if (con == null)
    543            {
    544                BasePeer.doDelete(criteria, TABLE_NAME);
    545            }
    546            else
    547            {
    548                BasePeer.doDelete(criteria, TABLE_NAME, con);
    549            }
    550         }
    551
    552        /**
    553         * Method to do selects
    554         *
    555         * @throws TorqueException Any exceptions caught during processing will be
    556         *         rethrown wrapped into a TorqueException.
    557         */
    558        public static List<JobEntry> doSelect(JobEntry obj) throws TorqueException
    559        {
    560            return doSelect(buildSelectCriteria(obj));
    561        }
    562
    563        /**
    564         * Method to do inserts
    565         *
    566         * @throws TorqueException Any exceptions caught during processing will be
    567         *         rethrown wrapped into a TorqueException.
    568         */
    569        public static void doInsert(JobEntry obj) throws TorqueException
    570        {
    571            obj.setPrimaryKey(doInsert(buildCriteria(obj)));
    572            obj.setNew(false);
    573            obj.setModified(false);
    574        }
    575
    576        /**
    577         * @param obj the data object to update in the database.
    578         * @throws TorqueException Any exceptions caught during processing will be
    579         *         rethrown wrapped into a TorqueException.
    580         */
    581        public static void doUpdate(JobEntry obj) throws TorqueException
    582        {
    583            doUpdate(buildCriteria(obj));
    584            obj.setModified(false);
    585        }
    586
    587        /**
    588         * @param obj the data object to delete in the database.
    589         * @throws TorqueException Any exceptions caught during processing will be
    590         *         rethrown wrapped into a TorqueException.
    591         */
    592        public static void doDelete(JobEntry obj) throws TorqueException
    593        {
    594            doDelete(buildSelectCriteria(obj));
    595        }
    596
    597        /**
    598         * Method to do inserts.  This method is to be used during a transaction,
    599         * otherwise use the doInsert(JobEntry) method.  It will take
    600         * care of the connection details internally.
    601         *
    602         * @param obj the data object to insert into the database.
    603         * @param con the connection to use
    604         * @throws TorqueException Any exceptions caught during processing will be
    605         *         rethrown wrapped into a TorqueException.
    606         */
    607        public static void doInsert(JobEntry obj, Connection con)
    608            throws TorqueException
    609        {
    610            obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
    611            obj.setNew(false);
    612            obj.setModified(false);
    613        }
    614
    615        /**
    616         * Method to do update.  This method is to be used during a transaction,
    617         * otherwise use the doUpdate(JobEntry) method.  It will take
    618         * care of the connection details internally.
    619         *
    620         * @param obj the data object to update in the database.
    621         * @param con the connection to use
    622         * @throws TorqueException Any exceptions caught during processing will be
    623         *         rethrown wrapped into a TorqueException.
    624         */
    625        public static void doUpdate(JobEntry obj, Connection con)
    626            throws TorqueException
    627        {
    628            doUpdate(buildCriteria(obj), con);
    629            obj.setModified(false);
    630        }
    631
    632        /**
    633         * Method to delete.  This method is to be used during a transaction,
    634         * otherwise use the doDelete(JobEntry) method.  It will take
    635         * care of the connection details internally.
    636         *
    637         * @param obj the data object to delete in the database.
    638         * @param con the connection to use
    639         * @throws TorqueException Any exceptions caught during processing will be
    640         *         rethrown wrapped into a TorqueException.
    641         */
    642        public static void doDelete(JobEntry obj, Connection con)
    643            throws TorqueException
    644        {
    645            doDelete(buildSelectCriteria(obj), con);
    646        }
    647
    648        /**
    649         * Method to do deletes.
    650         *
    651         * @param pk ObjectKey that is used DELETE from database.
    652         * @throws TorqueException Any exceptions caught during processing will be
    653         *         rethrown wrapped into a TorqueException.
    654         */
    655        public static void doDelete(ObjectKey pk) throws TorqueException
    656        {
    657            BaseJobEntryPeer
    658               .doDelete(pk, (Connection) null);
    659        }
    660
    661        /**
    662         * Method to delete.  This method is to be used during a transaction,
    663         * otherwise use the doDelete(ObjectKey) method.  It will take
    664         * care of the connection details internally.
    665         *
    666         * @param pk the primary key for the object to delete in the database.
    667         * @param con the connection to use
    668         * @throws TorqueException Any exceptions caught during processing will be
    669         *         rethrown wrapped into a TorqueException.
    670         */
    671        public static void doDelete(ObjectKey pk, Connection con)
    672            throws TorqueException
    673        {
    674            doDelete(buildCriteria(pk), con);
    675        }
    676
    677        /** Build a Criteria object from an ObjectKey */
    678        public static Criteria buildCriteria( ObjectKey pk )
    679        {
    680            Criteria criteria = new Criteria();
    681                criteria.add(JOB_ID, pk);
    682            return criteria;
    683         }
    684
    685        /** Build a Criteria object from the data object for this peer */
    686        public static Criteria buildCriteria( JobEntry obj )
    687        {
    688            Criteria criteria = new Criteria(DATABASE_NAME);
    689            if (!obj.isNew())
    690            criteria.add(JOB_ID, obj.getJobId());
    691            criteria.add(SECOND, obj.getSecond());
    692            criteria.add(MINUTE, obj.getMinute());
    693            criteria.add(HOUR, obj.getHour());
    694            criteria.add(WEEK_DAY, obj.getWeekDay());
    695            criteria.add(DAY_OF_MONTH, obj.getDayOfMonth());
    696            criteria.add(TASK, obj.getTask());
    697            criteria.add(EMAIL, obj.getEmail());
    698            criteria.add(PROPERTY, obj.getProperty());
    699            return criteria;
    700        }
    701
    702        /** Build a Criteria object from the data object for this peer, skipping all binary columns */
    703        public static Criteria buildSelectCriteria( JobEntry obj )
    704        {
    705            Criteria criteria = new Criteria(DATABASE_NAME);
    706            if (!obj.isNew())
    707            {
    708                criteria.add(JOB_ID, obj.getJobId());
    709            }
    710                criteria.add(SECOND, obj.getSecond());
    711                criteria.add(MINUTE, obj.getMinute());
    712                criteria.add(HOUR, obj.getHour());
    713                criteria.add(WEEK_DAY, obj.getWeekDay());
    714                criteria.add(DAY_OF_MONTH, obj.getDayOfMonth());
    715                criteria.add(TASK, obj.getTask());
    716                criteria.add(EMAIL, obj.getEmail());
    717            return criteria;
    718        }
    719
    720
    721        /**
    722         * Retrieve a single object by pk
    723         *
    724         * @param pk the primary key
    725         * @throws TorqueException Any exceptions caught during processing will be
    726         *         rethrown wrapped into a TorqueException.
    727         * @throws NoRowsException Primary key was not found in database.
    728         * @throws TooManyRowsException Primary key was not found in database.
    729         */
    730        public static JobEntry retrieveByPK(int pk)
    731            throws TorqueException, NoRowsException, TooManyRowsException
    732        {
    733            return retrieveByPK(SimpleKey.keyFor(pk));
    734        }
    735
    736        /**
    737         * Retrieve a single object by pk
    738         *
    739         * @param pk the primary key
    740         * @param con the connection to use
    741         * @throws TorqueException Any exceptions caught during processing will be
    742         *         rethrown wrapped into a TorqueException.
    743         * @throws NoRowsException Primary key was not found in database.
    744         * @throws TooManyRowsException Primary key was not found in database.
    745         */
    746        public static JobEntry retrieveByPK(int pk, Connection con)
    747            throws TorqueException, NoRowsException, TooManyRowsException
    748        {
    749            return retrieveByPK(SimpleKey.keyFor(pk), con);
    750        }
    751
    752        /**
    753         * Retrieve a single object by pk
    754         *
    755         * @param pk the primary key
    756         * @throws TorqueException Any exceptions caught during processing will be
    757         *         rethrown wrapped into a TorqueException.
    758         * @throws NoRowsException Primary key was not found in database.
    759         * @throws TooManyRowsException Primary key was not found in database.
    760         */
    761        public static JobEntry retrieveByPK(ObjectKey pk)
    762            throws TorqueException, NoRowsException, TooManyRowsException
    763        {
    764            Connection db = null;
    765            JobEntry retVal = null;
    766            try
    767            {
    768                db = Torque.getConnection(DATABASE_NAME);
    769                retVal = retrieveByPK(pk, db);
    770            }
    771            finally
    772            {
    773                Torque.closeConnection(db);
    774            }
    775            return retVal;
    776        }
    777
    778        /**
    779         * Retrieve a single object by pk
    780         *
    781         * @param pk the primary key
    782         * @param con the connection to use
    783         * @throws TorqueException Any exceptions caught during processing will be
    784         *         rethrown wrapped into a TorqueException.
    785         * @throws NoRowsException Primary key was not found in database.
    786         * @throws TooManyRowsException Primary key was not found in database.
    787         */
    788        public static JobEntry retrieveByPK(ObjectKey pk, Connection con)
    789            throws TorqueException, NoRowsException, TooManyRowsException
    790        {
    791            Criteria criteria = buildCriteria(pk);
    792            List<JobEntry> v = doSelect(criteria, con);
    793            if (v.size() == 0)
    794            {
    795                throw new NoRowsException("Failed to select a row.");
    796            }
    797            else if (v.size() > 1)
    798            {
    799                throw new TooManyRowsException("Failed to select only one row.");
    800            }
    801            else
    802            {
    803                return (JobEntry)v.get(0);
    804            }
    805        }
    806
    807        /**
    808         * Retrieve a multiple objects by pk
    809         *
    810         * @param pks List of primary keys
    811         * @throws TorqueException Any exceptions caught during processing will be
    812         *         rethrown wrapped into a TorqueException.
    813         */
    814        public static List<JobEntry> retrieveByPKs(List<ObjectKey> pks)
    815            throws TorqueException
    816        {
    817            Connection db = null;
    818            List<JobEntry> retVal = null;
    819            try
    820            {
    821               db = Torque.getConnection(DATABASE_NAME);
    822               retVal = retrieveByPKs(pks, db);
    823            }
    824            finally
    825            {
    826                Torque.closeConnection(db);
    827            }
    828            return retVal;
    829        }
    830
    831        /**
    832         * Retrieve a multiple objects by pk
    833         *
    834         * @param pks List of primary keys
    835         * @param dbcon the connection to use
    836         * @throws TorqueException Any exceptions caught during processing will be
    837         *         rethrown wrapped into a TorqueException.
    838         */
    839        public static List<JobEntry> retrieveByPKs( List<ObjectKey> pks, Connection dbcon )
    840            throws TorqueException
    841        {
    842            List<JobEntry> objs = null;
    843            if (pks == null || pks.size() == 0)
    844            {
    845                objs = new LinkedList<JobEntry>();
    846            }
    847            else
    848            {
    849                Criteria criteria = new Criteria();
    850                criteria.addIn( JOB_ID, pks );
    851            objs = doSelect(criteria, dbcon);
    852            }
    853            return objs;
    854        }
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865        /**
    866         * Returns the TableMap related to this peer.
    867         *
    868         * @throws TorqueException Any exceptions caught during processing will be
    869         *         rethrown wrapped into a TorqueException.
    870         */
    871        public static TableMap getTableMap()
    872            throws TorqueException
    873        {
    874            return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
    875        }
    876
    877        private static void setDbName(Criteria crit)
    878        {
    879            // Set the correct dbName if it has not been overridden
    880            // crit.getDbName will return the same object if not set to
    881            // another value so == check is okay and faster
    882            if (crit.getDbName() == Torque.getDefaultDB())
    883            {
    884                crit.setDbName(DATABASE_NAME);
    885            }
    886        }
    887
    888
    889        // The following methods wrap some methods in BasePeer
    890        // to have more support for Java5 generic types in the Peer
    891
    892        /**
    893         * Utility method which executes a given sql statement.  This
    894         * method should be used for select statements only.  Use
    895         * executeStatement for update, insert, and delete operations.
    896         *
    897         * @param queryString A String with the sql statement to execute.
    898         * @return List of Record objects.
    899         * @throws TorqueException Any exceptions caught during processing will be
    900         *         rethrown wrapped into a TorqueException.
    901         * @see org.apache.torque.util.BasePeer#executeQuery(String)
    902         */
    903        public static List<Record> executeQuery(String queryString) throws TorqueException
    904        {
    905            return BasePeer.executeQuery(queryString);
    906        }
    907
    908        /**
    909         * Utility method which executes a given sql statement.  This
    910         * method should be used for select statements only.  Use
    911         * executeStatement for update, insert, and delete operations.
    912         *
    913         * @param queryString A String with the sql statement to execute.
    914         * @param dbName The database to connect to.
    915         * @return List of Record objects.
    916         * @throws TorqueException Any exceptions caught during processing will be
    917         *         rethrown wrapped into a TorqueException.
    918         * @see org.apache.torque.util.BasePeer#executeQuery(String,String)
    919         */
    920        public static List<Record> executeQuery(String queryString, String dbName)
    921            throws TorqueException
    922        {
    923            return BasePeer.executeQuery(queryString,dbName);
    924        }
    925
    926
    927        /**
    928         * Method for performing a SELECT.  Returns all results.
    929         *
    930         * @param queryString A String with the sql statement to execute.
    931         * @param dbName The database to connect to.
    932         * @param singleRecord Whether or not we want to select only a
    933         * single record.
    934         * @return List of Record objects.
    935         * @throws TorqueException Any exceptions caught during processing will be
    936         *         rethrown wrapped into a TorqueException.
    937         * @see org.apache.torque.util.BasePeer#executeQuery(String,String,boolean)
    938         */
    939        public static List<Record> executeQuery(
    940            String queryString,
    941            String dbName,
    942            boolean singleRecord)
    943            throws TorqueException
    944        {
    945            return BasePeer.executeQuery(queryString,dbName,singleRecord);
    946        }
    947
    948        /**
    949         * Method for performing a SELECT.  Returns all results.
    950         *
    951         * @param queryString A String with the sql statement to execute.
    952         * @param singleRecord Whether or not we want to select only a
    953         * single record.
    954         * @param con A Connection.
    955         * @return List of Record objects.
    956         * @throws TorqueException Any exceptions caught during processing will be
    957         *         rethrown wrapped into a TorqueException.
    958         * @see org.apache.torque.util.BasePeer#executeQuery(String,boolean,Connection)
    959         */
    960        public static List<Record> executeQuery(
    961            String queryString,
    962            boolean singleRecord,
    963            Connection con)
    964            throws TorqueException
    965        {
    966            return BasePeer.executeQuery(queryString,singleRecord,con);
    967        }
    968
    969        /**
    970         * Method for performing a SELECT.
    971         *
    972         * @param queryString A String with the sql statement to execute.
    973         * @param start The first row to return.
    974         * @param numberOfResults The number of rows to return.
    975         * @param dbName The database to connect to.
    976         * @param singleRecord Whether or not we want to select only a
    977         * single record.
    978         * @return List of Record objects.
    979         * @throws TorqueException Any exceptions caught during processing will be
    980         *         rethrown wrapped into a TorqueException.
    981         * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean)
    982         */
    983        public static List<Record> executeQuery(
    984            String queryString,
    985            int start,
    986            int numberOfResults,
    987            String dbName,
    988            boolean singleRecord)
    989            throws TorqueException
    990        {
    991            return BasePeer.executeQuery(queryString,start,numberOfResults,dbName,singleRecord);
    992        }
    993
    994        /**
    995         * Method for performing a SELECT.  Returns all results.
    996         *
    997         * @param queryString A String with the sql statement to execute.
    998         * @param start The first row to return.
    999         * @param numberOfResults The number of rows to return.
    1000         * @param singleRecord Whether or not we want to select only a
    1001         * single record.
    1002         * @param con A Connection.
    1003         * @return List of Record objects.
    1004         * @throws TorqueException Any exceptions caught during processing will be
    1005         *         rethrown wrapped into a TorqueException.
    1006         * @see org.apache.torque.util.BasePeer#executeQuery(String,int,int,String,boolean,Connection)
    1007         */
    1008        public static List<Record> executeQuery(
    1009            String queryString,
    1010            int start,
    1011            int numberOfResults,
    1012            boolean singleRecord,
    1013            Connection con)
    1014            throws TorqueException
    1015        {
    1016            return BasePeer.executeQuery(queryString,start,numberOfResults,singleRecord,con);
    1017        }
    1018
    1019        /**
    1020         * Returns all records in a QueryDataSet as a List of Record
    1021         * objects.  Used for functionality like util.LargeSelect.
    1022         *
    1023         * @see #getSelectResults(QueryDataSet, int, int, boolean)
    1024         * @param qds the QueryDataSet
    1025         * @return a List of Record objects
    1026         * @throws TorqueException Any exceptions caught during processing will be
    1027         *         rethrown wrapped into a TorqueException.
    1028         * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet)
    1029         */
    1030        public static List<Record> getSelectResults(QueryDataSet qds)
    1031            throws TorqueException
    1032        {
    1033            return BasePeer.getSelectResults(qds);
    1034        }
    1035
    1036        /**
    1037         * Returns all records in a QueryDataSet as a List of Record
    1038         * objects.  Used for functionality like util.LargeSelect.
    1039         *
    1040         * @see #getSelectResults(QueryDataSet, int, int, boolean)
    1041         * @param qds the QueryDataSet
    1042         * @param singleRecord
    1043         * @return a List of Record objects
    1044         * @throws TorqueException Any exceptions caught during processing will be
    1045         *         rethrown wrapped into a TorqueException.
    1046         * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,boolean)
    1047         */
    1048        public static List<Record> getSelectResults(QueryDataSet qds, boolean singleRecord)
    1049            throws TorqueException
    1050        {
    1051            return BasePeer.getSelectResults(qds,singleRecord);
    1052        }
    1053
    1054        /**
    1055         * Returns numberOfResults records in a QueryDataSet as a List
    1056         * of Record objects.  Starting at record 0.  Used for
    1057         * functionality like util.LargeSelect.
    1058         *
    1059         * @see #getSelectResults(QueryDataSet, int, int, boolean)
    1060         * @param qds the QueryDataSet
    1061         * @param numberOfResults
    1062         * @param singleRecord
    1063         * @return a List of Record objects
    1064         * @throws TorqueException Any exceptions caught during processing will be
    1065         *         rethrown wrapped into a TorqueException.
    1066         * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,boolean)
    1067         */
    1068        public static List<Record> getSelectResults(
    1069            QueryDataSet qds,
    1070            int numberOfResults,
    1071            boolean singleRecord)
    1072            throws TorqueException
    1073        {
    1074            return BasePeer.getSelectResults(qds,numberOfResults,singleRecord);
    1075        }
    1076
    1077        /**
    1078         * Returns numberOfResults records in a QueryDataSet as a List
    1079         * of Record objects.  Starting at record start.  Used for
    1080         * functionality like util.LargeSelect.
    1081         *
    1082         * @param qds The <code>QueryDataSet</code> to extract results
    1083         * from.
    1084         * @param start The index from which to start retrieving
    1085         * <code>Record</code> objects from the data set.
    1086         * @param numberOfResults The number of results to return (or
    1087         * <code> -1</code> for all results).
    1088         * @param singleRecord Whether or not we want to select only a
    1089         * single record.
    1090         * @return A <code>List</code> of <code>Record</code> objects.
    1091         * @exception TorqueException If any <code>Exception</code> occurs.
    1092         * @see org.apache.torque.util.BasePeer#getSelectResults(QueryDataSet,int,int,boolean)
    1093         */
    1094        public static List getSelectResults(
    1095            QueryDataSet qds,
    1096            int start,
    1097            int numberOfResults,
    1098            boolean singleRecord)
    1099            throws TorqueException
    1100        {
    1101            return BasePeer.getSelectResults(qds,start,numberOfResults,singleRecord);
    1102        }
    1103
    1104        /**
    1105         * Performs a SQL <code>select</code> using a PreparedStatement.
    1106         * Note: this method does not handle null criteria values.
    1107         *
    1108         * @param criteria
    1109         * @param con
    1110         * @return a List of Record objects.
    1111         * @throws TorqueException Error performing database query.
    1112         * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria,Connection)
    1113         */
    1114        public static List<Record> doPSSelect(Criteria criteria, Connection con)
    1115            throws TorqueException
    1116        {
    1117            return BasePeer.doPSSelect(criteria,con);
    1118        }
    1119
    1120        /**
    1121         * Do a Prepared Statement select according to the given criteria
    1122         *
    1123         * @param criteria
    1124         * @return a List of Record objects.
    1125         * @throws TorqueException Any exceptions caught during processing will be
    1126         *         rethrown wrapped into a TorqueException.
    1127         * @see org.apache.torque.util.BasePeer#doPSSelect(Criteria)
    1128         */
    1129        public static List<Record> doPSSelect(Criteria criteria) throws TorqueException
    1130        {
    1131            return BasePeer.doPSSelect(criteria);
    1132        }
    1133    }