Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

some ejb-design issues  RSS feed

 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
In my application i am writing a mdb which recevies a message for insertion of data into database in which currently wht am i doing on the type of messages i am instantiaiing a java classes and with the help of those classes i am doing inserting via entity beans.
do u think this is the correct way of doing it,instead of classes can i write session bean (calling entity beans)for insertion of data into data base.
pls do tell me the advantage for both the approaches as well as disadvantages of the same .
help needed very fast...
Rishi
 
Paul Rhoades
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like you're doing the right thing. You might want to consider the following.
a) If you want to use declarative transactions (i.e. defined by the deployment descriptor) then you need to use Session Beans as well.
b) Session Bean will run slower than Java Helpers so if you don't need the transaction, security, RMI, etc. features then there's no need to use them.
c) If you write the Helper classes to be thread safe then you can turn them into singeltons and cache them for reuse. Otherwise any caching will need to employ a pooling mechanism and get very complex.
d) Try to keep business logic out of the MDB, limit the MDB to message decoding only. That way if you need a synchronous interface to the business logic you can use Session Beans calling the same helper classes as the MDBs.
Good Luck
Paul.
 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul
see i need transaction in our design how do i achive with java helper classes
Rishi
 
Paul Rhoades
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three fundamental approaches to implementing transactions within a J2EE application, though different App. Servers support different levels of functionality.
Declarative Demarcation : basically you detail in your deployment discriptor whether a method should constitute atransaction and the app server will do the rest(ish).
JTA Transactions : you use the J2EE JTA API and include create, begin, commit, rollback transactions calls within your code.
JDBC Transaction : you use JDBC specifics (depends on your JDBC driver) to begin, commit, rollback your transactions.
I use WebLogic which is pretty feature rich but you'll need to check you App. Server / EJB Container documentation for issues such as distributed transactions, isolation levels etc.
If you're not using EJB's to encapsulate your transactions then I'd recommend using JTA instead of JDBC, which goes something like (for WebLogic anyway)...
UserTransaction tx = (UserTransaction) ctx.lookup("javax.transaction.UserTransaction");
tx.begin();
// database stuff
tx.commit(); or tx.rollback();
For a good overview of tranactions have a look at JavaWorld, in fact I go here whenever I get stuck (not sure if the JavaRanch boys will appreciate me saying that, but on the other side I prefer JavaRanch for discussion groups...)
http://www.javaworld.com/javaworld/jw-07-2000/jw-0714-transaction.html
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Rhoades:
For a good overview of tranactions have a look at JavaWorld, in fact I go here whenever I get stuck (not sure if the JavaRanch boys will appreciate me saying that, but on the other side I prefer JavaRanch for discussion groups...)

That's disgraceful...
Just kidding, I use a whole bunch of sources as it's gives a much broader range of opinions, techniques and best practices, including TheServerSide, OnJava, JavaWorld and jGuru. You're right though, for discussion you can't beat JavaRanch - probably the largest independent Java site in the web.
Simon
"One of the JavaRanch Boys"
[ August 02, 2002: Message edited by: Simon Brown ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!