|
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;
|
|
24 | 25 | import java.util.HashMap;
|
25 | 26 | import java.util.HashSet;
|
26 | 27 | import java.util.List;
|
| 28 | +import java.util.Date; |
27 | 29 | import java.util.Map;
|
28 |
| -import java.util.Map.Entry; |
29 | 30 | import java.util.Set;
|
30 | 31 |
|
31 | 32 | import org.apache.commons.logging.Log;
|
|
63 | 64 | * @author Michael Minella
|
64 | 65 | * @author Mahmoud Ben Hassine
|
65 | 66 | * @author Dimitrios Liapis
|
| 67 | + * @author Philippe Marschall |
66 | 68 | */
|
67 | 69 | public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean {
|
68 | 70 |
|
@@ -356,27 +358,34 @@ public void deleteJobExecutionParameters(JobExecution jobExecution) {
|
356 | 358 | */
|
357 | 359 | private void insertJobParameters(Long executionId, JobParameters jobParameters) {
|
358 | 360 |
|
359 |
| - for (Entry<String, JobParameter<?>> entry : jobParameters.getParameters().entrySet()) { |
360 |
| - JobParameter jobParameter = entry.getValue(); |
361 |
| - insertParameter(executionId, jobParameter.getType(), entry.getKey(), jobParameter.getValue(), |
362 |
| - jobParameter.isIdentifying()); |
| 361 | + if (jobParameters.isEmpty()) { |
| 362 | + return; |
363 | 363 | }
|
| 364 | + |
| 365 | + getJdbcTemplate().batchUpdate(getQuery(CREATE_JOB_PARAMETERS), jobParameters.getParameters().entrySet(), 100, |
| 366 | + (ps, entry) -> { |
| 367 | + JobParameter jobParameter = entry.getValue(); |
| 368 | + insertParameter(ps, executionId, jobParameter.getType(), entry.getKey(), jobParameter.getValue(), |
| 369 | + jobParameter.isIdentifying()); |
| 370 | + }); |
364 | 371 | }
|
365 | 372 |
|
366 | 373 | /**
|
367 | 374 | * Convenience method that inserts an individual records into the JobParameters table.
|
| 375 | + * @throws SQLException if the driver throws an exception |
368 | 376 | */
|
369 |
| - private <T> void insertParameter(Long executionId, Class<T> type, String key, T value, boolean identifying) { |
370 |
| - |
371 |
| - Object[] args = new Object[0]; |
372 |
| - int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.CHAR }; |
| 377 | + private <T> void insertParameter(PreparedStatement preparedStatement, Long executionId, Class<T> type, String key, |
| 378 | + T value, boolean identifying) throws SQLException { |
373 | 379 |
|
374 | 380 | String identifyingFlag = identifying ? "Y" : "N";
|
375 | 381 |
|
376 | 382 | String stringValue = this.conversionService.convert(value, String.class);
|
377 |
| - args = new Object[] { executionId, key, type.getName(), stringValue, identifyingFlag }; |
378 | 383 |
|
379 |
| - getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); |
| 384 | + preparedStatement.setLong(1, executionId); |
| 385 | + preparedStatement.setString(2, key); |
| 386 | + preparedStatement.setString(3, type.getName()); |
| 387 | + preparedStatement.setString(4, stringValue); |
| 388 | + preparedStatement.setString(5, identifyingFlag); |
380 | 389 | }
|
381 | 390 |
|
382 | 391 | /**
|
|
0 commit comments