Use factory bean in integration project for repository

This commit is contained in:
dsyer
2008-07-30 08:56:19 +00:00
parent a6eb539b0e
commit c6e0c85731
3 changed files with 71 additions and 55 deletions

View File

@@ -23,7 +23,7 @@ import org.springframework.util.StringUtils;
* Value object used to carry information about the status of a
* {@link RepeatOperations}.
*
* ExitStatus is immutable and therefore thread-safe.
* ExitStatus is immutable and therefore thread-safe.
*
* @author Dave Syer
*
@@ -31,15 +31,25 @@ import org.springframework.util.StringUtils;
public class ExitStatus implements Serializable {
/**
* Convenient constant value representing unknown state - assumed
* not continuable.
* Convenient constant value representing unknown state - assumed not
* continuable.
*/
public static final ExitStatus UNKNOWN = new ExitStatus(false, "UNKNOWN");
/**
* Convenient constant value representing unfinished processing.
*/
public static final ExitStatus CONTINUABLE = new ExitStatus(true, "CONTINUABLE");
public static final ExitStatus CONTINUABLE = new ExitStatus(true,
"CONTINUABLE");
/**
* Convenient constant value representing continuable state where processing
* is still taking place, so no further action is required. Used for
* asynchronous execution scenarios where the processing is happening in
* another thread or process and the caller is not required to wait for the
* result.
*/
public static final ExitStatus EXECUTING = new ExitStatus(true, "EXECUTING");
/**
* Convenient constant value representing finished processing.
@@ -71,7 +81,8 @@ public class ExitStatus implements Serializable {
this(continuable, exitCode, "");
}
public ExitStatus(boolean continuable, String exitCode, String exitDescription) {
public ExitStatus(boolean continuable, String exitCode,
String exitDescription) {
super();
this.continuable = continuable;
this.exitCode = exitCode;
@@ -110,12 +121,14 @@ public class ExitStatus implements Serializable {
* Create a new {@link ExitStatus} with a logical combination of the
* continuable flag.
*
* @param continuable true if the caller thinks it is safe to continue.
* @param continuable
* true if the caller thinks it is safe to continue.
* @return a new {@link ExitStatus} with {@link #isContinuable()} the
* logical and of the current value and the argument provided.
* logical and of the current value and the argument provided.
*/
public ExitStatus and(boolean continuable) {
return new ExitStatus(this.continuable && continuable, this.exitCode, this.exitDescription);
return new ExitStatus(this.continuable && continuable, this.exitCode,
this.exitDescription);
}
/**
@@ -126,15 +139,17 @@ public class ExitStatus implements Serializable {
*
* If the input is null just return this.
*
* @param status an {@link ExitStatus} to combine with this one.
* @param status
* an {@link ExitStatus} to combine with this one.
* @return a new {@link ExitStatus} with {@link #isContinuable()} the
* logical and of the current value and the argument provided.
* logical and of the current value and the argument provided.
*/
public ExitStatus and(ExitStatus status) {
if (status == null) {
return this;
}
ExitStatus result = and(status.continuable).addExitDescription(status.exitDescription);
ExitStatus result = and(status.continuable).addExitDescription(
status.exitDescription);
if (result.continuable || !status.continuable) {
result = result.replaceExitCode(status.exitCode);
}
@@ -147,7 +162,8 @@ public class ExitStatus implements Serializable {
* @see java.lang.Object#toString()
*/
public String toString() {
return "continuable=" + continuable + ";exitCode=" + exitCode + ";exitDescription=" + exitDescription;
return "continuable=" + continuable + ";exitCode=" + exitCode
+ ";exitDescription=" + exitDescription;
}
/**
@@ -172,12 +188,13 @@ public class ExitStatus implements Serializable {
}
/**
* Add an exit code to an existing {@link ExitStatus}. If there is already a
* code present tit will be replaced.
* Add an exit code to an existing {@link ExitStatus}. If there is already
* a code present tit will be replaced.
*
* @param code the code to add
* @param code
* the code to add
* @return a new {@link ExitStatus} with the same properties but a new exit
* code.
* code.
*/
public ExitStatus replaceExitCode(String code) {
return new ExitStatus(continuable, code, exitDescription);
@@ -189,7 +206,8 @@ public class ExitStatus implements Serializable {
* @return true if the exit code is "RUNNING" or "UNKNOWN"
*/
public boolean isRunning() {
return "RUNNING".equals(this.exitCode) || "UNKNOWN".equals(this.exitCode);
return "RUNNING".equals(this.exitCode)
|| "UNKNOWN".equals(this.exitCode);
}
/**
@@ -197,12 +215,14 @@ public class ExitStatus implements Serializable {
* already a description present the two will be concatenated with a
* semicolon.
*
* @param description the description to add
* @param description
* the description to add
* @return a new {@link ExitStatus} with the same properties but a new exit
* description
* description
*/
public ExitStatus addExitDescription(String description) {
if (StringUtils.hasText(exitDescription) && StringUtils.hasText(description)
if (StringUtils.hasText(exitDescription)
&& StringUtils.hasText(description)
&& !exitDescription.equals(description)) {
description = exitDescription + "; " + description;
}

View File

@@ -20,11 +20,12 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.configuration.JobLocator;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -40,11 +41,12 @@ public class MessageOrientedStepIntegrationTests {
private JobLauncher jobLauncher;
@Autowired
private JobLocator jobLocator;
@Qualifier("job")
private Job job;
@Test
public void testLaunchJob() throws Exception {
JobExecution jobExecution = jobLauncher.run(jobLocator.getJob("job"), new JobParameters());
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
}

View File

@@ -1,44 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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.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">
<bean id="jobRegistryBeanPostProcessor"
class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
<property name="jobRegistry" ref="jobRegistry" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="jobRegistry"
class="org.springframework.batch.core.configuration.support.MapJobRegistry" />
<bean id="transactionManager"
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<constructor-arg ref="mapJobInstanceDao" />
<constructor-arg ref="mapJobExecutionDao" />
<constructor-arg ref="mapStepExecutionDao" />
<constructor-arg ref="mapExecutionContextDao" />
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="mapExecutionContextDao" lazy-init="true"
class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
<bean id="mapJobInstanceDao" lazy-init="true"
class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
<bean id="mapJobExecutionDao" lazy-init="true"
class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
<bean id="mapStepExecutionDao" lazy-init="true"
class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
<bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob"
<bean id="simpleJob"
class="org.springframework.batch.core.job.SimpleJob"
abstract="true">
<property name="jobRepository" ref="jobRepository" />
<property name="restartable" value="true" />
</bean>
<bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.TaskletStep"
<bean id="taskletStep"
class="org.springframework.batch.core.step.tasklet.TaskletStep"
abstract="true">
<property name="jobRepository" ref="jobRepository" />
<property name="allowStartIfComplete" value="true" />
@@ -50,25 +41,28 @@
<property name="jobRepository" ref="jobRepository" />
<property name="startLimit" value="100" />
<property name="commitInterval" value="1" />
</bean>
<bean id="skipLimitStep"
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean"
parent="simpleStep" abstract="true">
<property name="skipLimit" value="0" />
</bean>
<bean id="skipLimitStep"
class="org.springframework.batch.core.step.item.SkipLimitStepFactoryBean"
parent="simpleStep" abstract="true">
<property name="skipLimit" value="0" />
</bean>
<bean id="customEditorConfigurer"
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="int[]">
<bean class="org.springframework.batch.support.IntArrayPropertyEditor" />
<bean
class="org.springframework.batch.support.IntArrayPropertyEditor" />
</entry>
<entry key="org.springframework.batch.item.file.transform.Range[]">
<entry
key="org.springframework.batch.item.file.transform.Range[]">
<bean
class="org.springframework.batch.item.file.transform.RangeArrayPropertyEditor" />
</entry>
<entry key="java.util.Date">
<bean class="org.springframework.beans.propertyeditors.CustomDateEditor">
<bean
class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg>
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="yyyyMMdd" />