View Javadoc

    1   package org.apache.turbine.services.schedule;
    2
    3   import java.sql.ResultSet;
    4   import java.sql.SQLException;
    5   import java.util.List;
    6
    7   import org.apache.commons.logging.Log;
    8   import org.apache.commons.logging.LogFactory;
    9   import org.apache.torque.Column;
    10  import org.apache.torque.TorqueException;
    11  import org.apache.torque.criteria.CriteriaInterface;
    12  import org.apache.torque.om.mapper.RecordMapper;
    13
    14
    15  /**
    16   * Maps ResultSet rows into JobEntryTorque objects.
    17   *
    18   * The skeleton for this class was autogenerated by Torque on:
    19   *
    20   * [Mon Dec 21 20:40:21 CET 2015]
    21   *
    22   */
    23  public class BaseJobEntryTorqueRecordMapper implements RecordMapper<JobEntryTorque>
    24  {
    25
    26      /** The class log. */
    27      private static Log log
    28              = LogFactory.getLog(BaseJobEntryTorqueRecordMapper.class);
    29
    30      /**
    31       * Constructs the object from the current row in the resultSet.
    32       *
    33       * @param resultSet the resultSet to operate on, already pointing
    34       *        to the correct row. Not null.
    35       * @param a possible offset in the columns to be considered
    36       *        (if previous columns contain other objects),
    37       *        or 0 for no offset.
    38       * @param criteria The criteria which created the result set.
    39       *        If set, the attributes to set in the data object
    40       *        are determined from the select columns in the criteria;
    41       *        if no matching column can be found, null is returned.
    42       *        If not set, all of the table's columns are read from the
    43       *        result set in the order defined in the table definition.
    44       *
    45       * @return the mapped object, not null.
    46       *
    47       * @throws TorqueException when reading fields from the RecordSet fails
    48       *         or if a Criteria is passed which contains select columns other
    49       *         than the columns in the TURBINE_SCHEDULED_JOB table.
    50       */
    51      public JobEntryTorque processRow(
    52                  ResultSet resultSet,
    53                  int offset,
    54                  CriteriaInterface<?> criteria)
    55              throws TorqueException
    56      {
    57          JobEntryTorque jobEntryTorque = new JobEntryTorque();
    58
    59          try
    60          {
    61              jobEntryTorque.setLoading(true);
    62              if (criteria == null)
    63              {
    64                  jobEntryTorque.setJobId(
    65                          getJobId(resultSet, offset + 1));
    66                  jobEntryTorque.setSecond(
    67                          getSecond(resultSet, offset + 2));
    68                  jobEntryTorque.setMinute(
    69                          getMinute(resultSet, offset + 3));
    70                  jobEntryTorque.setHour(
    71                          getHour(resultSet, offset + 4));
    72                  jobEntryTorque.setWeekDay(
    73                          getWeekDay(resultSet, offset + 5));
    74                  jobEntryTorque.setDayOfMonth(
    75                          getDayOfMonth(resultSet, offset + 6));
    76                  jobEntryTorque.setTask(
    77                          getTask(resultSet, offset + 7));
    78                  jobEntryTorque.setEmail(
    79                          getEmail(resultSet, offset + 8));
    80                  jobEntryTorque.setProperty(
    81                          getProperty(resultSet, offset + 9));
    82              }
    83              else
    84              {
    85                  // try to get columns to be mapped
    86                  // from criteria's select columns
    87                  boolean columnMapped = false;
    88                  int totalOffset = offset + 1;
    89                  List<Column> selectColumns = criteria.getSelectColumns();
    90                  List<Column> columnsWithoutOffset = selectColumns.subList(
    91                          offset,
    92                          selectColumns.size());
    93                  for (Column column : columnsWithoutOffset)
    94                  {
    95                      if (BaseJobEntryTorquePeer.JOB_ID.getSqlExpression().equals(
    96                              column.getSqlExpression()))
    97                      {
    98                          jobEntryTorque.setJobId(
    99                              getJobId(resultSet, totalOffset));
    100                         columnMapped = true;
    101                     }
    102                     else if (BaseJobEntryTorquePeer.SECOND.getSqlExpression().equals(
    103                             column.getSqlExpression()))
    104                     {
    105                         jobEntryTorque.setSecond(
    106                             getSecond(resultSet, totalOffset));
    107                         columnMapped = true;
    108                     }
    109                     else if (BaseJobEntryTorquePeer.MINUTE.getSqlExpression().equals(
    110                             column.getSqlExpression()))
    111                     {
    112                         jobEntryTorque.setMinute(
    113                             getMinute(resultSet, totalOffset));
    114                         columnMapped = true;
    115                     }
    116                     else if (BaseJobEntryTorquePeer.HOUR.getSqlExpression().equals(
    117                             column.getSqlExpression()))
    118                     {
    119                         jobEntryTorque.setHour(
    120                             getHour(resultSet, totalOffset));
    121                         columnMapped = true;
    122                     }
    123                     else if (BaseJobEntryTorquePeer.WEEK_DAY.getSqlExpression().equals(
    124                             column.getSqlExpression()))
    125                     {
    126                         jobEntryTorque.setWeekDay(
    127                             getWeekDay(resultSet, totalOffset));
    128                         columnMapped = true;
    129                     }
    130                     else if (BaseJobEntryTorquePeer.DAY_OF_MONTH.getSqlExpression().equals(
    131                             column.getSqlExpression()))
    132                     {
    133                         jobEntryTorque.setDayOfMonth(
    134                             getDayOfMonth(resultSet, totalOffset));
    135                         columnMapped = true;
    136                     }
    137                     else if (BaseJobEntryTorquePeer.TASK.getSqlExpression().equals(
    138                             column.getSqlExpression()))
    139                     {
    140                         jobEntryTorque.setTask(
    141                             getTask(resultSet, totalOffset));
    142                         columnMapped = true;
    143                     }
    144                     else if (BaseJobEntryTorquePeer.EMAIL.getSqlExpression().equals(
    145                             column.getSqlExpression()))
    146                     {
    147                         jobEntryTorque.setEmail(
    148                             getEmail(resultSet, totalOffset));
    149                         columnMapped = true;
    150                     }
    151                     else if (BaseJobEntryTorquePeer.PROPERTY.getSqlExpression().equals(
    152                             column.getSqlExpression()))
    153                     {
    154                         jobEntryTorque.setProperty(
    155                             getProperty(resultSet, totalOffset));
    156                         columnMapped = true;
    157                     }
    158                     totalOffset++;
    159                 }
    160                 if (!columnMapped)
    161                 {
    162                     log.debug("no columns to map found in criteria, "
    163                         + "returning null");
    164                     return null;
    165                 }
    166             }
    167             jobEntryTorque.setNew(false);
    168             jobEntryTorque.setModified(false);
    169         }
    170         finally
    171         {
    172             jobEntryTorque.setLoading(false);
    173         }
    174         return jobEntryTorque;
    175     }
    176
    177         /**
    178          * Reads the value of the <code>columnIndex</code>'th column
    179          * in the <code>resultSet</code> so that it can be used to set
    180          * the field jobId in JobEntryTorque.
    181          *
    182          * @param dbObject the database object to fill, not null.
    183          * @param resultSet the ResultSet to read from, not null.
    184          * @param columnIndex the index in the resultSet which should be read.
    185          *
    186          * @return the content of the column.
    187          *
    188          * @throws SQLException if a problem occurs when reading
    189          *         from the resultSet.
    190          */
    191         protected int getJobId(
    192                     ResultSet resultSet,
    193                     int columnIndex)
    194                 throws TorqueException
    195         {
    196             try
    197             {
    198                 return resultSet.getInt(columnIndex);
    199             }
    200             catch (SQLException e)
    201             {
    202                 throw new TorqueException(e);
    203             }
    204         }
    205
    206         /**
    207          * Reads the value of the <code>columnIndex</code>'th column
    208          * in the <code>resultSet</code> so that it can be used to set
    209          * the field second in JobEntryTorque.
    210          *
    211          * @param dbObject the database object to fill, not null.
    212          * @param resultSet the ResultSet to read from, not null.
    213          * @param columnIndex the index in the resultSet which should be read.
    214          *
    215          * @return the content of the column.
    216          *
    217          * @throws SQLException if a problem occurs when reading
    218          *         from the resultSet.
    219          */
    220         protected int getSecond(
    221                     ResultSet resultSet,
    222                     int columnIndex)
    223                 throws TorqueException
    224         {
    225             try
    226             {
    227                 return resultSet.getInt(columnIndex);
    228             }
    229             catch (SQLException e)
    230             {
    231                 throw new TorqueException(e);
    232             }
    233         }
    234
    235         /**
    236          * Reads the value of the <code>columnIndex</code>'th column
    237          * in the <code>resultSet</code> so that it can be used to set
    238          * the field minute in JobEntryTorque.
    239          *
    240          * @param dbObject the database object to fill, not null.
    241          * @param resultSet the ResultSet to read from, not null.
    242          * @param columnIndex the index in the resultSet which should be read.
    243          *
    244          * @return the content of the column.
    245          *
    246          * @throws SQLException if a problem occurs when reading
    247          *         from the resultSet.
    248          */
    249         protected int getMinute(
    250                     ResultSet resultSet,
    251                     int columnIndex)
    252                 throws TorqueException
    253         {
    254             try
    255             {
    256                 return resultSet.getInt(columnIndex);
    257             }
    258             catch (SQLException e)
    259             {
    260                 throw new TorqueException(e);
    261             }
    262         }
    263
    264         /**
    265          * Reads the value of the <code>columnIndex</code>'th column
    266          * in the <code>resultSet</code> so that it can be used to set
    267          * the field hour in JobEntryTorque.
    268          *
    269          * @param dbObject the database object to fill, not null.
    270          * @param resultSet the ResultSet to read from, not null.
    271          * @param columnIndex the index in the resultSet which should be read.
    272          *
    273          * @return the content of the column.
    274          *
    275          * @throws SQLException if a problem occurs when reading
    276          *         from the resultSet.
    277          */
    278         protected int getHour(
    279                     ResultSet resultSet,
    280                     int columnIndex)
    281                 throws TorqueException
    282         {
    283             try
    284             {
    285                 return resultSet.getInt(columnIndex);
    286             }
    287             catch (SQLException e)
    288             {
    289                 throw new TorqueException(e);
    290             }
    291         }
    292
    293         /**
    294          * Reads the value of the <code>columnIndex</code>'th column
    295          * in the <code>resultSet</code> so that it can be used to set
    296          * the field weekDay in JobEntryTorque.
    297          *
    298          * @param dbObject the database object to fill, not null.
    299          * @param resultSet the ResultSet to read from, not null.
    300          * @param columnIndex the index in the resultSet which should be read.
    301          *
    302          * @return the content of the column.
    303          *
    304          * @throws SQLException if a problem occurs when reading
    305          *         from the resultSet.
    306          */
    307         protected int getWeekDay(
    308                     ResultSet resultSet,
    309                     int columnIndex)
    310                 throws TorqueException
    311         {
    312             try
    313             {
    314                 return resultSet.getInt(columnIndex);
    315             }
    316             catch (SQLException e)
    317             {
    318                 throw new TorqueException(e);
    319             }
    320         }
    321
    322         /**
    323          * Reads the value of the <code>columnIndex</code>'th column
    324          * in the <code>resultSet</code> so that it can be used to set
    325          * the field dayOfMonth in JobEntryTorque.
    326          *
    327          * @param dbObject the database object to fill, not null.
    328          * @param resultSet the ResultSet to read from, not null.
    329          * @param columnIndex the index in the resultSet which should be read.
    330          *
    331          * @return the content of the column.
    332          *
    333          * @throws SQLException if a problem occurs when reading
    334          *         from the resultSet.
    335          */
    336         protected int getDayOfMonth(
    337                     ResultSet resultSet,
    338                     int columnIndex)
    339                 throws TorqueException
    340         {
    341             try
    342             {
    343                 return resultSet.getInt(columnIndex);
    344             }
    345             catch (SQLException e)
    346             {
    347                 throw new TorqueException(e);
    348             }
    349         }
    350
    351         /**
    352          * Reads the value of the <code>columnIndex</code>'th column
    353          * in the <code>resultSet</code> so that it can be used to set
    354          * the field task in JobEntryTorque.
    355          *
    356          * @param dbObject the database object to fill, not null.
    357          * @param resultSet the ResultSet to read from, not null.
    358          * @param columnIndex the index in the resultSet which should be read.
    359          *
    360          * @return the content of the column.
    361          *
    362          * @throws SQLException if a problem occurs when reading
    363          *         from the resultSet.
    364          */
    365         protected String getTask(
    366                     ResultSet resultSet,
    367                     int columnIndex)
    368                 throws TorqueException
    369         {
    370             try
    371             {
    372                 return resultSet.getString(columnIndex);
    373             }
    374             catch (SQLException e)
    375             {
    376                 throw new TorqueException(e);
    377             }
    378         }
    379
    380         /**
    381          * Reads the value of the <code>columnIndex</code>'th column
    382          * in the <code>resultSet</code> so that it can be used to set
    383          * the field email in JobEntryTorque.
    384          *
    385          * @param dbObject the database object to fill, not null.
    386          * @param resultSet the ResultSet to read from, not null.
    387          * @param columnIndex the index in the resultSet which should be read.
    388          *
    389          * @return the content of the column.
    390          *
    391          * @throws SQLException if a problem occurs when reading
    392          *         from the resultSet.
    393          */
    394         protected String getEmail(
    395                     ResultSet resultSet,
    396                     int columnIndex)
    397                 throws TorqueException
    398         {
    399             try
    400             {
    401                 return resultSet.getString(columnIndex);
    402             }
    403             catch (SQLException e)
    404             {
    405                 throw new TorqueException(e);
    406             }
    407         }
    408
    409         /**
    410          * Reads the value of the <code>columnIndex</code>'th column
    411          * in the <code>resultSet</code> so that it can be used to set
    412          * the field property in JobEntryTorque.
    413          *
    414          * @param dbObject the database object to fill, not null.
    415          * @param resultSet the ResultSet to read from, not null.
    416          * @param columnIndex the index in the resultSet which should be read.
    417          *
    418          * @return the content of the column.
    419          *
    420          * @throws SQLException if a problem occurs when reading
    421          *         from the resultSet.
    422          */
    423         protected byte[] getProperty(
    424                     ResultSet resultSet,
    425                     int columnIndex)
    426                 throws TorqueException
    427         {
    428             try
    429             {
    430                 byte[] value = resultSet.getBytes(columnIndex);
    431                 if (resultSet.wasNull())
    432                 {
    433                     value = null;
    434                 }
    435                 return value;
    436             }
    437             catch (SQLException e)
    438             {
    439                 throw new TorqueException(e);
    440             }
    441         }
    442
    443
    444 }