BATCH-392:removed saveExecutionContext from step (it's handled at a lower level now)

This commit is contained in:
lucasward
2008-02-27 03:27:39 +00:00
parent 1527494b58
commit 6eb8883139
38 changed files with 691 additions and 76 deletions

View File

@@ -20,7 +20,6 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.repository.JobLocator;
@@ -81,7 +80,7 @@ import org.springframework.util.StringUtils;
*
* <p>
* <ul>
* <li>jobPath: the xml application context containing a {@link JobSupport}
* <li>jobPath: the xml application context containing a {@link Job}
* <li>jobName: the bean id of the job.
* <li>jobLauncherPath: the xml application context containing a
* {@link JobLauncher}
@@ -107,7 +106,7 @@ import org.springframework.util.StringUtils;
* none is contained in the bean factory (it searches by type) then a
* {@link BeanDefinitionStoreException} will be thrown. The same exception will also
* be thrown if there is more than one present. Assuming the JobLauncher has been
* set correctly, the jobName argument will be used to obtain an actual {@link JobSupport}.
* set correctly, the jobName argument will be used to obtain an actual {@link Job}.
* If a {@link JobLocator} has been set, then it will be used, if not the beanFactory
* will be asked, using the jobName as the bean id.</p>
*
@@ -231,7 +230,7 @@ public class CommandLineJobRunner {
* <p>
* <ul>
* <li>jobPath: the xml application context containing a
* {@link JobSupport}
* {@link Job}
* <li>jobName: the bean id of the job.
* <li>jobLauncherPath: the xml application context containing a
* {@link JobLauncher}

View File

@@ -20,7 +20,6 @@ import java.util.HashSet;
import java.util.Iterator;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.JobLocator;
import org.springframework.batch.core.repository.JobRegistry;
@@ -32,7 +31,7 @@ import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.Assert;
/**
* A {@link BeanPostProcessor} that registers {@link JobSupport} beans
* A {@link BeanPostProcessor} that registers {@link Job} beans
* with a {@link JobRegistry}. Include a bean of this type along
* with your job configuration, and use the same
* {@link JobRegistry} as a {@link JobLocator} when
@@ -67,7 +66,7 @@ public class JobRegistryBeanPostProcessor implements BeanPostProcessor, Initiali
}
/**
* De-register all the {@link JobSupport} instances that were
* De-register all the {@link Job} instances that were
* regsistered by this post processor.
* @see org.springframework.beans.factory.DisposableBean#destroy()
*/
@@ -80,7 +79,7 @@ public class JobRegistryBeanPostProcessor implements BeanPostProcessor, Initiali
}
/**
* If the bean is an instance of {@link JobSupport} then register it.
* If the bean is an instance of {@link Job} then register it.
* @throws FatalBeanException if there is a
* {@link DuplicateJobException}.
*

View File

@@ -0,0 +1,139 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.execution.job;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.util.ClassUtils;
/**
* Batch domain object representing a job. Job is an explicit abstraction
* representing the configuration of a job specified by a developer. It should
* be noted that restart policy is applied to the job as a whole and not to a
* step.
*
* @author Lucas Ward
* @author Dave Syer
*/
public abstract class AbstractJob implements BeanNameAware, Job {
private List steps = new ArrayList();
private String name;
private boolean restartable = false;
private int startLimit = Integer.MAX_VALUE;
/**
* Default constructor.
*/
public AbstractJob() {
super();
}
/**
* Convenience constructor to immediately add name (which is mandatory but
* not final).
*
* @param name
*/
public AbstractJob(String name) {
super();
this.name = name;
}
/**
* Set the name property if it is not already set. Because of the order of
* the callbacks in a Spring container the name property will be set first
* if it is present. Care is needed with bean definition inheritance - if a
* parent bean has a name, then its children need an explicit name as well,
* otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name == null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object
* is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getName()
*/
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getSteps()
*/
public List getSteps() {
return steps;
}
public void setSteps(List steps) {
this.steps.clear();
this.steps.addAll(steps);
}
public void addStep(Step step) {
this.steps.add(step);
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getStartLimit()
*/
public int getStartLimit() {
return startLimit;
}
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public void setRestartable(boolean restartable) {
this.restartable = restartable;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#isRestartable()
*/
public boolean isRestartable() {
return restartable;
}
public String toString() {
return ClassUtils.getShortName(getClass()) + ": [name=" + name + "]";
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.execution.job.simple;
package org.springframework.batch.execution.job;
import java.util.Date;
import java.util.Iterator;
@@ -25,7 +25,6 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
@@ -42,7 +41,7 @@ import org.springframework.batch.repeat.ExitStatus;
* @author Lucas Ward
* @author Dave Syer
*/
public class SimpleJob extends JobSupport {
public class SimpleJob extends AbstractJob {
private JobRepository jobRepository;

View File

@@ -1,7 +0,0 @@
<html>
<body>
<p>
Specific implementations of simple job concerns.
</p>
</body>
</html>

View File

@@ -16,7 +16,6 @@
package org.springframework.batch.execution.launch;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
@@ -36,7 +35,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
public interface JobLauncher {
/**
* Start a job execution for the given {@link JobSupport} and {@link JobParameters}.
* Start a job execution for the given {@link Job} and {@link JobParameters}.
*
* @return the exit code from the job if it returns synchronously. If the
* implementation is asynchronous, the status might well be unknown.

View File

@@ -21,7 +21,6 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.beans.factory.InitializingBean;
@@ -31,7 +30,7 @@ import org.springframework.util.Assert;
/**
* Simple implementation of the {@link JobLauncher} interface. The Spring Core
* {@link TaskExecutor} interface is used to launch a {@link JobSupport}. This
* {@link TaskExecutor} interface is used to launch a {@link Job}. This
* means that the type of executor set is very important. If a
* {@link SyncTaskExecutor} is used, then the job will be processed
* <strong>within the same thread that called the launcher.</strong> Care
@@ -42,7 +41,7 @@ import org.springframework.util.Assert;
* There is only one required dependency of this Launcher, a
* {@link JobRepository}. The JobRepository is used to obtain a valid
* JobExecution. The Repository must be used because the provided
* {@link JobSupport} could be a restart of an existing {@link JobInstance},
* {@link Job} could be a restart of an existing {@link JobInstance},
* and only the Repository can reliably recreate it.
*
* @author Lucas Ward

View File

@@ -24,7 +24,6 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.BatchRestartException;
@@ -88,7 +87,7 @@ public class SimpleJobRepository implements JobRepository {
* <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 JobSupport} restartable property will be
* restartability. The {@link Job} restartable property will be
* checked first. If it is false, a new job will be created, regardless of
* whether or not one exists. If it is true, the {@link JobInstanceDao} will
* be checked to determine if the job already exists, if it does, it's steps
@@ -107,7 +106,7 @@ 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 JobSupport} is marked restartable,
* <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 JobSupport} is not marked
* as restartable, it is an error. This could be caused by a job whose
@@ -131,7 +130,7 @@ public class SimpleJobRepository implements JobRepository {
* or if the platform does not support the higher isolation levels).
* </p>
*
* @see JobRepository#createJobExecution(JobSupport, JobParameters)
* @see JobRepository#createJobExecution(Job, JobParameters)
*
* @throws BatchRestartException if more than one JobInstance if found or if
* JobInstance.getJobExecutionCount() is greater than Job.getStartLimit()

View File

@@ -20,7 +20,6 @@ import org.springframework.batch.core.domain.ItemSkipPolicy;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.execution.step.support.DefaultItemFailureHandler;
import org.springframework.batch.execution.step.support.NeverSkipItemSkipPolicy;
@@ -30,6 +29,7 @@ import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.stream.StreamManager;
import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
import org.springframework.batch.retry.RetryPolicy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.Assert;
@@ -40,7 +40,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
* @author Ben Hale
*/
public abstract class AbstractStep extends StepSupport implements InitializingBean {
public abstract class AbstractStep implements Step, InitializingBean, BeanNameAware {
protected ExceptionHandler exceptionHandler;
@@ -59,6 +59,12 @@ public abstract class AbstractStep extends StepSupport implements InitializingBe
protected ItemSkipPolicy itemSkipPolicy = new NeverSkipItemSkipPolicy();
protected ItemFailureHandler itemFailureHandler = new DefaultItemFailureHandler();
protected String name;
protected int startLimit = Integer.MAX_VALUE;
protected boolean allowStartIfComplete;
/**
* Default constructor.
@@ -67,13 +73,65 @@ public abstract class AbstractStep extends StepSupport implements InitializingBe
super();
}
public String getName() {
return this.name;
}
/**
* Set the name property if it is not already set. Because of the order of the callbacks in a Spring container the
* name property will be set first if it is present. Care is needed with bean definition inheritance - if a parent
* bean has a name, then its children need an explicit name as well, otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name == null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
public int getStartLimit() {
return this.startLimit;
}
/**
* Public setter for the startLimit.
*
* @param startLimit the startLimit to set
*/
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public boolean isAllowStartIfComplete() {
return this.allowStartIfComplete;
}
/**
* Public setter for the shouldAllowStartIfComplete.
*
* @param allowStartIfComplete the shouldAllowStartIfComplete to set
*/
public void setAllowStartIfComplete(boolean allowStartIfComplete) {
this.allowStartIfComplete = allowStartIfComplete;
}
/**
* Convenient constructor for setting only the name property.
*
* @param name
*/
public AbstractStep(String name) {
super(name);
this.name = name;
}
/**

View File

@@ -237,7 +237,7 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
StepSynchronizationManager.register(stepContext);
possiblyRegisterStreams();
if (isSaveExecutionContext() && isRestart && lastStepExecution != null) {
if (isRestart && lastStepExecution != null) {
stepExecution.setExecutionContext(lastStepExecution.getExecutionContext());
}
else {

View File

@@ -23,7 +23,6 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.scope.SimpleStepContext;
@@ -36,6 +35,7 @@ import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
@@ -46,13 +46,72 @@ import org.springframework.util.Assert;
*
* @author Ben Hale
*/
public class TaskletStep extends StepSupport implements InitializingBean {
public class TaskletStep implements Step, InitializingBean, BeanNameAware {
private static final Log logger = LogFactory.getLog(TaskletStep.class);
private Tasklet tasklet;
private JobRepository jobRepository;
private String name;
private int startLimit = Integer.MAX_VALUE;
private boolean allowStartIfComplete;
public String getName() {
return this.name;
}
/**
* Set the name property if it is not already set. Because of the order of the callbacks in a Spring container the
* name property will be set first if it is present. Care is needed with bean definition inheritance - if a parent
* bean has a name, then its children need an explicit name as well, otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name == null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
public int getStartLimit() {
return this.startLimit;
}
/**
* Public setter for the startLimit.
*
* @param startLimit the startLimit to set
*/
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public boolean isAllowStartIfComplete() {
return this.allowStartIfComplete;
}
/**
* Public setter for the shouldAllowStartIfComplete.
*
* @param allowStartIfComplete the shouldAllowStartIfComplete to set
*/
public void setAllowStartIfComplete(boolean allowStartIfComplete) {
this.allowStartIfComplete = allowStartIfComplete;
}
private RepeatListener[] listeners = new RepeatListener[] {};

View File

@@ -25,13 +25,13 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.runtime.JobParametersFactory;
import org.springframework.batch.execution.configuration.MapJobRegistry;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.support.PropertiesConverter;

View File

@@ -19,9 +19,9 @@ import java.util.Collection;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.beans.FatalBeanException;
import org.springframework.context.support.ClassPathXmlApplicationContext;

View File

@@ -20,10 +20,10 @@ import java.util.Collection;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.DuplicateJobException;
import org.springframework.batch.core.repository.NoSuchJobException;
import org.springframework.batch.execution.configuration.MapJobRegistry;
import org.springframework.batch.execution.job.JobSupport;
/**
* @author Dave Syer
@@ -34,7 +34,7 @@ public class MapJobRegistryTests extends TestCase {
private MapJobRegistry registry = new MapJobRegistry();
/**
* Test method for {@link org.springframework.batch.execution.configuration.MapJobRegistry#unregister(org.springframework.batch.core.domain.JobSupport)}.
* Test method for {@link org.springframework.batch.execution.configuration.MapJobRegistry#unregister(org.springframework.batch.execution.job.JobSupport)}.
* @throws Exception
*/
public void testUnregister() throws Exception {

View File

@@ -0,0 +1,115 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.execution.job;
import java.util.Collections;
import org.springframework.batch.execution.step.StepSupport;
import junit.framework.TestCase;
/**
* @author Dave Syer
*
*/
public class AbstractJobTests extends TestCase {
JobSupport job = new JobSupport("job");
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#JobConfiguration()}.
*/
public void testJobConfiguration() {
job = new JobSupport();
assertNull(job.getName());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#setBeanName(java.lang.String)}.
*/
public void testSetBeanName() {
job.setBeanName("foo");
assertEquals("job", job.getName());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#setBeanName(java.lang.String)}.
*/
public void testSetBeanNameWithNullName() {
job = new JobSupport(null);
assertEquals(null, job.getName());
job.setBeanName("foo");
assertEquals("foo", job.getName());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#setStepNames(java.util.List)}.
*/
public void testSetSteps() {
job.setSteps(Collections.singletonList(new StepSupport("step")));
assertEquals(1, job.getSteps().size());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#addStepName(org.springframework.batch.core.configuration.StepConfiguration)}.
*/
public void testAddStep() {
job.addStep(new StepSupport("step"));
assertEquals(1, job.getSteps().size());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#setStartLimit(int)}.
*/
public void testSetStartLimit() {
assertEquals(Integer.MAX_VALUE, job.getStartLimit());
job.setStartLimit(10);
assertEquals(10, job.getStartLimit());
}
/**
* Test method for
* {@link org.springframework.batch.execution.job.AbstractJob#setRestartable(boolean)}.
*/
public void testSetRestartable() {
assertFalse(job.isRestartable());
job.setRestartable(true);
assertTrue(job.isRestartable());
}
public void testToString() throws Exception {
String value = job.toString();
assertTrue("Should contain name: "+value, value.indexOf("name=")>=0);
}
public void testRunNotSupported() throws Exception {
try {
job.execute(null);
} catch (UnsupportedOperationException e) {
// expected
String message = e.getMessage();
assertTrue("Message should contain JobSupport: "+message, message.contains("JobSupport"));
}
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.execution.job;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.util.ClassUtils;
/**
* Batch domain object representing a job. Job is an explicit abstraction
* representing the configuration of a job specified by a developer. It should
* be noted that restart policy is applied to the job as a whole and not to a
* step.
*
* @author Lucas Ward
* @author Dave Syer
*/
public class JobSupport implements BeanNameAware, Job {
private List steps = new ArrayList();
private String name;
private boolean restartable = false;
private int startLimit = Integer.MAX_VALUE;
/**
* Default constructor.
*/
public JobSupport() {
super();
}
/**
* Convenience constructor to immediately add name (which is mandatory but
* not final).
*
* @param name
*/
public JobSupport(String name) {
super();
this.name = name;
}
/**
* Set the name property if it is not already set. Because of the order of
* the callbacks in a Spring container the name property will be set first
* if it is present. Care is needed with bean definition inheritance - if a
* parent bean has a name, then its children need an explicit name as well,
* otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name == null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object
* is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getName()
*/
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getSteps()
*/
public List getSteps() {
return steps;
}
public void setSteps(List steps) {
this.steps.clear();
this.steps.addAll(steps);
}
public void addStep(Step step) {
this.steps.add(step);
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#getStartLimit()
*/
public int getStartLimit() {
return startLimit;
}
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public void setRestartable(boolean restartable) {
this.restartable = restartable;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.IJob#isRestartable()
*/
public boolean isRestartable() {
return restartable;
}
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.Job#run(org.springframework.batch.core.domain.JobExecution)
*/
public void execute(JobExecution execution) throws BatchCriticalException {
throw new UnsupportedOperationException("JobSupport does not provide an implementation of run(). Use a smarter subclass.");
}
public String toString() {
return ClassUtils.getShortName(getClass()) + ": [name=" + name + "]";
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.execution.job.simple;
package org.springframework.batch.execution.job;
import java.util.ArrayList;
import java.util.List;
@@ -30,6 +30,7 @@ import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
import org.springframework.batch.execution.job.SimpleJob;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobExecutionDao;
import org.springframework.batch.execution.repository.dao.JobInstanceDao;

View File

@@ -25,8 +25,8 @@ import org.easymock.MockControl;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.core.task.TaskExecutor;

View File

@@ -28,7 +28,7 @@ import org.springframework.batch.core.domain.ItemFailureHandler;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.execution.job.simple.SimpleJob;
import org.springframework.batch.execution.job.SimpleJob;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.MapJobDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;

View File

@@ -6,7 +6,7 @@ import java.util.Map;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.util.ClassUtils;

View File

@@ -26,14 +26,14 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.repository.BatchRestartException;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.repository.dao.JobExecutionDao;
import org.springframework.batch.execution.repository.dao.JobInstanceDao;
import org.springframework.batch.execution.repository.dao.StepExecutionDao;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
/**

View File

@@ -26,8 +26,8 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.util.ClassUtils;

View File

@@ -22,11 +22,11 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.dao.OptimisticLockingFailureException;

View File

@@ -22,7 +22,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;

View File

@@ -8,10 +8,10 @@ import org.easymock.MockControl;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

View File

@@ -24,7 +24,7 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.execution.job.JobSupport;
public class MapJobDaoTests extends TestCase {

View File

@@ -21,10 +21,10 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.step.StepSupport;
public class MapStepDaoTests extends TestCase {

View File

@@ -25,10 +25,10 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.scope.SimpleStepContext;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;

View File

@@ -21,7 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.StepSupport;
/**
* @author Dave Syer

View File

@@ -22,8 +22,8 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.step.StepSupport;
import org.springframework.batch.repeat.synch.RepeatSynchronizationManager;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.ObjectFactory;

View File

@@ -27,11 +27,10 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.MapJobDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
@@ -277,7 +276,6 @@ public class ItemOrientedStepTests extends TestCase {
Step step = new StepSupport("stepName");
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemReader(tasklet);
itemOrientedStep.setSaveExecutionContext(true);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -319,7 +317,6 @@ public class ItemOrientedStepTests extends TestCase {
Step step = new StepSupport("stepName");
MockRestartableItemReader tasklet = new MockRestartableItemReader();
itemOrientedStep.setItemReader(tasklet);
itemOrientedStep.setSaveExecutionContext(false);
JobExecution jobExecutionContext = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
@@ -345,7 +342,6 @@ public class ItemOrientedStepTests extends TestCase {
return "foo";
}
});
itemOrientedStep.setSaveExecutionContext(true);
JobExecution jobExecution = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecution);
@@ -371,7 +367,6 @@ public class ItemOrientedStepTests extends TestCase {
return "foo";
}
});
itemOrientedStep.setSaveExecutionContext(true);
JobExecution jobExecution = new JobExecution(jobInstance);
StepExecution stepExecution = new StepExecution(step, jobExecution);

View File

@@ -0,0 +1,117 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.execution.step;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.beans.factory.BeanNameAware;
/**
* Basic no-op support implementation for use as base class for {@link Step}. Implements {@link BeanNameAware} so that
* if no name is provided explicitly it will be inferred from the bean definition in Spring configuration.
*
* @author Dave Syer
*
*/
public class StepSupport implements Step, BeanNameAware {
private String name;
private int startLimit = Integer.MAX_VALUE;
private boolean allowStartIfComplete;
/**
* Default constructor for {@link StepSupport}.
*/
public StepSupport() {
super();
}
/**
* @param string
*/
public StepSupport(String string) {
super();
this.name = string;
}
public String getName() {
return this.name;
}
/**
* Set the name property if it is not already set. Because of the order of the callbacks in a Spring container the
* name property will be set first if it is present. Care is needed with bean definition inheritance - if a parent
* bean has a name, then its children need an explicit name as well, otherwise they will not be unique.
*
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
*/
public void setBeanName(String name) {
if (this.name == null) {
this.name = name;
}
}
/**
* Set the name property. Always overrides the default value if this object is a Spring bean.
*
* @see #setBeanName(java.lang.String)
*/
public void setName(String name) {
this.name = name;
}
public int getStartLimit() {
return this.startLimit;
}
/**
* Public setter for the startLimit.
*
* @param startLimit the startLimit to set
*/
public void setStartLimit(int startLimit) {
this.startLimit = startLimit;
}
public boolean isAllowStartIfComplete() {
return this.allowStartIfComplete;
}
/**
* Public setter for the shouldAllowStartIfComplete.
*
* @param allowStartIfComplete the shouldAllowStartIfComplete to set
*/
public void setAllowStartIfComplete(boolean allowStartIfComplete) {
this.allowStartIfComplete = allowStartIfComplete;
}
/**
* Not supported but provided so that tests can easily create a step.
*
* @throws UnsupportedOperationException always
*
* @see org.springframework.batch.core.domain.Step#execute(org.springframework.batch.core.domain.StepExecution)
*/
public void execute(StepExecution stepExecution) throws JobInterruptedException, BatchCriticalException {
throw new UnsupportedOperationException(
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");
}
}

View File

@@ -9,10 +9,9 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.scope.StepSynchronizationManager;
import org.springframework.batch.execution.step.support.JobRepositorySupport;
import org.springframework.batch.io.exception.BatchCriticalException;

View File

@@ -23,9 +23,9 @@ import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.execution.job.JobSupport;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobExecutionDao;
import org.springframework.batch.execution.repository.dao.JobInstanceDao;

View File

@@ -15,7 +15,7 @@
</bean>
<bean id="test-job"
class="org.springframework.batch.core.domain.JobSupport">
class="org.springframework.batch.execution.job.JobSupport">
<property name="steps">
<bean id="step1"
class="org.springframework.batch.execution.step.ItemOrientedStep">

View File

@@ -10,7 +10,7 @@
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="test-job"
class="org.springframework.batch.core.domain.JobSupport">
class="org.springframework.batch.execution.job.JobSupport">
<property name="steps">
<bean id="step1"
class="org.springframework.batch.execution.step.ItemOrientedStep">

View File

@@ -18,7 +18,7 @@
class="org.springframework.batch.execution.configuration.MapJobRegistry" />
<bean id="test-job"
class="org.springframework.batch.core.domain.JobSupport">
class="org.springframework.batch.execution.job.JobSupport">
<property name="steps">
<bean id="step1" class="org.springframework.batch.execution.step.ItemOrientedStep">
<property name="itemReader" ref="itemReader" />
@@ -44,17 +44,17 @@
<bean id="test-job-with-name"
class="org.springframework.batch.core.domain.JobSupport">
class="org.springframework.batch.execution.job.JobSupport">
<property name="name" value="foo" />
</bean>
<bean id="test-job-with-bean-name"
class="org.springframework.batch.core.domain.JobSupport">
class="org.springframework.batch.execution.job.JobSupport">
<property name="beanName" value="bar" />
</bean>
<bean id="abstract-job"
class="org.springframework.batch.core.domain.JobSupport"
class="org.springframework.batch.execution.job.JobSupport"
abstract="true" />
<bean id="test-job-with-parent" parent="abstract-job" />
@@ -66,7 +66,7 @@
p:name="bucket" />
<bean id="parent-job"
class="org.springframework.batch.core.domain.JobSupport" />
class="org.springframework.batch.execution.job.JobSupport" />
<bean id="test-job-with-concrete-parent" parent="parent-job"
p:name="maps" />

View File

@@ -18,7 +18,7 @@
class="org.springframework.batch.execution.configuration.MapJobRegistry" />
<bean id="simpleJob"
class="org.springframework.batch.execution.job.simple.SimpleJob"
class="org.springframework.batch.execution.job.SimpleJob"
abstract="true">
<property name="restartable" value="true" />
<property name="jobRepository" ref="simpleJobRepository" />
@@ -28,7 +28,6 @@
class="org.springframework.batch.execution.step.ItemOrientedStep"
abstract="true">
<property name="allowStartIfComplete" value="true" />
<property name="saveExecutionContext" value="false" />
<property name="exceptionHandler">
<bean
class="org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler">