Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Database Updates in EJB method

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone help me out ?
I am using Stateless session bean. In my bean, I call BO class which performs business validations and then , call Data Access Object class
(say, class A) .The class , A updates Db2 database table A, then, calls Data Access Object class B which updates database table B and class A then calls Data Access Object C which updates tables C.All the above are performed in the same DAO class A's method.

TheEJB method transaction attribute has been set to Required.

My question is can I pass the same connection from class A to class B and C. Or,is it good to use separate connections (fetched from the connection pool) in class A,B and C ?
I know both ways will work. Can someone say me which will be faster and better than the other.
Thanks in advance.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will go with separate connections.Establishing a database connection is a costly affair.But we are avoiding this by making a connection pool.So after each method call you can close the connection, it will go back to the pool and in the second method you can again request the pool to get you a connection.

Other advantage might be like the code will be cleaner.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rahul,

But what is it that you will benefit out of passing separate connection objects. Just for code cleanliness, I dont think it is wise to pass different objects. Tho you will be implementing a connection pool, other connection objects are not going to be waiting for this particular bean to complete. They might be used y other threads. If the whole process is in a single transaction, then I think we should pass the same connection object, while the Required Trans-attribute is fine.
 
Do you pee on your compost? Does this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic