Solved

transactions across DAO classes

Posted on 2004-03-25
8
214 Views
Last Modified: 2010-03-31
Hi,

I have an e-commerce application which has all kinds of data access objects which roughly relate to tables in hte database.

For example I have a customer table and an address table

These relate to my customer and Address objects which have CustomerDAO and AddressDAO objects associated with them.  Fine so far.

Each of the methods in my DAO objects open a connection to the database, do their thing (like an insert or an update) then release the connection.

The problem comes when I need to encapsulate the insertion of a customer and the insertion of an address into a transaction.  A transaction can not be done over more than one continuous connection (I think).  Should I be passing a connection object to these methods explicitly and only opening a new connection if it is null?

How do you do it?
Would EJBs help?
0
Comment
Question by:rosshind
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:Tommy Braas
ID: 10679297
>> How do you do it?
I assume that the Customer HAS-A Address, in which case, start a transaction, you insert/update the customer first, hand over control to the Address passing along the connection in some form (setConnection() perhaps, to keep it simple), and have the Address insert/update itself.

>> Would EJBs help?
Container managed persistence, if used, certainly would.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10679375
>>A transaction can not be done over more than one continuous connection (I think).  

The boundaries of a transaction are not really related to the connection. You mention EJBs. There is a case in point: not only are transactions not connection-related, they are not even process-related in that they can be distributed across process and even network boundaries.

It's the transaction object that would have to be passed around - sounds like you're getting into some farily complex wheel-reinvention here [unless you're now using third-party DAO] ;-)
0
 

Author Comment

by:rosshind
ID: 10685385
Thanks for your help,

I'm not sure how any third party technology could help.  Each of my DAO objcets is a custom object, I might want some ot work slightly differently to others.  

What kind of third party technology do you mean CJ?  What am I programming here  which has already been done for me by someone else?

Would you be using a third party DAO?

What are the fundamental differences between EJB and what I am doing? Can you referr me to a tutorial about the fundamentals of EJBs?  As you know, I'm not new to programming or to complex e-commerce sites,  but I've only really been doing JAVA for around 3 weeks ...
0
 

Author Comment

by:rosshind
ID: 10685556
From the sounds of it EJBs are the way to go.  I could continue my program with normal beans, but I recon it might work out more difficult and messy in the long run.  I may be better off learning EJBs  now before completing the first version of the software..  What do you think?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10686047
It's a possibility, although i think as we've said before (or at least 'ive said it ;-)) EJB is not really an 'escape route' out of persistence complexities. All you need seemingly is a persistence layer that supports transactions and O-R mapping by the sounds of things. That is already present in certain free packages, none of which i've used incidentally.

Having said that about EJBs, if you can take what will be a steep learning curve, these services, along with a host of other services are present as standard in EJB.

If you want to use EJB, you'll need an application server and unless you've got very deep pockets, we're talking about JBoss practically, which is free. The only slight problem is that free documentation is very thin on the ground and you probably need to pay for it. This is not highly priced though.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10696588
This may throw an interesting light on your investigations:

http://jdocentral.com/

http://jdocentral.com/JDO_Commentary_CraigRussell_1.html
0
 

Author Comment

by:rosshind
ID: 10697859
I've bought a dell server which is to be dedicated to this venture.  My pockets are empty now.

I've been on a steep learning curve for about 4 weeks learning JAVA.  I figure another week or two for EJB will be worth it in hte long term so that the first version can be using the best technology for the venture.

I've gone out and bought Enterprise JavaBeans by O'Reilly to help me get up to speed on this.  Thanks for your help.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10698090
8-)

>>...Enterprise JavaBeans by O'Reilly ...

Still keep meaning to do the JBoss exercises from that but haven't got round to it yet ;-)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now