|
16 | 16 |
|
17 | 17 | package org.springframework.batch.core.repository.dao;
|
18 | 18 |
|
| 19 | +import java.sql.PreparedStatement; |
19 | 20 | import java.sql.ResultSet;
|
20 | 21 | import java.sql.SQLException;
|
21 | 22 | import java.sql.Timestamp;
|
22 | 23 | import java.sql.Types;
|
23 | 24 | import java.util.HashMap;
|
24 | 25 | import java.util.HashSet;
|
25 | 26 | import java.util.List;
|
| 27 | +import java.util.Date; |
26 | 28 | import java.util.Map;
|
27 |
| -import java.util.Map.Entry; |
28 | 29 | import java.util.Set;
|
29 | 30 |
|
30 | 31 | import org.apache.commons.logging.Log;
|
|
61 | 62 | * @author Michael Minella
|
62 | 63 | * @author Mahmoud Ben Hassine
|
63 | 64 | * @author Dimitrios Liapis
|
| 65 | + * @author Philippe Marschall |
64 | 66 | */
|
65 | 67 | public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean {
|
66 | 68 |
|
@@ -321,42 +323,53 @@ public void synchronizeStatus(JobExecution jobExecution) {
|
321 | 323 | */
|
322 | 324 | private void insertJobParameters(Long executionId, JobParameters jobParameters) {
|
323 | 325 |
|
324 |
| - for (Entry<String, JobParameter> entry : jobParameters.getParameters() |
325 |
| - .entrySet()) { |
326 |
| - JobParameter jobParameter = entry.getValue(); |
327 |
| - insertParameter(executionId, jobParameter.getType(), entry.getKey(), |
328 |
| - jobParameter.getValue(), jobParameter.isIdentifying()); |
| 326 | + if (jobParameters.isEmpty()) { |
| 327 | + return; |
329 | 328 | }
|
330 |
| - } |
331 | 329 |
|
| 330 | + getJdbcTemplate().batchUpdate(getQuery(CREATE_JOB_PARAMETERS), jobParameters.getParameters().entrySet(), 100, (ps, entry) -> { |
| 331 | + JobParameter jobParameter = entry.getValue(); |
| 332 | + String key = entry.getKey(); |
| 333 | + ParameterType type = jobParameter.getType(); |
| 334 | + Object value = jobParameter.getValue(); |
| 335 | + boolean identifying = jobParameter.isIdentifying(); |
| 336 | + setJobParameters(executionId, type, key, value, identifying, ps); |
| 337 | + }); |
| 338 | + } |
| 339 | + |
332 | 340 | /**
|
333 | 341 | * Convenience method that inserts an individual records into the
|
334 | 342 | * JobParameters table.
|
335 | 343 | */
|
336 |
| - private void insertParameter(Long executionId, ParameterType type, String key, |
337 |
| - Object value, boolean identifying) { |
338 |
| - |
339 |
| - Object[] args = new Object[0]; |
340 |
| - int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, |
341 |
| - Types.VARCHAR, Types.VARCHAR, Types.TIMESTAMP, Types.BIGINT, |
342 |
| - Types.DOUBLE, Types.CHAR }; |
343 |
| - |
344 |
| - String identifyingFlag = identifying? "Y":"N"; |
345 |
| - |
| 344 | + private static void setJobParameters(Long executionId, ParameterType type, String key, |
| 345 | + Object value, boolean identifying, PreparedStatement preparedStatement) |
| 346 | + throws SQLException { |
| 347 | + |
| 348 | + preparedStatement.setLong(1, executionId); |
| 349 | + preparedStatement.setString(2, key); |
| 350 | + preparedStatement.setString(3, type.toString()); |
346 | 351 | if (type == ParameterType.STRING) {
|
347 |
| - args = new Object[] { executionId, key, type, value, new Timestamp(0L), |
348 |
| - 0L, 0D, identifyingFlag}; |
349 |
| - } else if (type == ParameterType.LONG) { |
350 |
| - args = new Object[] { executionId, key, type, "", new Timestamp(0L), |
351 |
| - value, 0.0d, identifyingFlag}; |
352 |
| - } else if (type == ParameterType.DOUBLE) { |
353 |
| - args = new Object[] { executionId, key, type, "", new Timestamp(0L), 0L, |
354 |
| - value, identifyingFlag}; |
355 |
| - } else if (type == ParameterType.DATE) { |
356 |
| - args = new Object[] { executionId, key, type, "", value, 0L, 0D, identifyingFlag}; |
| 352 | + preparedStatement.setString(4, (String) value); |
| 353 | + } else { |
| 354 | + preparedStatement.setString(4, ""); |
357 | 355 | }
|
358 |
| - |
359 |
| - getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); |
| 356 | + if (type == ParameterType.DATE) { |
| 357 | + preparedStatement.setTimestamp(5, new Timestamp(((Date) value).getTime())); |
| 358 | + } else { |
| 359 | + preparedStatement.setTimestamp(5, new Timestamp(0L)); |
| 360 | + } |
| 361 | + if (type == ParameterType.LONG) { |
| 362 | + preparedStatement.setLong(6, (Long) value); |
| 363 | + } else { |
| 364 | + preparedStatement.setLong(6, 0L); |
| 365 | + } |
| 366 | + if (type == ParameterType.DOUBLE) { |
| 367 | + preparedStatement.setDouble(7, (Double) value); |
| 368 | + } else { |
| 369 | + preparedStatement.setDouble(7, 0.0d); |
| 370 | + } |
| 371 | + String identifyingFlag = identifying ? "Y" : "N"; |
| 372 | + preparedStatement.setString(8, identifyingFlag); |
360 | 373 | }
|
361 | 374 |
|
362 | 375 | /**
|
|
0 commit comments