0

This involves using a JSR job, so I do not have access to use the tasklet definition in the job specification. The direction I've been given is to support only JSR 352 features as far as job specification goes.

Here is an example of a job:

<job id="xmlWriter" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<step id="firstStep">
    <chunk item-count="2">
        <reader ref="DelimitedFlatFileReader">
            <properties>
                <!-- Reads in from file Test.csv -->
                <property name="fileNameAndPath" value="#{jobParameters['readerFileNameAndPath']}" />
                <property name="fieldNames" value="firstName, lastName, city" />
                <property name="fullyQualifiedTargetClass" value="com.test.test.DatabaseMember" />
            </properties>
        </reader>
        <processor ref="com.test.test.ItemProcessor" />
        <writer ref="FlatFileWriter" >
            <properties>
                <property name="appendOn" value="true" />
                <!-- Read to file demoXMLReaderFlatFileWriterOutput.txt -->
                <property name="fileNameAndPath" value="#{jobParameters['writerFileNameAndPath']}" />
                <property name="fullyQualifiedTargetClass" value="com.test.test.DatabaseMember" />
            </properties>
        </writer>
    </chunk>
</step>

In the ItemProcessor I am interested in having some type of callback/listener that could trigger roll back for transactional items that occur inside it should the chunck for example fail during the write step.

So a good example would be I have some sort of db or jms operation that occurs in the ItemProcessor. If during the writer portion that chunck fails I would want to roll back all of those operations that occurred during the item processor that were part of this iteration (or several with item count > 1).

I have looked into the various listeners available based on the jsr spec and nothing seems to allow for this type of implementation. Also spring does not seem to wrap the processor in a transaction like it does when it is a true spring batch. Testing I did in creating db connections and testing them to see if they were transactional aware always returned false.

Is what I'm looking for even possible outside a entirely custom implementation and if so any guidance in how to accomplish it.

Mark Kouba
  • 236
  • 2
  • 12
  • This really isn't a question of listeners...it's a question of resources. If you're using multiple resources (a db connection and a JMS connection for example) and you want them to be transactional (participate in the same transaction), you need to use distributed transactions. Are you? – Michael Minella Aug 27 '15 at 19:18
  • I am not but i spent some time reading about these to understand how they might work. How would i tie transactional resources from the item processor to the over all transaction that is controlling the chunck rollback/commit. I am going to do some more reading see if i can figure that out but any info would be great. – Mark Kouba Aug 27 '15 at 22:14
  • I did finally figure out how to do this with an XA transaction manager. Using the tx:annotation-driven and defining a new transaction manager bean that was XA compliant. It still did not work quite like I expected, but in the end, because of some requirements that are out of my hands, could not end up using the solution. – Mark Kouba Sep 01 '15 at 13:57

0 Answers0