I'd like to propose a change to the Transaction API, for the purpose 
of making the standard try/catch/finally idiom a bit cleaner. What I 
would like is for the idiom to look like:

Session s = factory.openSession();
try {
        //instantiate a new Transaction object, begin the transaction
        s.beginTransaction();  
        
        // do some work
        ....
        
        // commit the transaction
        s.transaction().commit();
}
catch (Exception e) {
        // attempt to roll back the transaction
        s.transaction().attemptRollback();
        throw e;
}
finally {
        s.close();
}

This will require the following changes:

1. Change Session.beginTransaction() to keep a reference to the new 
   Transaction instance the Session.
   
2. Add Session.transaction(). This method returns the Transaction 
   object currently associated with the Session.

5. Add attemptCommit() and attemptRollback() methods to Transaction.
   Rather than throwing an exception, these methods return boolean 
   to indicate success or failure. In particular they return false 
   if we did not successfully begin the transaction in the first place.

6. Add Transaction.getLastException() to return any exception that
   was squashed.


Suggestions? Votes?


---------------------------------------------------------------------
NEW to mBox, receive faxes to any email address!
Find out more http://www.mbox.com.au/fax


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to