Re: Keel transaction support

Jeff Richley <jeffrichley-/[email protected]> Sat, 1 May 2004 08:44:44 -0700 (PDT)
Newsgroups gmane.comp.java.keel.user
Message-ID <[email protected]>
I was also noticing that there is a setTransaction()
method in persistent and that it seems to use it in
DefaultPersistent if you set it.  So would we do
something like this:

// get the persistent and add stuff to it
myPersistent.setTransaction(trx);
myPersistent.add();


--- "Michael Nash JGlobal.com" <[email protected]>
wrote:
> 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
> 
> _______________________________________________
> User mailing list
> [email protected]
>
http://lists.keelframework.org/listinfo.cgi/user-keelframework.org



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover