Proposal: Automatic Resource Management

Neal Gafter neal at gafter.com
Tue Mar 3 23:37:37 PST 2009


On Tue, Mar 3, 2009 at 9:53 PM, Bob Lee <crazybob at crazybob.org> wrote:
>> , transactions that can either
>> be committed or rolled back, etc, without requiring the language
>> commit itself to a single pattern.
>
> The current proposal supports existing transaction approaches just fine.
> Either your API auto-commits (in which case you roll back if someone calls
> setRollbackOnly() on the resource), or you have to explicitly commit:
>
>   try (Transaction t = ...; TransactionalResource tr = ...) {
>     // do some stuff w/ tr
>     ...
>     t.commit();
>   }
>
> If you don't commit(), the tx gets rolled back.

Bob-

java.sql.Connection has three methods (among others):
  commit() - to cause the transaction to take effect
  rollback() - to undo the transaction
  close() - to close the connection

Using the construct as you suggest closes the connection - not
necessarily a good idea, and not the point of the example.  The point
is to commit() when the controlled statement completes normally, and
rollback() when it terminates abnormally, without the programmer
having to add further boilerplate.  BGGA enables frameworks to provide
an API that makes this as easy as if a purpose-built statement were
available, but the present proposal appears to require boilerplate in
each client.



More information about the coin-dev mailing list