Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
BaseJobEntryTorqueRecordMapper |
|
| 5.1;5,1 |
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 | * [Tue Jun 18 13:27:16 CEST 2019] | |
21 | * | |
22 | */ | |
23 | 0 | public class BaseJobEntryTorqueRecordMapper implements RecordMapper<JobEntryTorque> |
24 | { | |
25 | ||
26 | /** The class log. */ | |
27 | 0 | private static Log log |
28 | 0 | = 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 | 0 | JobEntryTorque jobEntryTorque = new JobEntryTorque(); |
58 | ||
59 | try | |
60 | { | |
61 | 0 | jobEntryTorque.setLoading(true); |
62 | 0 | if (criteria == null) |
63 | { | |
64 | 0 | jobEntryTorque.setJobId( |
65 | 0 | getJobId(resultSet, offset + 1)); |
66 | 0 | jobEntryTorque.setSecond( |
67 | 0 | getSecond(resultSet, offset + 2)); |
68 | 0 | jobEntryTorque.setMinute( |
69 | 0 | getMinute(resultSet, offset + 3)); |
70 | 0 | jobEntryTorque.setHour( |
71 | 0 | getHour(resultSet, offset + 4)); |
72 | 0 | jobEntryTorque.setWeekDay( |
73 | 0 | getWeekDay(resultSet, offset + 5)); |
74 | 0 | jobEntryTorque.setDayOfMonth( |
75 | 0 | getDayOfMonth(resultSet, offset + 6)); |
76 | 0 | jobEntryTorque.setTask( |
77 | 0 | getTask(resultSet, offset + 7)); |
78 | 0 | jobEntryTorque.setEmail( |
79 | 0 | getEmail(resultSet, offset + 8)); |
80 | 0 | jobEntryTorque.setProperty( |
81 | 0 | getProperty(resultSet, offset + 9)); |
82 | } | |
83 | else | |
84 | { | |
85 | // try to get columns to be mapped | |
86 | // from criteria's select columns | |
87 | 0 | boolean columnMapped = false; |
88 | 0 | int totalOffset = offset + 1; |
89 | 0 | List<Column> selectColumns = criteria.getSelectColumns(); |
90 | 0 | List<Column> columnsWithoutOffset = selectColumns.subList( |
91 | offset, | |
92 | 0 | selectColumns.size()); |
93 | 0 | for (Column column : columnsWithoutOffset) |
94 | { | |
95 | 0 | if (BaseJobEntryTorquePeer.JOB_ID.getSqlExpression().equals( |
96 | 0 | column.getSqlExpression())) |
97 | { | |
98 | 0 | jobEntryTorque.setJobId( |
99 | 0 | getJobId(resultSet, totalOffset)); |
100 | 0 | columnMapped = true; |
101 | } | |
102 | 0 | else if (BaseJobEntryTorquePeer.SECOND.getSqlExpression().equals( |
103 | 0 | column.getSqlExpression())) |
104 | { | |
105 | 0 | jobEntryTorque.setSecond( |
106 | 0 | getSecond(resultSet, totalOffset)); |
107 | 0 | columnMapped = true; |
108 | } | |
109 | 0 | else if (BaseJobEntryTorquePeer.MINUTE.getSqlExpression().equals( |
110 | 0 | column.getSqlExpression())) |
111 | { | |
112 | 0 | jobEntryTorque.setMinute( |
113 | 0 | getMinute(resultSet, totalOffset)); |
114 | 0 | columnMapped = true; |
115 | } | |
116 | 0 | else if (BaseJobEntryTorquePeer.HOUR.getSqlExpression().equals( |
117 | 0 | column.getSqlExpression())) |
118 | { | |
119 | 0 | jobEntryTorque.setHour( |
120 | 0 | getHour(resultSet, totalOffset)); |
121 | 0 | columnMapped = true; |
122 | } | |
123 | 0 | else if (BaseJobEntryTorquePeer.WEEK_DAY.getSqlExpression().equals( |
124 | 0 | column.getSqlExpression())) |
125 | { | |
126 | 0 | jobEntryTorque.setWeekDay( |
127 | 0 | getWeekDay(resultSet, totalOffset)); |
128 | 0 | columnMapped = true; |
129 | } | |
130 | 0 | else if (BaseJobEntryTorquePeer.DAY_OF_MONTH.getSqlExpression().equals( |
131 | 0 | column.getSqlExpression())) |
132 | { | |
133 | 0 | jobEntryTorque.setDayOfMonth( |
134 | 0 | getDayOfMonth(resultSet, totalOffset)); |
135 | 0 | columnMapped = true; |
136 | } | |
137 | 0 | else if (BaseJobEntryTorquePeer.TASK.getSqlExpression().equals( |
138 | 0 | column.getSqlExpression())) |
139 | { | |
140 | 0 | jobEntryTorque.setTask( |
141 | 0 | getTask(resultSet, totalOffset)); |
142 | 0 | columnMapped = true; |
143 | } | |
144 | 0 | else if (BaseJobEntryTorquePeer.EMAIL.getSqlExpression().equals( |
145 | 0 | column.getSqlExpression())) |
146 | { | |
147 | 0 | jobEntryTorque.setEmail( |
148 | 0 | getEmail(resultSet, totalOffset)); |
149 | 0 | columnMapped = true; |
150 | } | |
151 | 0 | else if (BaseJobEntryTorquePeer.PROPERTY.getSqlExpression().equals( |
152 | 0 | column.getSqlExpression())) |
153 | { | |
154 | 0 | jobEntryTorque.setProperty( |
155 | 0 | getProperty(resultSet, totalOffset)); |
156 | 0 | columnMapped = true; |
157 | } | |
158 | 0 | totalOffset++; |
159 | 0 | } |
160 | 0 | if (!columnMapped) |
161 | { | |
162 | 0 | log.debug("no columns to map found in criteria, " |
163 | + "returning null"); | |
164 | 0 | return null; |
165 | } | |
166 | } | |
167 | 0 | jobEntryTorque.setNew(false); |
168 | 0 | jobEntryTorque.setModified(false); |
169 | } | |
170 | finally | |
171 | { | |
172 | 0 | jobEntryTorque.setLoading(false); |
173 | 0 | } |
174 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
199 | } | |
200 | 0 | catch (SQLException e) |
201 | { | |
202 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
228 | } | |
229 | 0 | catch (SQLException e) |
230 | { | |
231 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
257 | } | |
258 | 0 | catch (SQLException e) |
259 | { | |
260 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
286 | } | |
287 | 0 | catch (SQLException e) |
288 | { | |
289 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
315 | } | |
316 | 0 | catch (SQLException e) |
317 | { | |
318 | 0 | 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 | 0 | return resultSet.getInt(columnIndex); |
344 | } | |
345 | 0 | catch (SQLException e) |
346 | { | |
347 | 0 | 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 | 0 | return resultSet.getString(columnIndex); |
373 | } | |
374 | 0 | catch (SQLException e) |
375 | { | |
376 | 0 | 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 | 0 | return resultSet.getString(columnIndex); |
402 | } | |
403 | 0 | catch (SQLException e) |
404 | { | |
405 | 0 | 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 | 0 | byte[] value = resultSet.getBytes(columnIndex); |
431 | 0 | if (resultSet.wasNull()) |
432 | { | |
433 | 0 | value = null; |
434 | } | |
435 | 0 | return value; |
436 | } | |
437 | 0 | catch (SQLException e) |
438 | { | |
439 | 0 | throw new TorqueException(e); |
440 | } | |
441 | } | |
442 | ||
443 | ||
444 | } |