added a BatchResourceFactoryBean to fixedlengthImportJob and fixed a repository error it illuminated.

This commit is contained in:
lucasward
2008-01-28 15:41:43 +00:00
parent c412bce1f0
commit f092cb8a99
7 changed files with 82 additions and 37 deletions

View File

@@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/spring-batch-execution/src/main/java/org/springframework/batch/execution/bootstrap/support/BatchCommandLineLauncher.java"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="1"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;core&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;classpathContainer path=&amp;quot;org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.classpathContainer&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;execution&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;infrastructure&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.springframework.batch.execution.bootstrap.support.BatchCommandLineLauncher"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="spring-batch-samples"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djob.configuration.path=jobs/footballJob.xml -Djob.name=footballJob -Dplayer.file.name=player.csv -Dgames.file.name=games.csv"/>
</launchConfiguration>
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/spring-batch-samples"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;core&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;classpathContainer path=&amp;quot;org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.classpathContainer&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;execution&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;infrastructure&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.springframework.batch.execution.bootstrap.support.BatchCommandLineLauncher"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="spring-batch-samples"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djob.configuration.path=jobs/footballJob.xml -Djob.name=footballJob -Dplayer.file.name=player.csv -Dgames.file.name=games.csv"/>
</launchConfiguration>

View File

@@ -37,7 +37,7 @@
</bean>
<!-- Use this to set additional properties on beans at run time -->
<bean
<bean id="batchProperties"
class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">
<property name="location" value="classpath:batch.properties" />
<!-- Allow system properties (-D) to override those from file -->
@@ -50,7 +50,7 @@
<property name="order" value="2" />
</bean>
<bean
<bean id="overrideProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:batch.properties" />
<property name="systemPropertiesModeName"

View File

@@ -10,7 +10,7 @@
<bean parent="stepScope"/>
<bean parent="jobConfigurationRegistryBeanPostProcessor"/>
<bean id="fixedLengthImportJob" parent="simpleJob">
<bean id="fixedLengthImportJob" parent="simpleJob" lazy-init="true">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="tasklet">
@@ -19,7 +19,7 @@
<property name="itemReader">
<bean
class="org.springframework.batch.item.reader.ValidatingItemReader">
<property name="itemReader" ref="fileInputTemplate" />
<property name="itemReader" ref="fileItemReader" />
<property name="validator" ref="fixedValidator" />
</bean>
</property>
@@ -37,13 +37,10 @@
<!-- INFRASTRUCTURE SETUP -->
<!-- This input source is injected into the test case to verify the output - not used by the job at all -->
<bean id="testInputTemplate" class="org.springframework.batch.io.file.DefaultFlatFileItemReader">
<bean id="fileItemReader" class="org.springframework.batch.io.file.DefaultFlatFileItemReader" scope="step">
<property name="resource" ref="fileLocator" />
<property name="tokenizer" ref="fixedFileDescriptor" />
<property name="fieldSetMapper" ref="fieldSetMapper" />
</bean>
<bean id="fileInputTemplate" parent="testInputTemplate" autowire-candidate="false" scope="step">
<property name="fieldSetMapper" ref="fieldSetMapper" />
<aop:scoped-proxy/>
</bean>
@@ -75,11 +72,17 @@
</property>
</bean>
<!--
<bean id="fileLocator" class="org.springframework.core.io.ClassPathResource">
<constructor-arg type="java.lang.String"
value="data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt" />
</bean>
-->
<bean id="fileLocator" class="org.springframework.batch.execution.resource.BatchResourceFactoryBean" scope="step" lazy-init="true">
<property name="filePattern" value="data/%JOB_NAME%/input/20070122.teststream.ImportTradeDataStep.txt" />
<aop:scoped-proxy/>
</bean>
<bean id="fieldSetMapper" class="org.springframework.batch.sample.mapping.TradeFieldSetMapper" />

View File

@@ -167,7 +167,7 @@
</aop:aspect>
</aop:config>
<bean
<bean id="footbalProperties"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<value>
@@ -177,7 +177,7 @@
</property>
<property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreUnresolvablePlaceholders" value="false" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="order" value="1" />
</bean>

View File

@@ -15,7 +15,7 @@
<bean id="stepScope"
class="org.springframework.batch.execution.scope.StepScope" />
<bean id="jobConfigurationRegistryBeanPostProcessor"
<bean id="jobConfigurationRegistryBeanPostProcessor" abstract="true"
class="org.springframework.batch.execution.configuration.JobRegistryBeanPostProcessor">
<property name="jobConfigurationRegistry"
ref="jobConfigurationRegistry" />

View File

@@ -6,6 +6,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.batch.sample.item.processor.CustomerCreditIncreaseProcessor;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
@@ -28,6 +29,13 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
protected PlatformTransactionManager transactionManager;
private static final BigDecimal CREDIT_INCREASE = CustomerCreditIncreaseProcessor.FIXED_AMOUNT;
private static String[] customers = { "INSERT INTO customer (id, version, name, credit) VALUES (1, 0, 'customer1', 100000)",
"INSERT INTO customer (id, version, name, credit) VALUES (2, 0, 'customer2', 100000)",
"INSERT INTO customer (id, version, name, credit) VALUES (3, 0, 'customer3', 100000)",
"INSERT INTO customer (id, version, name, credit) VALUES (4, 0, 'customer4', 100000)"};
private static String DELETE_CUSTOMERS = "DELETE FROM customer";
private static final String ALL_CUSTOMERS = "select * from CUSTOMER order by ID";
@@ -36,6 +44,8 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
protected static final String ID_COLUMN = "ID";
private List creditsBeforeUpdate;
private SessionFactory sessionFactory;
/**
* @param jdbcTemplate
@@ -44,6 +54,10 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
this.jdbcTemplate = jdbcTemplate;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/**
* Public setter for the PlatformTransactionManager.
* @param transactionManager the transactionManager to set
@@ -57,8 +71,10 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
*/
protected void validatePreConditions() throws Exception {
super.validatePreConditions();
ensureState();
creditsBeforeUpdate = (List) new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
return jdbcTemplate.query(ALL_CUSTOMERS, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return rs.getBigDecimal(CREDIT_COLUMN);
@@ -68,6 +84,24 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
});
}
/*
* Ensure the state of the database is accurate by delete all the contents of the
* customer table and reading the expected defaults.
*/
private void ensureState(){
new TransactionTemplate(transactionManager).execute(new TransactionCallback(){
public Object doInTransaction(TransactionStatus status) {
jdbcTemplate.update(DELETE_CUSTOMERS);
for(int i = 0; i < customers.length;i++){
jdbcTemplate.update(customers[i]);
}
return null;
}
});
}
/**
* Credit was increased by CREDIT_INCREASE
*/
@@ -94,8 +128,7 @@ public abstract class AbstractCustomerCreditIncreaseTests extends AbstractValida
});
assertEquals(getExpectedMatches(), matches.size());
checkMatches(matches);
checkMatches(matches);
}
/**

View File

@@ -21,8 +21,14 @@ import java.io.FileReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.sample.domain.Trade;
import org.springframework.batch.sample.mapping.TradeFieldSetMapper;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowCallbackHandler;
@@ -35,11 +41,17 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
//auto-injected attributes
private JdbcOperations jdbcTemplate;
private Resource fileLocator;
private ItemReader inputSource;
private DefaultFlatFileItemReader inputSource;
private LineTokenizer lineTokenizer;
protected void onSetUp() throws Exception {
super.onSetUp();
jdbcTemplate.update("delete from TRADE");
fileLocator = new ClassPathResource("data/fixedLengthImportJob/input/20070122.teststream.ImportTradeDataStep.txt");
inputSource = new DefaultFlatFileItemReader();
inputSource.setFieldSetMapper(new TradeFieldSetMapper());
inputSource.setTokenizer(lineTokenizer);
inputSource.setResource(fileLocator);
}
protected String[] getConfigLocations() {
@@ -89,12 +101,9 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
public void setJdbcTemplate(JdbcOperations jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public void setFileLocator(Resource fileLocator) {
this.fileLocator = fileLocator;
public void setLineTokenizer(LineTokenizer lineTokenizer) {
this.lineTokenizer = lineTokenizer;
}
public void setItemReader(ItemReader inputSource){
this.inputSource = inputSource;
}
}