From 94fa4834411362fa3dd4d1300ee634eb557b450a Mon Sep 17 00:00:00 2001 From: robokaso Date: Wed, 16 Jul 2008 09:32:37 +0000 Subject: [PATCH] IN PROGRESS - BATCH-709: Change all collections to use generics --- .../AbstractJobRepositoryFactoryBean.java | 1 + .../support/SimpleJobRepository.java | 33 ++++++++---------- .../StepExecutionPreparedStatementSetter.java | 34 ++++++++++--------- .../resource/StepExecutionResourceProxy.java | 4 +-- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java index 75d9e1be9..4dfc6ee28 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/AbstractJobRepositoryFactoryBean.java @@ -64,6 +64,7 @@ public abstract class AbstractJobRepositoryFactoryBean implements FactoryBean, I * @return JobRepository.class * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ + @SuppressWarnings("unchecked") public Class getObjectType() { return JobRepository.class; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index a9ad50d6c..9163f39d3 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -17,7 +17,6 @@ package org.springframework.batch.core.repository.support; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.springframework.batch.core.BatchStatus; @@ -106,8 +105,7 @@ public class SimpleJobRepository implements JobRepository { *
    *
  1. First we find all jobs which match the given {@link JobParameters} * and job name
  2. - *
  3. What happens then depends on how many existing job instances we - * find: + *
  4. What happens then depends on how many existing job instances we find: *
      *
    • If there are none, or the {@link Job} is marked restartable, then we * create a new {@link JobInstance}
    • @@ -161,11 +159,10 @@ public class SimpleJobRepository implements JobRepository { throw new JobRestartException("JobInstance already exists and is not restartable"); } - List executions = jobExecutionDao.findJobExecutions(jobInstance); + List executions = jobExecutionDao.findJobExecutions(jobInstance); // check for running executions and find the last started - for (Iterator iterator = executions.iterator(); iterator.hasNext();) { - JobExecution execution = (JobExecution) iterator.next(); + for (JobExecution execution : executions) { if (execution.isRunning()) { throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: " + jobInstance); @@ -199,8 +196,8 @@ public class SimpleJobRepository implements JobRepository { * Save or Update a JobExecution. A JobExecution is considered one * 'execution' of a particular job. Therefore, it must have it's jobId field * set before it is passed into this method. It also has it's own unique - * identifier, because it must be updatable separately. If an id isn't found, - * a new JobExecution is created, if one is found, the current row is + * identifier, because it must be updatable separately. If an id isn't + * found, a new JobExecution is created, if one is found, the current row is * updated. * * @param jobExecution to be stored. @@ -247,7 +244,10 @@ public class SimpleJobRepository implements JobRepository { /* * (non-Javadoc) - * @see org.springframework.batch.core.repository.JobRepository#saveOrUpdateExecutionContext(org.springframework.batch.core.domain.StepExecution) + * + * @seeorg.springframework.batch.core.repository.JobRepository# + * saveOrUpdateExecutionContext + * (org.springframework.batch.core.domain.StepExecution) */ public void saveOrUpdateExecutionContext(StepExecution stepExecution) { // Until there is an interface change ( @@ -259,18 +259,16 @@ public class SimpleJobRepository implements JobRepository { * @return the last execution of the step within given job instance */ public StepExecution getLastStepExecution(JobInstance jobInstance, Step step) { - List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); - List stepExecutions = new ArrayList(jobExecutions.size()); - for (Iterator iterator = jobExecutions.iterator(); iterator.hasNext();) { - JobExecution jobExecution = (JobExecution) iterator.next(); + List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); + List stepExecutions = new ArrayList(jobExecutions.size()); + for (JobExecution jobExecution : jobExecutions) { StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, step); if (stepExecution != null) { stepExecutions.add(stepExecution); } } StepExecution latest = null; - for (Iterator iterator = stepExecutions.iterator(); iterator.hasNext();) { - StepExecution stepExecution = (StepExecution) iterator.next(); + for (StepExecution stepExecution : stepExecutions) { if (latest == null) { latest = stepExecution; } @@ -286,9 +284,8 @@ public class SimpleJobRepository implements JobRepository { */ public int getStepExecutionCount(JobInstance jobInstance, Step step) { int count = 0; - List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); - for (Iterator iterator = jobExecutions.iterator(); iterator.hasNext();) { - JobExecution jobExecution = (JobExecution) iterator.next(); + List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); + for (JobExecution jobExecution : jobExecutions) { if (stepExecutionDao.getStepExecution(jobExecution, step) != null) { count++; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionPreparedStatementSetter.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionPreparedStatementSetter.java index eb7476977..03587e0b4 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionPreparedStatementSetter.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionPreparedStatementSetter.java @@ -31,40 +31,42 @@ import org.springframework.jdbc.core.StatementCreatorUtils; import org.springframework.util.Assert; /** - * Implementation of the {@link PreparedStatementSetter} interface that also implements - * {@link StepExecutionListener} and uses {@link JobParameters} to set the parameters on a - * PreparedStatement. + * Implementation of the {@link PreparedStatementSetter} interface that also + * implements {@link StepExecutionListener} and uses {@link JobParameters} to + * set the parameters on a PreparedStatement. * * @author Lucas Ward - * + * */ public class StepExecutionPreparedStatementSetter extends StepExecutionListenerSupport implements PreparedStatementSetter, InitializingBean { - private List parameterKeys; + private List parameterKeys; + private JobParameters jobParameters; - + public void setValues(PreparedStatement ps) throws SQLException { - Map parameters = jobParameters.getParameters(); - for(int i = 0; i < parameterKeys.size(); i++){ + Map parameters = jobParameters.getParameters(); + for (int i = 0; i < parameterKeys.size(); i++) { Object arg = parameters.get(parameterKeys.get(i)); - if(arg == null){ - throw new IllegalStateException("No job parameter found for with key of: [" + parameterKeys.get(i) + "]"); + if (arg == null) { + throw new IllegalStateException("No job parameter found for with key of: [" + parameterKeys.get(i) + + "]"); } StatementCreatorUtils.setParameterValue(ps, i + 1, SqlTypeValue.TYPE_UNKNOWN, arg); } } - + public void beforeStep(StepExecution stepExecution) { this.jobParameters = stepExecution.getJobParameters(); } - + /** - * The parameter names that will be pulled from the {@link JobParameters}. It is - * assumed that their order in the List is the order of the parameters in the - * PreparedStatement. + * The parameter names that will be pulled from the {@link JobParameters}. + * It is assumed that their order in the List is the order of the parameters + * in the PreparedStatement. */ - public void setParameterKeys(List parameterKeys) { + public void setParameterKeys(List parameterKeys) { this.parameterKeys = parameterKeys; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java index 7e58f0d41..ed083fcf2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/resource/StepExecutionResourceProxy.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URL; -import java.util.Iterator; import java.util.Properties; import java.util.Map.Entry; @@ -259,8 +258,7 @@ public class StepExecutionResourceProxy extends StepExecutionListenerSupport imp fileName = replacePattern(fileName, STEP_NAME_PATTERN, stepName); if (properties != null) { - for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) { - Entry entry = (Entry) iterator.next(); + for (Entry entry : properties.entrySet()) { String key = (String) entry.getKey(); fileName = replacePattern(fileName, "%" + key + "%", (String) entry.getValue()); }