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.CriteriaInterface; 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 * [Mon Mar 05 12:40:05 CET 2018] 021 * 022 */ 023public class BaseJobEntryTorqueRecordMapper implements RecordMapper<JobEntryTorque> 024{ 025 026 /** The class log. */ 027 private static Log log 028 = LogFactory.getLog(BaseJobEntryTorqueRecordMapper.class); 029 030 /** 031 * Constructs the object from the current row in the resultSet. 032 * 033 * @param resultSet the resultSet to operate on, already pointing 034 * to the correct row. Not null. 035 * @param a possible offset in the columns to be considered 036 * (if previous columns contain other objects), 037 * or 0 for no offset. 038 * @param criteria The criteria which created the result set. 039 * If set, the attributes to set in the data object 040 * are determined from the select columns in the criteria; 041 * if no matching column can be found, null is returned. 042 * If not set, all of the table's columns are read from the 043 * result set in the order defined in the table definition. 044 * 045 * @return the mapped object, not null. 046 * 047 * @throws TorqueException when reading fields from the RecordSet fails 048 * or if a Criteria is passed which contains select columns other 049 * than the columns in the TURBINE_SCHEDULED_JOB table. 050 */ 051 public JobEntryTorque processRow( 052 ResultSet resultSet, 053 int offset, 054 CriteriaInterface<?> criteria) 055 throws TorqueException 056 { 057 JobEntryTorque jobEntryTorque = new JobEntryTorque(); 058 059 try 060 { 061 jobEntryTorque.setLoading(true); 062 if (criteria == null) 063 { 064 jobEntryTorque.setJobId( 065 getJobId(resultSet, offset + 1)); 066 jobEntryTorque.setSecond( 067 getSecond(resultSet, offset + 2)); 068 jobEntryTorque.setMinute( 069 getMinute(resultSet, offset + 3)); 070 jobEntryTorque.setHour( 071 getHour(resultSet, offset + 4)); 072 jobEntryTorque.setWeekDay( 073 getWeekDay(resultSet, offset + 5)); 074 jobEntryTorque.setDayOfMonth( 075 getDayOfMonth(resultSet, offset + 6)); 076 jobEntryTorque.setTask( 077 getTask(resultSet, offset + 7)); 078 jobEntryTorque.setEmail( 079 getEmail(resultSet, offset + 8)); 080 jobEntryTorque.setProperty( 081 getProperty(resultSet, offset + 9)); 082 } 083 else 084 { 085 // try to get columns to be mapped 086 // from criteria's select columns 087 boolean columnMapped = false; 088 int totalOffset = offset + 1; 089 List<Column> selectColumns = criteria.getSelectColumns(); 090 List<Column> columnsWithoutOffset = selectColumns.subList( 091 offset, 092 selectColumns.size()); 093 for (Column column : columnsWithoutOffset) 094 { 095 if (BaseJobEntryTorquePeer.JOB_ID.getSqlExpression().equals( 096 column.getSqlExpression())) 097 { 098 jobEntryTorque.setJobId( 099 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}