DataLoader使用Spring Batch - 分区

时间:2011-10-24 15:34:31

标签: java transactions spring-batch

我正在研究一个数据加载器,它读取平面文件,一些处理并写入数据库。 dataloader.properties个文件包含值

LOAD=MM1,MM2,MM3,MM4,MM5...

我必须阅读这个属性文件并使用spring batch的partition steppartitioner,我想要文件夹(MM1)中的所有文件,读取和写入db parallel,任何db错误对于特定文件应该回滚该文件的内容,类似于其他文件夹(MM2)因为我是春季批处理的新手,我想知道如何对文件夹和XML配置文件中的文件名进行后期绑定,需要适当的回滚。我还想在文件夹分区步骤

中共享数据

以下是执行此操作的作业的粗略配置。根据上述要求,这是一种正确的方法吗?

<!--  The Data Loading Configuration goes here  -->      

<job id="partition${jobname}Job" name="${jobname}" xmlns="http://www.springframework.org/schema/batch">
    <step id="exchangestep" next="filestep">
        <partition step="step1" partitioner="exchangepartitioner">
            <handler grid-size="999" task-executor="taskExecutor" />
        </partition>
    </step>
    <step id="filestep">
        <partition step="step1" partitioner="filepartitioner">
            <handler grid-size="99" task-executor="taskExecutor" />
        </partition>
    </step>
</job>

<bean id="folderpartitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
    <property name="resources" value="#${folder}" />
</bean>

<bean id="filepartitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner">
    <property name="resources" value="#${file}" />
</bean>

<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor" />

<step id="step1" xmlns="http://www.springframework.org/schema/batch">
    <tasklet transaction-manager="transactionManager">
        <chunk writer="itemWriter" reader="itemReader" processor="itemProcessor" commit-interval="5000" />
    </tasklet>
</step>

<bean id="itemReader" scope="step" autowire-candidate="false" parent="itemReaderParent">
    <property name="resource" value="#{stepExecutionContext[fileName]}" />
</bean>

<bean id="multifileReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
    <property name="resources" value="#${filename}" />
    <property name="delegate" ref="fileItemReader" />
</bean>

<bean id="fileItemReader" parent="itemReaderParent" />


<!--  CONFIGURE THE FLAT FILE ITEM READER TO READ INDIVIDUAL BATCH -->
<bean id="itemReaderParent" class="org.springframework.batch.item.file.FlatFileItemReader" abstract="true">
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
                    <property name="names" value="${columns}" />
                    <property name="columns" value="${range}" />
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean class="org.springframework.batch.item.file.mapping.FieldSetMapper">
                    <property name="targetType" value="DataLoaderMapper" />
                </bean>
            </property>
        </bean>
    </property>
</bean>

0 个答案:

没有答案