Results 1 to 4 of 4

Thread: Single transaction, multiple requests using DataSourceTransactionManager subclass

  1. #1

    Default Single transaction, multiple requests using DataSourceTransactionManager subclass

    I'm hoping to discover if I am using the DataSourceTransactionManager in the proper way, as a base class to support long transactions that exist in our legacy system. Please don't tell me not to support long transactions across multiple requests, as this is not an option.
    This class also must support a time out mechanism; we have a subscriber that relies on a timeout implemented in our current architecture.

    My approach so far was to create a new Interface called SuspendablePlatformTransactionManager. (Perhaps this is not be the correct metaphor, since the original concept of transaction suspension, is to start a new transaction within the same workflow, and then resume the suspended transaction later down the line).
    The interface extends PlatformTransactionManager and has two additional methods
    Code:
    package com.choicehotels.cis.infrastructure;
    
    import org.springframework.transaction.PlatformTransactionManager;
    import org.springframework.transaction.TransactionStatus;
    import org.springframework.transaction.support.DefaultTransactionStatus;
    
    public interface SuspendablePlatformTransactionManager extends PlatformTransactionManager
    {
       
       public DefaultTransactionStatus suspendTransaction(DefaultTransactionStatus status);
       
       public DefaultTransactionStatus resumeTransaction(DefaultTransactionStatus status);
    
    }
    This gives the hooks available to the caller (a Servlet in the simplest case) to suspend, and later resume, in another thread, the transaction.

    I then created an extension to the DataSourceTransactionManager that also implements the interface.
    This class overrides doCommit, doRollback, doResume, doSuspend, and newTransactionStatus.

    At first I misunderstood the suspension process, and thought the suspend would occur on the currently running transaction, but this is not the case.
    It is the new transaction that has not "begun" yet that is the target in the doSuspend call.

    This led to a problem, in my code that would cause an NPE upon resumption of the existing transaction, since I was suspending the existing transaction object (which removes the connection holder from the transaction object)

    My workaround is to reattach the connection holder to the "suspended" transaction upon resumption, but I'm really hoping there is a better and more elegant way.

    Attached is the relevant code if anyone is interested in offering suggestions or alternatives.

    Thanks in advance
    Dan Shaw
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think this thread talked about a poor man's distributed transaction, which might be similar to what you're talking about.
    http://forum.springframework.org/showthread.php?t=34880
    Last edited by karldmoore; Aug 30th, 2007 at 05:48 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    Actually, the concept is not a bad idea, and might work for me..I'll definitely investigate more..

    The difference here, is that the "client" in our case are mostly web pages, or REST like services we provide, and the transaction begins and ends on our server.. any transactions occuring on the client, have nothing to do with our services.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by dan@danieljshaw.com View Post
    Actually, the concept is not a bad idea, and might work for me..I'll definitely investigate more..
    I'm not suggesting it is a bad idea. The thread I posted described it as a poor mans distributed transaction as it could have been replaced with a stateless session bean.
    Last edited by karldmoore; Aug 30th, 2007 at 05:48 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •