If you were to use the Spring Framework you could write a new Dao, LoggingDao, to handle inserts of your logging statements and define that the LoggingDao gets a new transaction as opposed to participating within the current transaction. This would suspend any current transaction and begin a new Transaction that would operate outside of your existing transaction and would cause your logging inserts to always commit, but you would need to decide if this were to occur before or after the execution of your other database activities.
 
If you want to get really fancy and clean, you would write an interceptor (Before Advice) that would perform the insert, using LoggingDao, before the other statements get executed. That way there is no need to place this logging mechanism within your code at all. (Separation of concerns)


From: "rs"<[EMAIL PROTECTED]> [mailto:"rs"<[EMAIL PROTECTED]>]
Sent: Thursday, May 04, 2006 4:08 PM
To: [email protected]
Subject: A separate transaction for the logger


Hi,

Am using a single static instance of SqlMapClient for all my DAOs. There's a need to save some logging info into the database regardless if the application logic fails or not, i.e. there is a need to start a separte transaction for logger.

Illustration:

// application logic
...
SQL_MAPPER.startTransaction();
// do some stuff
...
//-----------> log current app status
//
// 1) start a new transaction for logger
// 2) log the status
// 3) commit and end logger transaction
...
// application error here but the status has been saved and committed
...
SQL_MAPPER.endTransaction();


So the question is how to start a new separate transaton for the logger. I'm thinking about building a separate instance of SqlMapClient just for logger operations but maybe there's a better way.

Thanks









_______________________________________________
No banners. No pop-ups. No kidding.
Make My Way your home on the Web - http://www.myway.com



Reply via email to