Sorry about the confusion. I meant using
Torque.getConnection() and dbConn.close() instead of  
Transaction.begin()..

And if iI was. the following would work well? 


        Connection dbConn = null;
        try { 
                // get a connection from the pool
                dbConn =
Torque.getConnection(db2.torque.environment);
                ////Do Stuff
                //Commit the transaction 
                dbConn.commit();
        }
        finally {
                if (!dbConn.isClosed()) {
                        // some error occurred, try to rollback and return
connection to the pool
                        dbConn.close();
                        dbConn.rollback(); //Is this needed?
                }
        }

--- Thomas Fischer <[EMAIL PROTECTED]> wrote:

> Jim,
> 
> I'm not sure if you can "not use a transaction".
> E.g. in oracle, every sql
> select/update/delete/insert command automatically
> starts a transaction. The
> closest you can come to "not using transactions" in
> oracle is autocommit
> mode where every sql command is wrapped in its own
> transaction. I'm not
> sure what the situation is for DB2.
> 
> In my experience, you can use the same code without
> problems if you are in
> autocommit mode in oracle, but this may vary from
> database to database.
> From my oracle-based experience, I would try to use
> exactly the same code,
> and see if its works in all cases (with/without
> errors). Only if this does
> not work, I'd try to use Torque.getConnection() and
> dbConn.close() instead
> of Transaction.begin() and
> Transaction.commit()/Transaction.safeRollback.
> But to be sure, check the DB2 docs.
> 
>     Thomas
> 
> Jim Caserta <[EMAIL PROTECTED]> schrieb am
> 10.04.2006 16:54:28:
> 
> > Thomas,
> >
> > I see what you mean...
> >
> > I'm assuming I can take the same approach if I'm
> Not
> > using a Transaction. Correct?
> >
> > Jim
> >
> > --- Thomas Fischer <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> > >
> > > I am using the following code:
> > >
> > > Connection dbConn = null;
> > > try
> > > {
> > >     dbConn =
> > > Transaction.begin(db2.torque.environment));
> > >
> > >     ////Do Stuff
> > >
> > >     //Commit the transaction (Transaction.commit
> > > releases connection back
> > > to the pool)
> > >     Transaction.commit(dbConn);
> > >     dbConn = null;
> > > }
> > > finally
> > > {
> > >     if (connection != null)
> > >     {
> > >         // some error occurred, try to rollback
> and
> > > return connection to
> > > pool
> > >         Transaction.safeRollback(dbConn);
> > >         dbConn = null;
> > >     }
> > > }
> > >
> > > It is safer to use a finally block than a catch
> > > block. In some ugly cases,
> > > you get errors and not exceptions, and they are
> not
> > > caught by
> > > catch(exception). Also, the finally block works
> even
> > > if you return inside
> > > the block.
> > >
> > > I have also written some docs about this, but I
> have
> > > forgotten to commit it
> > > :-(.
> > >
> > >     Thomas
> > >
> > >
> > > Jim Caserta <[EMAIL PROTECTED]> schrieb am
> > > 10.04.2006 15:27:37:
> > >
> > > > Thomas,
> > > >
> > > > I was reading through this thread and I
> wantwed to
> > > be
> > > > sure what you are saying. Is the example below
> the
> > > way
> > > > we should be handling transactions? Thanks!
> > > >
> > > >
> > > > Connection dbConn = null;
> > > > try {
> > > >       dbConn =
> > > Transaction.begin(db2.torque.environment));
> > > >
> > > >       ////Do Stuff
> > > >       //Commit the transaction
> > > (Transaction.commit, should
> > > > release connection back to the pool
> > > >       Transaction.commit(dbConn);
> > > >       Transaction.safeRollback(dbConn);
> > > >    }catch(TorqueException e){
> > > >       try {
> > > >          Transaction.rollback(dbConn);
> > > >       } catch (TorqueException e1) {
> > > >          Transaction.safeRollback(dbConn);
> > > >       }
> > > >       }finally {
> > > >          if(!dbConn.isClosed()){
> > > >             Torque.closeConnection(dbConn);
> > > >          }
> > > >       }
> > > >
> > > >
> > > > --- Thomas Fischer <[EMAIL PROTECTED]>
> wrote:
> > > >
> > > > > Using commits/rollbacks without explicitly
> > > startung
> > > > > a connection may look
> > > > > unclean but does not cause any problems in
> > > practice
> > > > > (at least none known
> > > > > to me). The problem described seems to be
> the
> > > other
> > > > > way round: there is no
> > > > > rollback/commit where should be one.
> > > > >
> > > > >    Thomas
> > > > >
> > > > > On Mon, 27 Mar 2006, Greg Monroe wrote:
> > > > >
> > > > > > I did a quick wander thru the Torque code
> and
> > > saw
> > > > > one thing
> > > > > > that did not look right to me.  Here's
> some
> > > > > background first:
> > > > > >
> > > > > > All of the Torque Transaction handling is
> > > built on
> > > > > the
> > > > > > Transaction class. This is used primarily
> by
> > > the
> > > > > BasePeer
> > > > > > methods like doUpdate(Criteria) and the
> like.
> > > > > >
> > > > > > These methods are the ones that
> automatically
> > > wrap
> > > > > the
> > > > > > DB actions as a transaction with rollback.
> > > > > >
> > > > > > The first thing that didn't look right to
> me
> > > was
> > > > > that the
> > > > > > Transaction.beginOptional(dbName,
> > > useTransaction)
> > > > > method
> > > > > > is called with the useTransaction arg set
> to
> > > the
> > > > > value of
> > > > > > criteria.isUseTransation().  This value is
> set
> > > to
> > > > > false by
> > > > > > default.
> > > > > >
> > > > > > So, it seems that if you don't set this
> > > explicitly
> > > > > on your
> > > > > > Criteria, you are not using really using
> > > > > transactions but
> > > > > > you still have the Transaction try/catch
> code
> > > with
> > > > > commits and
> > > > > > rollbacks.
> > > > > >
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to