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

  • ChunkTransactionListener?

    Hi all,

    My use case is that I'm inserting a bunch of rows in a table in a chunk, and as part of the chunk's commit, I need to call a sproc that derives a bunch more (denormalized) data from the inserted rows.

    According to the ChunkListener interface, beforeChunk() is called after the chunk and its transaction start, and afterChunk() is called after the chunk is executed and the transaction is committed. Additionally, there's no Chunk/Step/JobExectution context passed into these methods. It's as though I need an interface called TransactionalChunkListener that looks like this:
    Code:
    public interface TransactionalChunkListener {
      public void beforeChunkBeforeTransactionStart(ChunkContext cx);
      public void beforeChunkAfterTransactionStart(ChunkContext cx);
      public void afterChunkBeforeTransactionCommit(ChunkContext cx); // this is the one I need
      public void afterChunkAfterTransactionCompletion(ChunkContext cx, boolean committed);
    }
    How do I achieve this in Spring Batch 2.1.x & later?

    -matthew

  • #2
    can't you use the ItemWriteListener interface?

    Comment


    • #3
      Originally posted by arno View Post
      can't you use the ItemWriteListener interface?
      That might be just the ticket! I didn't see that one. I'll let you know.

      Thanks,
      Matthew

      Comment


      • #4
        Yes. ItemWriteListener should do the job but remember the behavior that I noticed was that onWrite() method gets called for each item written to the target because my commit count was set to 1.

        Comment


        • #5
          Originally posted by tiger.spring View Post
          Yes. ItemWriteListener should do the job but remember the behavior that I noticed was that onWrite() method gets called for each item written to the target because my commit count was set to 1.
          Noted. Thanks.

          Comment


          • #6
            I think ItemWriteListener covers the use case as I understand it. I don't see enough value in a new listener interface yet, and you have to be very careful with transaction boundaries because other components are going to try and push their actions to the last moment before a commit as well, and you can't easily assume that your callback will be the very last thing to happen. You best bet is to just join the transaction in ItemWriteListener.

            Comment

            Working...
            X