Announcement Announcement Module
No announcement yet.
Transaction Management Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction Management


    I need some help in order to manage transaction.

    My batch do that:

    1) read element in database, process them and write them in a flat file
    2) read a flat file, process it and write element in database
    3) read another element in database, process them and write them in the same flat file
    4) task which marks all element as "processed"
    5) historicize the flat file
    6) send fiat file in ftp

    I do a Step in one Job for each steps 1,2,3,4 and 5.

    I want these step are in the same transaction. If an exception occures during step 1,2,3,4 or 5, i want to rollback all modifications in database.

    How to configure the step and job in config file.
    Someone can create a sample of simple config file?

  • #2
    I create a sample config file

    <!-- BATCH -->
        <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="myDs"></property>
        <bean id="jobRepository" class="">
        	<property name="transactionManager" ref="transactionManager"/>
        <bean id="jobLauncher" class="">
            <property name="jobRepository" ref="jobRepository" />
        <job id="exportJob"  job-repository="jobRepository" xmlns="" >
            <step  id="step1">
                    <chunk reader="myReader1" writer="myWriter1" processor="myProcessor1" commit-interval="100" />
                <next on="*" to="step2" />
            <step id="step2">
                    <chunk reader="myReader2" writer="myWriter2" processor="myProcessor2" commit-interval="100" />
                <next on="*" to="step3" />
            <step id="step3">
                    <chunk reader="myReader3" writer="myWriter3" processor="myProcessor3" commit-interval="100" />
                <next on="*" to="markAsProcessed" />
            <step id="markAsProcessed">
            	<tasklet ref="markAsProcessedTasklet"/>
                <next on="*" to="historyTasklet" />
            <step id="history">
            	<tasklet ref="historyTasklet" />
                <next on="*" to="ftpManagement" />
            <step id="ftpManagement" >
            	<tasklet ref="ftpTasklet" />

    It seems it open and close a transaction on each step. But i want one transaction for step1, step2, step3, "markAsProcessed" and history"
    If i have errors on step "history", how to rollback the step "markAsProcessed" and step2 ?

    Please need help.