001package org.apache.turbine.services.schedule; 002 003import java.sql.ResultSet; 004import java.sql.SQLException; 005import java.util.List; 006 007import org.apache.commons.logging.Log; 008import org.apache.commons.logging.LogFactory; 009import org.apache.torque.Column; 010import org.apache.torque.TorqueException; 011import org.apache.torque.criteria.Criteria; 012import org.apache.torque.om.mapper.RecordMapper; 013 014 015/** 016 * Maps ResultSet rows into JobEntryTorque objects. 017 * 018 * The skeleton for this class was autogenerated by Torque on: 019 * 020 * [Wed Sep 22 14:43:21 CEST 2021] 021 * 022 */ 023@SuppressWarnings("unused") 024public class BaseJobEntryTorqueRecordMapper implements RecordMapper<JobEntryTorque> 025{ 026 /** Serial version */ 027 private static final long serialVersionUID = 1632314601660L; 028 029 /** The class log. */ 030 private static Log log 031 = LogFactory.getLog(BaseJobEntryTorqueRecordMapper.class); 032 033 /** 034 * Constructs the object from the current row in the resultSet. 035 * 036 * @param resultSet the resultSet to operate on, already pointing 037 * to the correct row. Not null. 038 * @param offset a possible offset in the columns to be considered 039 * (if previous columns contain other objects), 040 * or 0 for no offset. 041 * @param criteria The criteria which created the result set. 042 * If set, the attributes to set in the data object 043 * are determined from the select columns in the criteria; 044 * if no matching column can be found, null is returned. 045 * If not set, all of the table's columns are read from the 046 * result set in the order defined in the table definition. 047 * 048 * @return the mapped object, not null. 049 * 050 * @throws TorqueException when reading fields from the RecordSet fails 051 * or if a Criteria is passed which contains select columns other 052 * than the columns in the TURBINE_SCHEDULED_JOB table. 053 */ 054 public JobEntryTorque processRow( 055 ResultSet resultSet, 056 int offset, 057 Criteria criteria) 058 throws TorqueException 059 { 060 JobEntryTorque jobEntryTorque = new JobEntryTorque(); 061 062 try 063 { 064 jobEntryTorque.setLoading(true); 065 if (criteria == null) 066 { 067 jobEntryTorque.setJobId( 068 getJobId(resultSet, offset + 1)); 069 jobEntryTorque.setSecond( 070 getSecond(resultSet, offset + 2)); 071 jobEntryTorque.setMinute( 072 getMinute(resultSet, offset + 3)); 073 jobEntryTorque.setHour( 074 getHour(resultSet, offset + 4)); 075 jobEntryTorque.setWeekDay( 076 getWeekDay(resultSet, offset + 5)); 077 jobEntryTorque.setDayOfMonth( 078 getDayOfMonth(resultSet, offset + 6)); 079 jobEntryTorque.setTask( 080 getTask(resultSet, offset + 7)); 081 jobEntryTorque.setEmail( 082 getEmail(resultSet, offset + 8)); 083 jobEntryTorque.setProperty( 084 getProperty(resultSet, offset + 9)); 085 } 086 else 087 { 088 // try to get columns to be mapped 089 // from criteria's select columns 090 boolean columnMapped = false; 091 int totalOffset = offset + 1; 092 List<Column> selectColumns = criteria.getSelectColumns(); 093 List<Column> columnsWithoutOffset = selectColumns.subList( 094 offset, 095 selectColumns.size()); 096 for (Column column : columnsWithoutOffset) 097 { 098 if (BaseJobEntryTorquePeer.JOB_ID.getSqlExpression().equals( 099 column.getSqlExpression())) 100 { 101 jobEntryTorque.setJobId( 102 getJobId(resultSet, totalOffset)); 103 columnMapped = true; 104 } 105 else if (BaseJobEntryTorquePeer.SECOND.getSqlExpression().equals( 106 column.getSqlExpression())) 107 { 108 jobEntryTorque.setSecond( 109 getSecond(resultSet, totalOffset)); 110 columnMapped = true; 111 } 112 else if (BaseJobEntryTorquePeer.MINUTE.getSqlExpression().equals( 113 column.getSqlExpression())) 114 { 115 jobEntryTorque.setMinute( 116 getMinute(resultSet, totalOffset)); 117 columnMapped = true; 118 } 119 else if (BaseJobEntryTorquePeer.HOUR.getSqlExpression().equals( 120 column.getSqlExpression())) 121 { 122 jobEntryTorque.setHour( 123 getHour(resultSet, totalOffset)); 124 columnMapped = true; 125 } 126 else if (BaseJobEntryTorquePeer.WEEK_DAY.getSqlExpression().equals( 127 column.getSqlExpression())) 128 { 129 jobEntryTorque.setWeekDay( 130 getWeekDay(resultSet, totalOffset)); 131 columnMapped = true; 132 } 133 else if (BaseJobEntryTorquePeer.DAY_OF_MONTH.getSqlExpression().equals( 134 column.getSqlExpression())) 135 { 136 jobEntryTorque.setDayOfMonth( 137 getDayOfMonth(resultSet, totalOffset)); 138 columnMapped = true; 139 } 140 else if (BaseJobEntryTorquePeer.TASK.getSqlExpression().equals( 141 column.getSqlExpression())) 142 { 143 jobEntryTorque.setTask( 144 getTask(resultSet, totalOffset)); 145 columnMapped = true; 146 } 147 else if (BaseJobEntryTorquePeer.EMAIL.getSqlExpression().equals( 148 column.getSqlExpression())) 149 { 150 jobEntryTorque.setEmail( 151 getEmail(resultSet, totalOffset)); 152 columnMapped = true; 153 } 154 else if (BaseJobEntryTorquePeer.PROPERTY.getSqlExpression().equals( 155 column.getSqlExpression())) 156 { 157 jobEntryTorque.setProperty( 158 getProperty(resultSet, totalOffset)); 159 columnMapped = true; 160 } 161 totalOffset++; 162 } 163 if (!columnMapped) 164 { 165 log.debug("no columns to map found in criteria, " 166 + "returning null"); 167 return null; 168 } 169 } 170 jobEntryTorque.setNew(false); 171 jobEntryTorque.setModified(false); 172 } 173 finally 174 { 175 jobEntryTorque.setLoading(false); 176 } 177 return jobEntryTorque; 178 } 179 180 /** 181 * Reads the value of the <code>columnIndex</code>'th column 182 * in the <code>resultSet</code> so that it can be used to set 183 * the field jobId in JobEntryTorque. 184 * 185 * @param resultSet the ResultSet to read from, not null. 186 * @param columnIndex the index in the resultSet which should be read. 187 * 188 * @return the content of the column. 189 * 190 * @throws SQLException if a problem occurs when reading 191 * from the resultSet. 192 */ 193 protected int getJobId( 194 ResultSet resultSet, 195 int columnIndex) 196 throws TorqueException 197 { 198 try 199 { 200 return resultSet.getInt(columnIndex); 201 } 202 catch (SQLException e) 203 { 204 throw new TorqueException(e); 205 } 206 } 207 /** 208 * Reads the value of the <code>columnIndex</code>'th column 209 * in the <code>resultSet</code> so that it can be used to set 210 * the field second in JobEntryTorque. 211 * 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 * Reads the value of the <code>columnIndex</code>'th column 236 * in the <code>resultSet</code> so that it can be used to set 237 * the field minute in JobEntryTorque. 238 * 239 * @param resultSet the ResultSet to read from, not null. 240 * @param columnIndex the index in the resultSet which should be read. 241 * 242 * @return the content of the column. 243 * 244 * @throws SQLException if a problem occurs when reading 245 * from the resultSet. 246 */ 247 protected int getMinute( 248 ResultSet resultSet, 249 int columnIndex) 250 throws TorqueException 251 { 252 try 253 { 254 return resultSet.getInt(columnIndex); 255 } 256 catch (SQLException e) 257 { 258 throw new TorqueException(e); 259 } 260 } 261 /** 262 * Reads the value of the <code>columnIndex</code>'th column 263 * in the <code>resultSet</code> so that it can be used to set 264 * the field hour in JobEntryTorque. 265 * 266 * @param resultSet the ResultSet to read from, not null. 267 * @param columnIndex the index in the resultSet which should be read. 268 * 269 * @return the content of the column. 270 * 271 * @throws SQLException if a problem occurs when reading 272 * from the resultSet. 273 */ 274 protected int getHour( 275 ResultSet resultSet, 276 int columnIndex) 277 throws TorqueException 278 { 279 try 280 { 281 return resultSet.getInt(columnIndex); 282 } 283 catch (SQLException e) 284 { 285 throw new TorqueException(e); 286 } 287 } 288 /** 289 * Reads the value of the <code>columnIndex</code>'th column 290 * in the <code>resultSet</code> so that it can be used to set 291 * the field weekDay in JobEntryTorque. 292 * 293 * @param resultSet the ResultSet to read from, not null. 294 * @param columnIndex the index in the resultSet which should be read. 295 * 296 * @return the content of the column. 297 * 298 * @throws SQLException if a problem occurs when reading 299 * from the resultSet. 300 */ 301 protected int getWeekDay( 302 ResultSet resultSet, 303 int columnIndex) 304 throws TorqueException 305 { 306 try 307 { 308 return resultSet.getInt(columnIndex); 309 } 310 catch (SQLException e) 311 { 312 throw new TorqueException(e); 313 } 314 } 315 /** 316 * Reads the value of the <code>columnIndex</code>'th column 317 * in the <code>resultSet</code> so that it can be used to set 318 * the field dayOfMonth in JobEntryTorque. 319 * 320 * @param resultSet the ResultSet to read from, not null. 321 * @param columnIndex the index in the resultSet which should be read. 322 * 323 * @return the content of the column. 324 * 325 * @throws SQLException if a problem occurs when reading 326 * from the resultSet. 327 */ 328 protected int getDayOfMonth( 329 ResultSet resultSet, 330 int columnIndex) 331 throws TorqueException 332 { 333 try 334 { 335 return resultSet.getInt(columnIndex); 336 } 337 catch (SQLException e) 338 { 339 throw new TorqueException(e); 340 } 341 } 342 /** 343 * Reads the value of the <code>columnIndex</code>'th column 344 * in the <code>resultSet</code> so that it can be used to set 345 * the field task in JobEntryTorque. 346 * 347 * @param resultSet the ResultSet to read from, not null. 348 * @param columnIndex the index in the resultSet which should be read. 349 * 350 * @return the content of the column. 351 * 352 * @throws SQLException if a problem occurs when reading 353 * from the resultSet. 354 */ 355 protected String getTask( 356 ResultSet resultSet, 357 int columnIndex) 358 throws TorqueException 359 { 360 try 361 { 362 return resultSet.getString(columnIndex); 363 } 364 catch (SQLException e) 365 { 366 throw new TorqueException(e); 367 } 368 } 369 /** 370 * Reads the value of the <code>columnIndex</code>'th column 371 * in the <code>resultSet</code> so that it can be used to set 372 * the field email in JobEntryTorque. 373 * 374 * @param resultSet the ResultSet to read from, not null. 375 * @param columnIndex the index in the resultSet which should be read. 376 * 377 * @return the content of the column. 378 * 379 * @throws SQLException if a problem occurs when reading 380 * from the resultSet. 381 */ 382 protected String getEmail( 383 ResultSet resultSet, 384 int columnIndex) 385 throws TorqueException 386 { 387 try 388 { 389 return resultSet.getString(columnIndex); 390 } 391 catch (SQLException e) 392 { 393 throw new TorqueException(e); 394 } 395 } 396 /** 397 * Reads the value of the <code>columnIndex</code>'th column 398 * in the <code>resultSet</code> so that it can be used to set 399 * the field property in JobEntryTorque. 400 * 401 * @param resultSet the ResultSet to read from, not null. 402 * @param columnIndex the index in the resultSet which should be read. 403 * 404 * @return the content of the column. 405 * 406 * @throws SQLException if a problem occurs when reading 407 * from the resultSet. 408 */ 409 protected byte[] getProperty( 410 ResultSet resultSet, 411 int columnIndex) 412 throws TorqueException 413 { 414 try 415 { 416 byte[] value = resultSet.getBytes(columnIndex); 417 if (resultSet.wasNull()) 418 { 419 value = null; 420 } 421 return value; 422 } 423 catch (SQLException e) 424 { 425 throw new TorqueException(e); 426 } 427 } 428 429}