db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: Torque Connection pool .. ORA- 01453 - Set Transaction must be the first statement
Date Mon, 10 Apr 2006 20:41:39 GMT
One other minor gotcha for error tracking is that in some
very rare instances, the error is actually thrown as a 
subclass of Throwable rather than Exception. I haven't 
seen this for a while, but some JDBC drivers used to do 
this.  

So, if you want to make sure to catch every error, you 
should use:

}
catch (Throwable t) 
{ ...


> -----Original Message-----
> From: Thomas Fischer [mailto:tfischer@apache.org] 
> Sent: Monday, April 10, 2006 4:30 PM
> To: Apache Torque Users List
> Subject: RE: Torque Connection pool .. ORA- 01453 - Set 
> Transaction must be the first statement
> 
> 
> You can use catch and finally simultaneously.
> 
> try
> {
>    doSomething();
> }
> catch (Exception e)
> {
>    logError(e);
> }
> finally
> {
>    closeResources();
> }
> 
> You can also use several catch blocks.
> 
>     Thomas
> 
> On Mon, 10 Apr 2006, Jim Caserta wrote:
> 
> > One last item..
> >
> > I can see using ther finally's as we discussed,
> > however I can also see using the catches if I want to
> > handle different exceptions in different ways.
> >
> > If I don't use them, I will have no idea what error
> > messages to log.
> >
> > Don't you have the same issue?
> >
> > Jim
> >
> > --- Thomas Fischer <tfischer@apache.org> wrote:
> >
> >> It helps if an error occurs in the doStuff() part,
> >> because the transaction
> >> is closed properly. As a further benefit, all 
> updates/inserts since 
> >> the last commit/rollback (which is hopefully at the
> >> point where you last
> >> returned the connection to the pool) are reverted.
> >> If no errors occur, the rollback does not hurt,
> >> because it is after the
> >> commit.
> >>
> >> By the way, I just committed the documentation page
> >> about transactions and
> >> connections. See
> >>
> >>
> > 
> http://svn.apache.org/viewcvs.cgi/db/torque/runtime/trunk/xdocs/refere
> > nce/connections-transactions.xml?view=markup
> >>
> >>     Thomas
> >>
> >> On Mon, 10 Apr 2006, Jim Caserta wrote:
> >>
> >>> Exactly how does that rollback help at that point
> >> of
> >>> the code Thomas?
> >>>
> >>> --- Thomas Fischer <tfischer@apache.org> wrote:
> >>>
> >>>> The code now looks good. It's fine to rollback
> >> after
> >>>> you do the commit.
> >>>>
> >>>>     Thomas
> >>>>
> >>>> On Mon, 10 Apr 2006, Jim Caserta wrote:
> >>>>
> >>>>> So if I'm using the following code below,
> >>>>> My question is:
> >>>>> Even if the connection is fine and the database
> >>>> logic
> >>>>> does it's stuff correctly (Do Stuff)..
> >>>>> And the connection is NOT closed. It's ok to do
> >>>> the
> >>>>> "rollback" since the commit worked fine also.
> >>>> correct?
> >>>>>
> >>>>> 	Connection dbConn = null;
> >>>>> 	try {
> >>>>> 		dbConn = 
> Torque.getConnection("db2.torque.environment");
> >>>>> 		////Do Stuff
> >>>>> 		dbConn.commit();
> >>>>> 	}
> >>>>> 	finally {
> >>>>> 		if (dbConn == null)	{
> >>>>> 			//Connection error logic
> >>>>> 		}
> >>>>> 		if (!dbConn.isClosed()) {
> >>>>> 			dbConn.rollback();
> >>>>> 			dbConn.close();
> >>>>> 		}
> >>>>> 	}
> >>>>>
> >>>>> --- Thomas Fischer <fischer@seitenbau.net>
> >> wrote:
> >>>>>
> >>>>>>
> >>>>>> Jim Caserta <smoothie_jc@yahoo.com> schrieb am 10.04.2006

> >>>>>> 17:40:05:
> >>>>>>
> >>>>>>> Sorry about the confusion. I meant using
> >>>>>>> Torque.getConnection() and dbConn.close()
> >>>> instead
> >>>>>> of
> >>>>>>> Transaction.begin()..
> >>>>>>
> >>>>>> For any DB which supports transactions:  _Make
> >>>> sure_
> >>>>>> that the connection is
> >>>>>> in autocommit mode or use Transaction.begin and
> >>>>>> Transaction.commit() or do
> >>>>>> both. If you do not commit/rollback and are not
> >>>> in
> >>>>>> autocommit mode you can
> >>>>>> run into ugly trouble (e.g. if the transaction 
> serialization is 
> >>>>>> read committed, other connections will never see the
> >>>>>> changes to the data in the
> >>>>>> uncommitted transaction and the like).
> >>>>>>
> >>>>>>> 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?
> >>>>>>>       }
> >>>>>>>    }
> >>>>>>
> >>>>>> This is similar to an earlier version I used
> >> some
> >>>>>> time ago. The problem is
> >>>>>> it would throw a NullPointerException in the
> >>>> finally
> >>>>>> block if
> >>>>>> Torque.getConnection() fails. Also, you should
> >>>>>> rollback() before you
> >>>>>> close().
> >>>>>>
> >>>>>> Whatever code you use in the end, make sure
> >> (i.e.
> >>>>>> _test_) that an error in
> >>>>>> retrieving/working with the connection is
> >> handled
> >>>>>> correctly.
> >>>>>>
> >>>>>>       Thomas
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>
> >>>
> >>
> > 
> ---------------------------------------------------------------------
> >>>>>> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> >>>>>> For additional commands, e-mail:
> >>>>>> torque-user-help@db.apache.org
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >> __________________________________________________
> >>>>> Do You Yahoo!?
> >>>>> Tired of spam?  Yahoo! Mail has the best spam
> >>>> protection around
> >>>>> http://mail.yahoo.com
> >>>>>
> >>>>>
> >>>>
> >>>
> >>
> > 
> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail:
> >>>> torque-user-unsubscribe@db.apache.org
> >>>>> For additional commands, e-mail:
> >>>> torque-user-help@db.apache.org
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>
> > 
> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail:
> >>>> torque-user-unsubscribe@db.apache.org
> >>>> For additional commands, e-mail:
> >>>> torque-user-help@db.apache.org
> >>>>
> >>>>
> >>>
> >>>
> >>> __________________________________________________
> >>> Do You Yahoo!?
> >>> Tired of spam?  Yahoo! Mail has the best spam
> >> protection around
> >>> http://mail.yahoo.com
> >>>
> >>>
> >>
> > 
> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >>> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>>
> >>>
> >>
> >>
> > 
> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> torque-user-unsubscribe@db.apache.org
> >> For additional commands, e-mail:
> >> torque-user-help@db.apache.org
> >>
> >>
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
> 
> 

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message