-
Mar 1st, 2011, 06:22 AM
#1
Read flat file and process it without writing using Spring Batch
Hi
I am new to Spring Batch please help
Requirement is
Read flat file and process it I should not write those processed data using Spring Batch. (To write those processed data I will use my own product component).
How do I do it can you please give me the code snippet
Thanks for your time
-
Mar 4th, 2011, 02:46 AM
#2
There isn't really enough detail here to say what you should do. Maybe you need to use just the spring-batch-infrastructure components to do the reading and handle everything else yourself? Or if you want the Job-Step domain abstraction from spring-batch-core, you can just wrap your own code in an ItemWriter (maybe you can even use the POJO adapters in the framework).
-
Mar 4th, 2011, 02:53 AM
#3
Thanks
The following helped me

CustomCompositeItemWriterJob.xm
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns
="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/schem...-beans-2.0.xsd
http://www.springframework.org/schema/batch http://www.springframework.org/schem...-batch-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!--<beans:import resource="MEMORY-JOBREPOSITORY.xml"/> -->
<import resource="DB-JOBREPOSITORY.xml"/>
<bean id="dynamicJobParameters" class="com.ecomputercoach.DynamicJobParameters" />
<batch:job id="singleInputMultipleOutputsJob" incrementer="dynamicJobParameters" job-repository="jobRepository">
<batch:step id="step1">
<batch:tasklet transaction-manager="jobRepository-transactionManager" >
<batch:chunk reader="playerFileItemReader" writer="compositeWriter"
commit-interval="100">
<batch:streams>
<batch:stream ref="playerFileItemReader"/>
</batch:streams>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<!-- INFRASTRUCTURE SETUP -->
<bean id="compositeWriter" class="com.ecomputercoach.file.composite.Separator CompositeItemWriter">
</bean>
<bean id="playerFileItemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
<!-- <property
name="resource" value="classpath:input/player.csv" /> -->
<property name="resource" value="file:c:\data\input\player.csv" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer">
<property name="delimiter" value=","/>
<property name="names" value="ID,lastName,firstName,position,debutYear,fi nalYear" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="com.ecomputercoach.file.PlayerFieldSetMappe r" />
</property>
</bean>
</property>
</bean>
</beans>
SeparatorCompositeItemWriter.java
package com.ecomputercoach.file.composite;
import java.util.List;
import com.ecomputercoach.file.composite.PersistDatabase;
import org.springframework.batch.item.ItemWriter;
@SuppressWarnings("unchecked")
public class SeparatorCompositeItemWriter implements ItemWriter
{
public void write(List items) throws Exception
{
new PersistDatabase().processBundle(items);
System.out.println(" end printed all from process +++++++++++++");
}
}
-
Mar 7th, 2011, 04:38 AM
#4
Is there any way to avoid calling writer at all after reading ? Can we completely ignore calling writer?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules