IN PROGRESS - BATCH-971: add database writers to iosample

migrate ibatisJob to iosamples
fixed AbstractPagingItemReader to reset its state on close()
This commit is contained in:
robokaso
2008-12-17 16:31:13 +00:00
parent c98903793a
commit 194cc1db69
8 changed files with 50 additions and 88 deletions

View File

@@ -111,7 +111,9 @@ public abstract class AbstractPagingItemReader<T> extends AbstractItemCountingIt
protected void doClose() throws Exception {
initialized = false;
current = 0;
page = 0;
results = null;
}

View File

@@ -18,7 +18,6 @@
<config>src/main/resources/jobs/adhocLoopJob.xml</config>
<config>src/main/resources/jobs/infiniteLoopJob.xml</config>
<config>src/main/resources/data-source-context-init.xml</config>
<config>src/main/resources/jobs/ibatisJob.xml</config>
<config>src/main/resources/jobs/footballJob.xml</config>
<config>src/main/resources/jobs/delegatingJob.xml</config>
<config>src/main/resources/jobs/parallelJob.xml</config>
@@ -108,7 +107,6 @@
<incomplete>false</incomplete>
<configs>
<config>src/main/resources/data-source-context.xml</config>
<config>src/main/resources/jobs/ibatisJob.xml</config>
<config>src/main/resources/simple-job-launcher-context.xml</config>
<config>src/main/resources/org/springframework/batch/sample/config/common-context.xml</config>
</configs>

View File

@@ -13,6 +13,10 @@
select ID from CUSTOMER
</select>
<select id="getAllCustomerCredits" resultMap="result">
select ID, NAME, CREDIT from CUSTOMER
</select>
<select id="getCustomerCreditById" parameterClass="int" resultMap="result">
select NAME, CREDIT from CUSTOMER where ID = #value#
</select>

View File

@@ -1,58 +0,0 @@
<?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"
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">
<description>Example for iBATIS integration.</description>
<bean id="ibatisJob" parent="simpleJob">
<property name="steps">
<bean id="step1" parent="simpleStep">
<property name="itemReader" ref="ibatisItemReader" />
<property name="itemProcessor">
<bean class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditIncreaseProcessor" />
</property>
<property name="itemWriter">
<bean
class="org.springframework.batch.sample.domain.trade.internal.CustomerCreditItemWriter">
<property name="customerCreditDao">
<bean
class="org.springframework.batch.sample.domain.trade.internal.IbatisCustomerCreditDao">
<property name="sqlMapClient"
ref="sqlMapClient" />
<property name="statementId"
value="updateCredit" />
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
<bean id="ibatisItemReader"
class="org.springframework.batch.item.database.IbatisDrivingQueryItemReader">
<property name="detailsQueryId" value="getCustomerCreditById" />
<property name="sqlMapClient" ref="sqlMapClient" />
<property name="keyCollector" ref="ibatisKeyGenerator" />
</bean>
<bean id="ibatisKeyGenerator"
class="org.springframework.batch.item.database.support.IbatisKeyCollector">
<property name="drivingQueryId" value="getAllCustomerCreditIds" />
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="sqlMapClient"
class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="ibatis-config.xml" />
<property name="dataSource" ref="dataSource" />
</bean>
</beans>

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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.xsd">
<bean id="itemReader"
class="org.springframework.batch.item.database.IbatisPagingItemReader">
<property name="queryId" value="getAllCustomerCredits" />
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="itemWriter"
class="org.springframework.batch.item.database.IbatisBatchItemWriter">
<property name="statementId" value="updateCredit" />
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="ibatis-config.xml" />
</bean>
</beans>

View File

@@ -1,17 +0,0 @@
package org.springframework.batch.sample;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Test for IbatisJob - checks that customer credit has been updated to expected value.
*
* @author Robert Kasanicky
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration()
public class IbatisJobFunctionalTests extends AbstractCustomerCreditIncreaseTests{
}

View File

@@ -0,0 +1,19 @@
package org.springframework.batch.sample.iosample;
import org.junit.runner.RunWith;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.sample.domain.trade.CustomerCredit;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/ioSampleJob.xml",
"/jobs/iosample/ibatis.xml" })
public class IbatisFunctionalTests extends AbstractIoSampleTests {
@Override
protected void pointReaderToOutput(ItemReader<CustomerCredit> reader) {
// no-op
}
}

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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">
<import resource="classpath:/simple-job-launcher-context.xml" />
<import resource="classpath:/jobs/ibatisJob.xml*" />
</beans>