IN PROGRESS - BATCH-709: Change all collections to use generics
This commit is contained in:
@@ -4,7 +4,6 @@ import java.io.Serializable;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.SerializationUtils;
|
||||
@@ -114,8 +113,8 @@ class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao {
|
||||
*/
|
||||
private void saveOrUpdateExecutionContext(ExecutionContext ctx, Long executionId, String discriminator) {
|
||||
|
||||
for (Iterator it = ctx.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
for (Entry<String, Object> entry : ctx.entrySet()) {
|
||||
|
||||
final String key = entry.getKey().toString();
|
||||
final Object value = entry.getValue();
|
||||
|
||||
|
||||
@@ -72,7 +72,8 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
this.exitMessageLength = exitMessageLength;
|
||||
}
|
||||
|
||||
public List findJobExecutions(final JobInstance job) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<JobExecution> findJobExecutions(final JobInstance job) {
|
||||
|
||||
Assert.notNull(job, "Job cannot be null.");
|
||||
Assert.notNull(job.getId(), "Job Id cannot be null.");
|
||||
@@ -229,11 +230,12 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public JobExecution getLastJobExecution(JobInstance jobInstance) {
|
||||
|
||||
Long id = jobInstance.getId();
|
||||
|
||||
List executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), new Object[] { id, id },
|
||||
List<JobExecution> executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), new Object[] { id, id },
|
||||
new JobExecutionRowMapper(jobInstance));
|
||||
|
||||
Assert.state(executions.size() <= 1, "There must be at most one latest job execution");
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.Iterator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@@ -41,8 +41,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
|
||||
private static final String FIND_JOBS_WITH_KEY = "SELECT JOB_INSTANCE_ID from %PREFIX%JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?";
|
||||
|
||||
private static final String FIND_JOBS_WITH_EMPTY_KEY =
|
||||
"SELECT JOB_INSTANCE_ID from %PREFIX%JOB_INSTANCE where JOB_NAME = ? and (JOB_KEY = ? OR JOB_KEY is NULL)";
|
||||
private static final String FIND_JOBS_WITH_EMPTY_KEY = "SELECT JOB_INSTANCE_ID from %PREFIX%JOB_INSTANCE where JOB_NAME = ? and (JOB_KEY = ? OR JOB_KEY is NULL)";
|
||||
|
||||
private DataFieldMaxValueIncrementer jobIncrementer;
|
||||
|
||||
@@ -62,13 +61,14 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
Assert.notNull(jobParameters, "JobParameters must not be null.");
|
||||
|
||||
Assert.state(getJobInstance(job, jobParameters) == null, "JobInstance must not already exist");
|
||||
|
||||
|
||||
Long jobId = new Long(jobIncrementer.nextLongValue());
|
||||
|
||||
|
||||
JobInstance jobInstance = new JobInstance(jobId, jobParameters, job.getName());
|
||||
jobInstance.incrementVersion();
|
||||
|
||||
Object[] parameters = new Object[] { jobId, job.getName(), createJobKey(jobParameters), jobInstance.getVersion() };
|
||||
|
||||
Object[] parameters = new Object[] { jobId, job.getName(), createJobKey(jobParameters),
|
||||
jobInstance.getVersion() };
|
||||
getJdbcTemplate().update(getQuery(CREATE_JOB_INSTANCE), parameters,
|
||||
new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER });
|
||||
|
||||
@@ -79,10 +79,9 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
|
||||
private String createJobKey(JobParameters jobParameters) {
|
||||
|
||||
Map props = jobParameters.getParameters();
|
||||
Map<String, Object> props = jobParameters.getParameters();
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
for (Entry<String, Object> entry : props.entrySet()) {
|
||||
stringBuffer.append(entry.toString() + ";");
|
||||
}
|
||||
|
||||
@@ -96,41 +95,22 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
*/
|
||||
private void insertJobParameters(Long jobId, JobParameters jobParameters) {
|
||||
|
||||
Map parameters = jobParameters.getStringParameters();
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
for (Iterator it = parameters.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
insertParameter(jobId, ParameterType.STRING, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
for (Entry<String, String> entry : jobParameters.getStringParameters().entrySet()) {
|
||||
insertParameter(jobId, ParameterType.STRING, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
|
||||
parameters = jobParameters.getLongParameters();
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
for (Iterator it = parameters.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
insertParameter(jobId, ParameterType.LONG, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
parameters = jobParameters.getDoubleParameters();
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
for (Iterator it = parameters.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
insertParameter(jobId, ParameterType.DOUBLE, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
for (Entry<String, Long> entry : jobParameters.getLongParameters().entrySet()) {
|
||||
insertParameter(jobId, ParameterType.LONG, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
|
||||
parameters = jobParameters.getDateParameters();
|
||||
|
||||
if (!parameters.isEmpty()) {
|
||||
for (Iterator it = parameters.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
insertParameter(jobId, ParameterType.DATE, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
for (Entry<String, Double> entry : jobParameters.getDoubleParameters().entrySet()) {
|
||||
insertParameter(jobId, ParameterType.DOUBLE, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
|
||||
for (Entry<String, Date> entry : jobParameters.getDateParameters().entrySet()) {
|
||||
insertParameter(jobId, ParameterType.DATE, entry.getKey().toString(), entry.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,6 +147,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
* @throws IllegalArgumentException if any {@link JobParameters} fields are
|
||||
* null.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public JobInstance getJobInstance(final Job job, final JobParameters jobParameters) {
|
||||
|
||||
Assert.notNull(job, "Job must not be null.");
|
||||
@@ -183,20 +164,21 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
return jobInstance;
|
||||
}
|
||||
};
|
||||
|
||||
List instances;
|
||||
|
||||
List<JobInstance> instances;
|
||||
if (StringUtils.hasLength(jobKey)) {
|
||||
instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_KEY), parameters, rowMapper);
|
||||
}
|
||||
else {
|
||||
instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_EMPTY_KEY), parameters, rowMapper);
|
||||
}
|
||||
|
||||
|
||||
if (instances.isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Assert.state(instances.size() == 1);
|
||||
return (JobInstance) instances.get(0);
|
||||
return instances.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +214,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements
|
||||
public static final ParameterType DATE = new ParameterType("DATE");
|
||||
|
||||
public static final ParameterType LONG = new ParameterType("LONG");
|
||||
|
||||
|
||||
public static final ParameterType DOUBLE = new ParameterType("DOUBLE");
|
||||
|
||||
private static final ParameterType[] VALUES = { STRING, DATE, LONG, DOUBLE };
|
||||
|
||||
@@ -251,8 +251,9 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
||||
ecDao.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
|
||||
List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
|
||||
List<StepExecution> executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION),
|
||||
new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution, step));
|
||||
|
||||
Assert.state(executions.size() <= 1,
|
||||
|
||||
@@ -46,7 +46,7 @@ public interface JobExecutionDao {
|
||||
* @param jobInstance
|
||||
* @return list of jobExecutions.
|
||||
*/
|
||||
List findJobExecutions(JobInstance jobInstance);
|
||||
List<JobExecution> findJobExecutions(JobInstance jobInstance);
|
||||
|
||||
/**
|
||||
* @return last JobExecution for given JobInstance.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -15,11 +14,15 @@ import org.springframework.util.Assert;
|
||||
* In-memory implementation of {@link JobExecutionDao}.
|
||||
*
|
||||
*/
|
||||
|
||||
public class MapJobExecutionDao implements JobExecutionDao {
|
||||
|
||||
private static Map executionsById = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Long, JobExecution> executionsById = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
|
||||
private static Map contextsByJobExecutionId = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Long, ExecutionContext> contextsByJobExecutionId = TransactionAwareProxyFactory
|
||||
.createTransactionalMap();
|
||||
|
||||
private static long currentId = 0;
|
||||
|
||||
@@ -30,9 +33,8 @@ public class MapJobExecutionDao implements JobExecutionDao {
|
||||
|
||||
public int getJobExecutionCount(JobInstance jobInstance) {
|
||||
int count = 0;
|
||||
for (Iterator iterator = executionsById.values().iterator(); iterator.hasNext();) {
|
||||
JobExecution exec = (JobExecution) iterator.next();
|
||||
if (exec.getJobInstance().equals(jobInstance)) {
|
||||
for (JobExecution execution : executionsById.values()) {
|
||||
if (execution.getJobInstance().equals(jobInstance)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
@@ -47,10 +49,9 @@ public class MapJobExecutionDao implements JobExecutionDao {
|
||||
executionsById.put(newId, jobExecution);
|
||||
}
|
||||
|
||||
public List findJobExecutions(JobInstance jobInstance) {
|
||||
List executions = new ArrayList();
|
||||
for (Iterator iterator = executionsById.values().iterator(); iterator.hasNext();) {
|
||||
JobExecution exec = (JobExecution) iterator.next();
|
||||
public List<JobExecution> findJobExecutions(JobInstance jobInstance) {
|
||||
List<JobExecution> executions = new ArrayList<JobExecution>();
|
||||
for (JobExecution exec : executionsById.values()) {
|
||||
if (exec.getJobInstance().equals(jobInstance)) {
|
||||
executions.add(exec);
|
||||
}
|
||||
@@ -68,8 +69,7 @@ public class MapJobExecutionDao implements JobExecutionDao {
|
||||
|
||||
public JobExecution getLastJobExecution(JobInstance jobInstance) {
|
||||
JobExecution lastExec = null;
|
||||
for (Iterator iterator = executionsById.values().iterator(); iterator.hasNext();) {
|
||||
JobExecution exec = (JobExecution) iterator.next();
|
||||
for (JobExecution exec : executionsById.values()) {
|
||||
if (!exec.getJobInstance().equals(jobInstance)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.springframework.batch.core.repository.dao;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
@@ -14,7 +13,8 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MapJobInstanceDao implements JobInstanceDao {
|
||||
|
||||
private static Collection jobInstances = TransactionAwareProxyFactory.createTransactionalList();
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Collection<JobInstance> jobInstances = TransactionAwareProxyFactory.createTransactionalList();
|
||||
|
||||
private long currentId = 0;
|
||||
|
||||
@@ -23,26 +23,25 @@ public class MapJobInstanceDao implements JobInstanceDao {
|
||||
}
|
||||
|
||||
public JobInstance createJobInstance(Job job, JobParameters jobParameters) {
|
||||
|
||||
|
||||
Assert.state(getJobInstance(job, jobParameters) == null, "JobInstance must not already exist");
|
||||
|
||||
|
||||
JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters, job.getName());
|
||||
jobInstance.incrementVersion();
|
||||
jobInstances.add(jobInstance);
|
||||
|
||||
|
||||
return jobInstance;
|
||||
}
|
||||
|
||||
public JobInstance getJobInstance(Job job, JobParameters jobParameters) {
|
||||
|
||||
for (Iterator iterator = jobInstances.iterator(); iterator.hasNext();) {
|
||||
JobInstance instance = (JobInstance) iterator.next();
|
||||
|
||||
for (JobInstance instance : jobInstances) {
|
||||
if (instance.getJobName().equals(job.getName()) && instance.getJobParameters().equals(jobParameters)) {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,17 +31,16 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MapStepExecutionDao implements StepExecutionDao {
|
||||
|
||||
private static Map executionsByJobExecutionId;
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Long, Map<String, StepExecution>> executionsByJobExecutionId = TransactionAwareProxyFactory
|
||||
.createTransactionalMap();
|
||||
|
||||
private static Map contextsByStepExecutionId;
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<Long, ExecutionContext> contextsByStepExecutionId = TransactionAwareProxyFactory
|
||||
.createTransactionalMap();
|
||||
|
||||
private static long currentId = 0;
|
||||
|
||||
static {
|
||||
executionsByJobExecutionId = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
contextsByStepExecutionId = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
executionsByJobExecutionId.clear();
|
||||
contextsByStepExecutionId.clear();
|
||||
@@ -51,12 +50,13 @@ public class MapStepExecutionDao implements StepExecutionDao {
|
||||
return (ExecutionContext) contextsByStepExecutionId.get(stepExecution.getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void saveStepExecution(StepExecution stepExecution) {
|
||||
Assert.isTrue(stepExecution.getId() == null);
|
||||
Assert.isTrue(stepExecution.getVersion() == null);
|
||||
Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already.");
|
||||
|
||||
Map executions = (Map) executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
Map<String, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
if (executions == null) {
|
||||
executions = TransactionAwareProxyFactory.createTransactionalMap();
|
||||
executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions);
|
||||
@@ -70,7 +70,7 @@ public class MapStepExecutionDao implements StepExecutionDao {
|
||||
|
||||
Assert.notNull(stepExecution.getJobExecutionId());
|
||||
|
||||
Map executions = (Map) executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
Map<String, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId());
|
||||
Assert.notNull(executions, "step executions for given job execution are expected to be already saved");
|
||||
|
||||
StepExecution persistedExecution = (StepExecution) executions.get(stepExecution.getStepName());
|
||||
@@ -89,7 +89,7 @@ public class MapStepExecutionDao implements StepExecutionDao {
|
||||
}
|
||||
|
||||
public StepExecution getStepExecution(JobExecution jobExecution, Step step) {
|
||||
Map executions = (Map) executionsByJobExecutionId.get(jobExecution.getId());
|
||||
Map<String, StepExecution> executions = executionsByJobExecutionId.get(jobExecution.getId());
|
||||
if (executions == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user