Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Best Practice / pattern for coding for transactions

Thread view: 
js - 17 Nov 2006 03:31 GMT
Is there a best practice / pattern for coding for transactions outside of an
J2EE container so that the code could be easily adapted to
Container-Managed Transactions ?
richardsosborn@gmail.com - 18 Nov 2006 22:29 GMT
I would think some of this would be done easily in Spring framework.
I haven't looked real close at their API for tranx, but it seems like
it would
be a good start.

Sun's forums and tutorials has some examples I think.

> Is there a best practice / pattern for coding for transactions outside of an
> J2EE container so that the code could be easily adapted to
> Container-Managed Transactions ?
Mark Jeffcoat - 19 Nov 2006 10:08 GMT
> I would think some of this would be done easily in Spring framework.
> I haven't looked real close at their API for tranx, but it seems like
> it would
> be a good start.

I'm using Spring's transaction and JDBC management
on my current Big Project. It works good, but I'm
not sure it's compelling enough to recommend that
someone adopt the whole framework just for that.

(If someone asks nicely, I'll tell the story of the
home-brewed transaction management code written by an
earlier developer on this project, a Certified Java
Architect. Sadly, he'd made it through the certification
project (and xx years of experience) without actually
understanding what a transaction was, which made that
module a fabulous source of hilarious party stories.
Parties that didn't have quite enough girls and beer.)

Signature

Mark Jeffcoat
Austin, TX

Tom Forsmo - 22 Nov 2006 16:32 GMT
> (If someone asks nicely, I'll tell the story of the
> home-brewed transaction management code written by an
[quoted text clipped - 4 lines]
> module a fabulous source of hilarious party stories.
> Parties that didn't have quite enough girls and beer.)

Please share. Its always interesting to hear others use of technology,
because one might learn from it.

tom
Mark Jeffcoat - 22 Nov 2006 20:30 GMT
>> (If someone asks nicely, I'll tell the story of the
>> home-brewed transaction management code written by an
[quoted text clipped - 7 lines]
> Please share. Its always interesting to hear others use of technology,
> because one might learn from it.

I made the offer in a mildly mean-spirited kind of
mood. That having passed, I'll try to tell the story
with minimal sarcasm:

  The Developer Who Almost Understood Databases

  Once upon a time, I inherited a medium-sized Java project,
  around 30,000 lines of code. After a few minutes of poking
  around, I realized that 9,600 of those lines were in a
  single class, the DataMaster. (No names have been changed
  to protect anyone, as they started out generic enough.)

  Every method in the DataMaster started and finished with the
  exact same copy-and-pasted boiler-plate: The method would
  open a new Connection to the database, do its own query and
  update thing, and close the Connection.
 
  Now, aside from being ridiculously verbose and slow, this
  strategy worked. There were some odd bits of data corruption
  here and there, but hey, Programming is Hard, and These
  Things Happen.

  In the course of ripping all this out, enlightenment struck:
  Occasionally, one method in the DataMaster would call another.
  Unfortunately, as both methods were using the same open/close
  boilerplate, they were working in completely different Connections,
  and the underlying database's transaction management was shielding
  the one from the other's necessary updates.

  Ooops.

  Go ye and do not likewise.

(Readers are invited to draw their own moral from
this tale, and decide for themselves whether or not
my claim that the developer in question "didn't
understand what a [database] transaction was" was
justified.)

Signature

Mark Jeffcoat
Austin, TX

js - 19 Nov 2006 23:42 GMT
> I would think some of this would be done easily in Spring framework.
> I haven't looked real close at their API for tranx, but it seems like
> it would
> be a good start.
>
> Sun's forums and tutorials has some examples I think.

I can't really use Spring for now. There's still debate about it internally
here. Furthermore, a lot of non-Spring users "don't get it" straight
away ... The mindset has to be changed, and I think that the introduction
does not give it justice.

       http://www.theserverside.com/news/thread.tss?thread_id=38767
js - 20 Nov 2006 00:05 GMT
>> I would think some of this would be done easily in Spring framework.
>> I haven't looked real close at their API for tranx, but it seems like
[quoted text clipped - 9 lines]
>
>         http://www.theserverside.com/news/thread.tss?thread_id=38767

Just to clarify, I know that Spring has declarative transactions, ... but
has anyone gone from using Spring+Hibernate to moving the code to a J2EE
environment ( EJB 3.0 using Java Persistence ... similar to Hibernate ) ?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.