Results 1 to 4 of 4

Thread: Read flat file and process it without writing using Spring Batch

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Default 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

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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).

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Talking

    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 +++++++++++++");

    }

    }

  4. #4
    Join Date
    Mar 2011
    Posts
    5

    Default

    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
  •