|
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; |
|
70 | 71 | * @author Michael Minella |
71 | 72 | * @author Mahmoud Ben Hassine |
72 | 73 | * @author Dimitrios Liapis |
| 74 | + * @author Philippe Marschall |
73 | 75 | */ |
74 | 76 | public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean { |
75 | 77 |
|
@@ -376,27 +378,34 @@ public void deleteJobExecutionParameters(JobExecution jobExecution) { |
376 | 378 | */ |
377 | 379 | private void insertJobParameters(Long executionId, JobParameters jobParameters) { |
378 | 380 |
|
379 | | - for (Entry<String, JobParameter<?>> entry : jobParameters.getParameters().entrySet()) { |
380 | | - JobParameter jobParameter = entry.getValue(); |
381 | | - insertParameter(executionId, jobParameter.getType(), entry.getKey(), jobParameter.getValue(), |
382 | | - jobParameter.isIdentifying()); |
| 381 | + if (jobParameters.isEmpty()) { |
| 382 | + return; |
383 | 383 | } |
| 384 | + |
| 385 | + getJdbcTemplate().batchUpdate(getQuery(CREATE_JOB_PARAMETERS), jobParameters.getParameters().entrySet(), 100, |
| 386 | + (ps, entry) -> { |
| 387 | + JobParameter jobParameter = entry.getValue(); |
| 388 | + insertParameter(ps, executionId, jobParameter.getType(), entry.getKey(), jobParameter.getValue(), |
| 389 | + jobParameter.isIdentifying()); |
| 390 | + }); |
384 | 391 | } |
385 | 392 |
|
386 | 393 | /** |
387 | 394 | * Convenience method that inserts an individual records into the JobParameters table. |
| 395 | + * @throws SQLException if the driver throws an exception |
388 | 396 | */ |
389 | | - private <T> void insertParameter(Long executionId, Class<T> type, String key, T value, boolean identifying) { |
390 | | - |
391 | | - Object[] args = new Object[0]; |
392 | | - int[] argTypes = new int[] { Types.BIGINT, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.CHAR }; |
| 397 | + private <T> void insertParameter(PreparedStatement preparedStatement, Long executionId, Class<T> type, String key, |
| 398 | + T value, boolean identifying) throws SQLException { |
393 | 399 |
|
394 | 400 | String identifyingFlag = identifying ? "Y" : "N"; |
395 | 401 |
|
396 | 402 | String stringValue = this.conversionService.convert(value, String.class); |
397 | | - args = new Object[] { executionId, key, type.getName(), stringValue, identifyingFlag }; |
398 | 403 |
|
399 | | - getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); |
| 404 | + preparedStatement.setLong(1, executionId); |
| 405 | + preparedStatement.setString(2, key); |
| 406 | + preparedStatement.setString(3, type.getName()); |
| 407 | + preparedStatement.setString(4, stringValue); |
| 408 | + preparedStatement.setString(5, identifyingFlag); |
400 | 409 | } |
401 | 410 |
|
402 | 411 | /** |
|
0 commit comments