Re: Keel transaction support

"Michael Nash JGlobal.com" <[email protected]>
Newsgroups gmane.comp.java.keel.user
Organization JGlobal
Message-ID <20040430101008.3e030498@jglobal>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.