Results 1 to 7 of 7

Thread: Declarative flush as transactionAttribute???

  1. #1
    Join Date
    Sep 2004
    Posts
    346

    Default Declarative flush as transactionAttribute???

    Is there some feature that allows a declarative flush as a transactionAttribute similar to PROPAGATE_REQUIRED???

    i.e FLUSH_MANDATORY

    This way if I call several service methods within on transaction I can declaratively cause a flush to check for successful insert.

    i.e:

    service1: /* transaction begins */
    try {
    call service 2
    } exception {
    check for exception i.e: a db insert failed due to constraint
    }
    call service 3
    /* transaction ends */

    in this example

    service 1,2 & 3 are proxied by TransactionProxyFactoryBean
    and the transaction attributes on 2 cause flush.

    In the real example I am trying to implement there is no service 1 and the code is as follows. Service 2 & 3 are transaction proxied normally but because transaction is already started the parent transaction is used:
    Code:
    TransactionStatus transaction 
       = getTransactionManager().getTransaction(
            new DefaultTransactionDefinition());
    
    call service2
    call service 3
    
    getTransactionManager().commit(transaction);

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    There's no way right now to force a flush. As you say, if there's an existing transaciton it's just joined. Is there something stopping you from actually doing a manual flush? This is what is normally done (inside or outside spring) by code that doesn't know if it's running as part of an existing transaction or not...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Sep 2004
    Posts
    346

    Default It would be just cleaner to do it declaratively

    It would be just cleaner to do it declaratively. Why is that facility not available? Is there some other way to approach this problem?

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    For one thing, flushing is not a transactional aspect. How do you actually flush, in terms of an abstraction that works across all the technologies. i.e. something like HibernateTransactionManager could know how to flush hibernate sessions, but what about JDBC access on the same connection, and what about when you switch to JTATransactionManager.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Sep 2004
    Posts
    346

    Default continued

    Well the transaction manager itself relies on transactionAttributes to decide what it supports and what it can do. In the case of JDBC the JDBCTransaction manager would simply ignore the flush attribute....

  6. #6
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    It's an interesting idea. I agree with Colin that it doesn't really belong in with declarative transaction management, but you could write your own aspect that you apply as a pre or post interceptor using TransactionProxyFactoryBean, or however you drive Spring declarative transactions.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  7. #7
    Join Date
    Sep 2004
    Posts
    346

    Default Could you provide an example...

    Could you provide an example?

Similar Threads

  1. Programmatically rollback a declarative transaction
    By george in forum Architecture
    Replies: 10
    Last Post: Jun 15th, 2007, 01:39 PM
  2. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  3. Replies: 4
    Last Post: May 4th, 2005, 01:40 PM
  4. Replies: 10
    Last Post: Nov 2nd, 2004, 09:38 AM
  5. Declarative Transaction while using JOTM
    By schiremath in forum Data
    Replies: 1
    Last Post: Aug 22nd, 2004, 05:26 AM

Posting Permissions

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