Just to follow up on this:
My understanding is that Transaction.commit() and rollback() do the
right thing (ie, release the connection back to the pool). You can
confirm this, if you want, by looking at the Torque code - there's a
release called in the commit and rollback.
But the most common source of connection pool leaks is if you throw an
exception in the middle of a routine and therefore don't call commit or
rollback on the connection.
On the other hand, it probably won't make a difference unless you're
writing a server of some sort (ie, something that runs for a long time -
like a web-server.)
-Peter
On Fri, 2002-10-18 at 15:11, [EMAIL PROTECTED] wrote:
>
> I assume that Peter's way of getting a connection object works, but you can
> also get connection objects from the Transaction class.
>
> Connection conn = Transaction.begin(<TablePeer>.DATABASE_NAME);
> // do all your inserts, updates, deletes like Peter said, using the
> versions that pass in a connection
>
> //if everything is ok
> Transaction.commit(conn);
> //if something went wrong
> Transaction.rollback(conn); or Transaction.safeRollback(conn);
>
> To me, this seems more intuitive. (I'm hoping that the commit and
> rollbacks call releaseConnection() internally, I didn't know that we were
> supposed to do that until now, but I haven't had any problems yet...)
>
> - Tobin
>
>
>
>
>
>
> "Peter S. Hamlen"
>
> <[EMAIL PROTECTED] To: Turbine Torque Users List
><[EMAIL PROTECTED]>
> > cc:
>
> Subject: Re: Transactions
>
> 10/18/2002 11:24
>
> AM
>
> Please respond to
>
> "Turbine Torque
>
> Users List"
>
>
>
>
>
>
>
>
>
> Vera,
>
> This should be pretty straightforward. Assuming you're using the latest
> version of Torque, you'll notice that most calls that retrieve data have
> two versions - one that takes a java.sql.Connection object and one that
> doesn't.
>
> If you want to use transactions, you need to use the versions that pass
> in the Connection object. And then you have the usual semantics for
> commit and rollback.
>
> Begining transactions is simply a case of getting a Connection from
> Torque - and that is done by:
>
> Connection conn = Torque.getConnection();
>
> And then return the connection via Torque.releaseConnection(conn);
>
> BE SURE TO RETURN THE CONNECTION TO THE POOL WHEN YOU'RE DONE!
> Usually, the best way to do this something like:
>
> try
> {
> Connection conn = Torque.getConnection();
>
> }
> finally
> {
> try
> {
> Torque.releaseConnection(conn);
> }
> catch (TorqueException e)
> {
> // log the error - but generally we ignore
> // this case
> }
> }
>
> By placing the Release connection in the finally block, you are
> guaranteed that you won't get connection leaks - remember, Torque uses a
> connection pool and if you don't return a connection, it will linger
> unused and eventually you'll run out connections in your pool.
>
> -Peter
> On Fri, 2002-10-18 at 10:03, Vera Neupert wrote:
> > Hello,
> >
> > does anybody knows how I could manage my own Transactions. How to begin,
> > commit and rollback.
> >
> > Vera
>
>
>
> --
> To unsubscribe, e-mail: <
> mailto:turbine-torque-user-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail: <
> mailto:turbine-torque-user-help@;jakarta.apache.org>
>
>
>
>
>
>
>
> --
> To unsubscribe, e-mail: <mailto:turbine-torque-user-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail: <mailto:turbine-torque-user-help@;jakarta.apache.org>
>
--
To unsubscribe, e-mail: <mailto:turbine-torque-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:turbine-torque-user-help@;jakarta.apache.org>