Remove duplicate job name (causing failures in test suite)

This commit is contained in:
dsyer
2008-01-23 12:23:27 +00:00
parent d67a4b4caf
commit 8833158f0d
10 changed files with 113 additions and 121 deletions

View File

@@ -58,6 +58,13 @@ public class SimpleJobRepository implements JobRepository {
private StepDao stepDao;
/**
* Provide default constructor with low visibility in case user wants to use
* use aop:proxy-target-class="true" for transaction interceptor.
*/
SimpleJobRepository() {
}
public SimpleJobRepository(JobDao jobDao, StepDao stepDao) {
super();
this.jobDao = jobDao;
@@ -67,19 +74,18 @@ public class SimpleJobRepository implements JobRepository {
/**
* <p>
* Create a (@link {@link JobExecution}) based on the passed in
* {@link JobIdentifier} and {@link Job}. However, unique
* identification of a job can only come from the database, and therefore
* must come from JobDao by either creating a new job or finding an existing
* one, which will ensure that the id of the job is populated with the
* correct value.
* {@link JobIdentifier} and {@link Job}. However, unique identification of
* a job can only come from the database, and therefore must come from
* JobDao by either creating a new job or finding an existing one, which
* will ensure that the id of the job is populated with the correct value.
* </p>
*
* <p>
* There are two ways in which the method determines if a job should be
* created or an existing one should be returned. The first is
* restartability. The {@link Job} restartable property will be
* checked first. If it is not false, a new job will be created, regardless
* of whether or not one exists. If it is true, the {@link JobDao} will be
* restartability. The {@link Job} restartable property will be checked
* first. If it is not false, a new job will be created, regardless of
* whether or not one exists. If it is true, the {@link JobDao} will be
* checked to determine if the job already exists, if it does, it's steps
* will be populated (there must be at least 1) and a new
* {@link JobExecution} will be returned. If no job is found, a new one will
@@ -95,11 +101,11 @@ public class SimpleJobRepository implements JobRepository {
* <li>What happens then depends on how many existing job instances we
* find:
* <ul>
* <li>If there are none, or the {@link Job} is marked
* restartable, then we create a new {@link JobInstance}</li>
* <li>If there is more than one and the {@link Job} is not
* marked as restartable, it is an error. This could be caused by a job
* whose restartable flag has changed to be more strict (true not false)
* <li>If there are none, or the {@link Job} is marked restartable, then we
* create a new {@link JobInstance}</li>
* <li>If there is more than one and the {@link Job} is not marked as
* restartable, it is an error. This could be caused by a job whose
* restartable flag has changed to be more strict (true not false)
* <em>after</em> it has been executed at least once.</li>
* <li>If there is precisely one existing {@link JobInstance} then we check
* the {@link JobExecution} instances for that job, and if any of them tells
@@ -121,22 +127,18 @@ public class SimpleJobRepository implements JobRepository {
*
* @see JobRepository#createJobExecution(Job, JobInstanceProperties)
*
* @throws BatchRestartException
* if more than one JobInstance if found or if
* JobInstance.getJobExecutionCount() is greater than
* Job.getStartLimit()
* @throws JobExecutionAlreadyRunningException
* if a job execution is found for the given
* {@link JobIdentifier} that is already running
* @throws BatchRestartException if more than one JobInstance if found or if
* JobInstance.getJobExecutionCount() is greater than Job.getStartLimit()
* @throws JobExecutionAlreadyRunningException if a job execution is found
* for the given {@link JobIdentifier} that is already running
*
*/
public JobExecution createJobExecution(Job job,
JobInstanceProperties jobInstanceProperties)
public JobExecution createJobExecution(Job job, JobInstanceProperties jobInstanceProperties)
throws JobExecutionAlreadyRunningException {
Assert.notNull(job, "Job must not be null.");
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
List jobs = new ArrayList();
JobInstance jobInstance;
@@ -158,30 +160,28 @@ public class SimpleJobRepository implements JobRepository {
if (jobs.size() == 1) {
// One job was found
jobInstance = (JobInstance) jobs.get(0);
jobInstance.setStepInstances(findStepInstances(job.getSteps(),
jobInstance));
jobInstance.setStepInstances(findStepInstances(job.getSteps(), jobInstance));
jobInstance.setJobExecutionCount(jobDao.getJobExecutionCount(jobInstance.getId()));
if (jobInstance.getJobExecutionCount() > job.getStartLimit()) {
throw new BatchRestartException(
"Restart Max exceeded for Job: " + jobInstance.toString());
throw new BatchRestartException("Restart Max exceeded for Job: " + jobInstance.toString());
}
List executions = jobDao.findJobExecutions(jobInstance);
for (Iterator iterator = executions.iterator(); iterator.hasNext();) {
JobExecution execution = (JobExecution) iterator.next();
if (execution.isRunning()) {
throw new JobExecutionAlreadyRunningException(
"A job execution for this job is already running: "
+ jobInstance);
throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: "
+ jobInstance);
}
}
} else if (jobs.size() == 0) {
}
else if (jobs.size() == 0) {
// no job found, create one
jobInstance = createJobInstance(job, jobInstanceProperties);
} else {
}
else {
// More than one job found, throw exception
throw new BatchRestartException(
"Error restarting job, more than one JobInstance found for: "
+ job.toString());
throw new BatchRestartException("Error restarting job, more than one JobInstance found for: "
+ job.toString());
}
return generateJobExecution(jobInstance);
@@ -204,21 +204,19 @@ public class SimpleJobRepository implements JobRepository {
* a new JobExecution is created, if one is found, the current row is
* updated.
*
* @param JobExecution
* to be stored.
* @throws IllegalArgumentException
* if jobExecution is null.
* @param JobExecution to be stored.
* @throws IllegalArgumentException if jobExecution is null.
*/
public void saveOrUpdate(JobExecution jobExecution) {
Assert.notNull(jobExecution, "JobExecution cannot be null.");
Assert.notNull(jobExecution.getJobId(),
"JobExecution must have a Job ID set.");
Assert.notNull(jobExecution.getJobId(), "JobExecution must have a Job ID set.");
if (jobExecution.getId() == null) {
// existing instance
jobDao.save(jobExecution);
} else {
}
else {
// new execution
jobDao.update(jobExecution);
}
@@ -229,19 +227,14 @@ public class SimpleJobRepository implements JobRepository {
* findOrCreateJob method, otherwise it is likely that the id is incorrect
* or non-existant.
*
* @param job
* to be updated.
* @throws IllegalArgumentException
* if Job or it's Id is null.
* @param job to be updated.
* @throws IllegalArgumentException if Job or it's Id is null.
*/
public void update(JobInstance job) {
Assert.notNull(job, "Job cannot be null.");
Assert
.notNull(
job.getId(),
"Job cannot be updated if it's ID is null. It must be obtained"
+ "from SimpleJobRepository.findOrCreateJob to be considered valid.");
Assert.notNull(job.getId(), "Job cannot be updated if it's ID is null. It must be obtained"
+ "from SimpleJobRepository.findOrCreateJob to be considered valid.");
jobDao.update(job);
}
@@ -252,21 +245,19 @@ public class SimpleJobRepository implements JobRepository {
* noted that assigning an ID randomly will likely cause an exception
* depending on the StepDao implementation.
*
* @param StepExecution
* to be saved.
* @throws IllegalArgumentException
* if stepExecution is null.
* @param StepExecution to be saved.
* @throws IllegalArgumentException if stepExecution is null.
*/
public void saveOrUpdate(StepExecution stepExecution) {
Assert.notNull(stepExecution, "StepExecution cannot be null.");
Assert.notNull(stepExecution.getStepId(),
"StepExecution's Step Id cannot be null.");
Assert.notNull(stepExecution.getStepId(), "StepExecution's Step Id cannot be null.");
if (stepExecution.getId() == null) {
// new execution, obtain id and insert
stepDao.save(stepExecution);
} else {
}
else {
// existing execution, update
stepDao.update(stepExecution);
}
@@ -275,17 +266,14 @@ public class SimpleJobRepository implements JobRepository {
/**
* Update the given step.
*
* @param StepInstance
* to be updated.
* @throws IllegalArgumentException
* if step or it's id is null.
* @param StepInstance to be updated.
* @throws IllegalArgumentException if step or it's id is null.
*/
public void update(StepInstance step) {
Assert.notNull(step, "Step cannot be null.");
Assert.notNull(step.getId(),
"Step cannot be updated if it's ID is null. It must be obtained"
+ "from SimpleJobRepository.findOrCreateJob to be considered valid.");
Assert.notNull(step.getId(), "Step cannot be updated if it's ID is null. It must be obtained"
+ "from SimpleJobRepository.findOrCreateJob to be considered valid.");
stepDao.update(step);
@@ -312,11 +300,9 @@ public class SimpleJobRepository implements JobRepository {
Iterator i = steps.iterator();
while (i.hasNext()) {
Step step = (Step) i.next();
StepInstance stepInstance = stepDao.createStep(job, step
.getName());
StepInstance stepInstance = stepDao.createStep(job, step.getName());
// Ensure valid restart data is being returned.
if (stepInstance.getRestartData() == null
|| stepInstance.getRestartData().getProperties() == null) {
if (stepInstance.getRestartData() == null || stepInstance.getRestartData().getProperties() == null) {
stepInstance.setRestartData(new GenericRestartData(new Properties()));
}
stepInstances.add(stepInstance);
@@ -334,18 +320,13 @@ public class SimpleJobRepository implements JobRepository {
while (i.hasNext()) {
Step stepConfiguration = (Step) i.next();
StepInstance step = stepDao.findStep(job, stepConfiguration
.getName());
StepInstance step = stepDao.findStep(job, stepConfiguration.getName());
if (step != null) {
step.setStepExecutionCount(stepDao.getStepExecutionCount(step
.getId()));
step.setStepExecutionCount(stepDao.getStepExecutionCount(step.getId()));
// Ensure valid restart data is being returned.
if (step.getRestartData() == null
|| step.getRestartData().getProperties() == null) {
step
.setRestartData(new GenericRestartData(
new Properties()));
if (step.getRestartData() == null || step.getRestartData().getProperties() == null) {
step.setRestartData(new GenericRestartData(new Properties()));
}
stepInstances.add(step);
}

View File

@@ -44,6 +44,7 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
*/
public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implements Skippable, Restartable,
StatisticsProvider {
private static Log log = LogFactory.getLog(DefaultFlatFileItemReader.class);
public static final String READ_STATISTICS_NAME = "lines.read.count";

View File

@@ -18,6 +18,8 @@ package org.springframework.batch.io.file;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.io.exception.FlatFileParsingException;
import org.springframework.batch.io.file.mapping.DefaultFieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
@@ -55,6 +57,8 @@ import org.springframework.util.Assert;
public class SimpleFlatFileItemReader extends AbstractItemReader implements ItemReader,
InitializingBean, DisposableBean {
private static Log log = LogFactory.getLog(SimpleFlatFileItemReader.class);
// default encoding for input files - set to ISO-8859-1
public static final String DEFAULT_CHARSET = "ISO-8859-1";
@@ -136,6 +140,8 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
Assert.state(resource.exists(), "Resource must exist: [" + resource
+ "]");
log.debug("Opening flat file for reading: "+resource);
if (this.reader == null) {
ResourceLineReader reader = new ResourceLineReader(resource, encoding);
if (recordSeparatorPolicy != null) {
@@ -172,6 +178,7 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
public void close() {
try {
if (reader != null) {
log.debug("Closing flat file for reading: "+resource);
reader.close();
}
} finally {

View File

@@ -133,7 +133,6 @@ public class ResourceLineReader extends AbstractItemReader implements LineReader
if (line != null) {
while (line != null && !recordSeparatorPolicy.isEndOfRecord(record)) {
record = recordSeparatorPolicy.preProcess(record) + (line = readLine());
// record = new StringBuilder(recordSeparatorPolicy.preProcess(record)).append(line = readLine()).toString();
}
}
return recordSeparatorPolicy.postProcess(record);

View File

@@ -1,32 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>spring-batch-samples</name>
<comment>Example batch jobs using Spring Batch Core and Execution.</comment>
<projects>
<project>spring-batch-infrastructure</project>
<project>spring-batch-core</project>
<project>spring-batch-execution</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>spring-batch-samples</name>
<comment>Example batch jobs using Spring Batch Core and Execution.</comment>
<projects>
<project>spring-batch-infrastructure</project>
<project>spring-batch-core</project>
<project>spring-batch-execution</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.core.springbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
</natures>
</projectDescription>

View File

@@ -1,5 +0,0 @@
#Mon Dec 10 14:44:37 EST 2007
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.source=1.4
org.eclipse.jdt.core.compiler.compliance=1.4

View File

@@ -38,11 +38,15 @@ public class ProcessorLogAdvice {
Object[] args = pjp.getArgs();
StringBuffer output = new StringBuffer();
output.append(pjp.getTarget().getClass().getName()+": ");
output.append(pjp.toShortString()+": ");
for(int i = 0; i < args.length; i++){
output.append(args[i] + " ");
}
log.info("Processed: " + output.toString());
log.info("Basic: " + output.toString());
}
public void doStronglyTypedLogging(Object item){

View File

@@ -12,7 +12,7 @@
<bean parent="stepScope" />
<bean parent="jobConfigurationRegistryBeanPostProcessor" />
<bean id="fixedLengthImportJob" parent="simpleJob">
<bean id="parallelJob" parent="simpleJob">
<property name="steps">
<list>
<bean id="staging" parent="simpleStep">

View File

@@ -29,5 +29,6 @@ log4j.logger.org.springframework.batch.sample=info
#log4j.logger.org.springframework.orm=debug
### debug your specific package or classes with the following example
log4j.logger.org.springframework.batch.io=debug
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
log4j.logger.org.springframework.batch.container.common.module.process.support.DefaultXmlDataProvider=debug

View File

@@ -5,9 +5,9 @@
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<import resource="data-source-context.xml" />
@@ -160,6 +160,10 @@
pointcut="execution( * org.springframework.batch.item.ItemProcessor+.process(Object)) and args(item)"
method="doStronglyTypedLogging" />
<aop:before
pointcut="execution( * org.springframework.batch..*ItemReader.*(..))"
method="doBasicLogging" />
</aop:aspect>
</aop:config>