RE: Keel transaction support
"Hagerty, Timothy CIV NAVSAFECEN, 52D" <[email protected]>
| Newsgroups | gmane.comp.java.keel.user |
|---|---|
| Message-ID | <A87876CC4C70F349B0ED74EF9F4CA77604401921@NAEANRFKEX01VA.nadsusea.nads.navy.mil> |
Thanks a bunch Mike. This helps out a lot. Tim -----Original Message----- From: Michael Nash JGlobal.com [mailto:[email protected]] Sent: Friday, April 30, 2004 10:10 To: user-6VIttnCrOeJXNEnpj1eHPNi2O/[email protected] Cc: Hagerty, Timothy CIV NAVSAFECEN, 52D Subject: Re: [Keel User] Keel transaction support Tim: Keel won't do transaction handling by default, but with a slight change to your calls you can enable it: Before you access the persistent from your factory, do this: Transaction trx = pf.begin(); then do your add calls as normal, checking for any errors - something like this try { Persistent userPersistent = (Persistent) pf.create("xconfName.tableName"); userPersistent.setField(..... userPersistent.add(); .... userPersistent.add(); ... /* if we get here, all is well... */ trx.commit(); } catch (PersistenceException pe) { try { trx.rollback(); } catch (PersistenceException pe2) { ... report a problem rolling back... } ... report the error, say that we've rolled back... } Also, you might want to use just the Persistent interface, rather than casting all the way to DefaultPersistent. Your code will be a bit more portable that way, just in case you ever want to switch to a different persistence implementation. HTH! Mike On Fri, 30 Apr 2004 09:47:31 -0400 "Hagerty, Timothy CIV NAVSAFECEN, 52D" <[email protected]> wrote: > > All, > > I am doing a set of inserts into our database and I was wondering how keel handles transaction support. I am using the following to reference my connection: > > > PersistentFactory pf = (PersistentFactory) request.getService(PersistentFactory.ROLE, > request.getDomain()); > > > Then I use the following per each table I will be inserting into: > > DefaultPersistent userPersistent = (DefaultPersistent) pf.create( > "xconfName.tableName"); > > > If any of the inserts fail will keel handle the transaction and roll everything back? > > Thanks, > Tim > > > -- Michael Nash JGlobal Ltd Next-Generation Web Application Development and Open Source Support http://www.jglobal.com Bahamas Commerce and Trade Offshore eCommerce Hosting and Business Services http://www.bahamascommerce.com