具有commit-interval 2的Spring批处理将相同的对象写入两次并跳过另一个对象

时间:2017-01-27 15:40:41

标签: jdbc spring-batch spring-jdbc

我使用来自Spring Framework的FlatFileItemReaderJdbcItemWriter批量写入从文件到Oracle数据库的数据。 配置commit-interval>时1,让我们说2,Reader从文件中读取两行,然后写入器将数据从第二行写入数据库两次。

我的配置是这样的:

<batch:job id="Job">
    <batch:step id="step">
        <batch:tasklet>
            <batch:chunk reader="Reader" writer="Writer"
                commit-interval="2" processor-transactional="false" />
        </batch:tasklet>
        <batch:fail on="FAILED" />
    </batch:step>
</batch:job>

<bean id="Reader" class="org.springframework.batch.item.file.FlatFileItemReader">
    <property name="linesToSkip" value="1" />
    <!-- TODO: FilePath definieren (Umgebungsabhängig) -->
    <property name="resource" value="file:in/Users_kurz.csv" />
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer">
                <bean
                    class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
                    <property name="names" value="name1, name2, name3, name4" />
                    <property name="delimiter" value=";" />
                </bean>
            </property>
            <property name="fieldSetMapper">
                <bean
                    class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
                    <property name="prototypeBeanName" value="lineObject" />
                </bean>
            </property>
        </bean>
    </property>
</bean>
  <bean id="LineObject" class="this.is.my.LineObject" />

 <bean id="dcIdentityWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter">
    <property name="dataSource" ref="dataSource" />
    <property name="sql"
        value="INSERT INTO table(col1, col2, col3, col4)
   VALUES (:name1, name2, name3, name4)" />
    <property name="itemSqlParameterSourceProvider">
        <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
    </property>
    </bean>

0 个答案:

没有答案