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

  • Transaction Management

    Hello,

    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

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

    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.

    Comment

    Working...
    X