Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open Property File from EJB

 
Andrei Montchik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I want to separate SQL statements from EJB and place them to property file. After that I would read this file and find appropriate SQL statement by property name.
Is there the best way how to do this? I do not want to invent a bicycle at this time. :-)
Thanks,
Andrei Montchik.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess my first question would be:
If you are going to go thru all this trouble to separate the SQL from your EJBs, then why not use CMP?
If you decide not to use CMP then you could always read in the SQL statements as EJB Environment variables. This would mean writing your SQL in the EJBs deployment descriptor (ie the poor man's CMP).
 
Andrei Montchik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Chris.
I decided to use BMP because CMP is not very good technology to work with databases (IMHO).
SQL in deployment descriptor should be written for each EJB. Unfortunately, there are no context-params in ejb-jar.xml like in web.xml. And it will make descriptor more difficult to read after including a few dozens of SQL statements.
To be honest with you, I am not sure that it is a good idea to separate SQL from EJB. I just wanted to hear proffesional opinion about this approach.
Thank you,
Andrei Montchik.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My 02 cents:
Go with CMP. It will get you 80% to 90% of the way there. Use Session Beans + DAO for the other 10% to 20% and don't worry about separating the SQL. It is unlikely that separating the SQL is going to gain you anything in the future.
Alternatively, go JDO behind a Session Facade and scrap CMP altogether.
 
Christian Ebage
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are using BMP, you could use a Data Access Object(DAO) to encapsulate the SQL. This reduces coupling of the EJB with the SQL code in the bean.
Ebage
SCJP
SCEA
[ November 06, 2002: Message edited by: Christian Ebage ]
[ November 06, 2002: Message edited by: Christian Ebage ]
 
Andrei Montchik
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, gentlemen. I think I will select BMP + DAO for current project.
Andrei Montchik.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Chris - opting for CMP will probably get you where you want to be much, much quicker. Then there are the added performance benefits too. We adopted a mix of CMP and session beans + DAO (for complex reads) in a recent project and it worked really well.
If you are trying to acheive separation between the EJB layer and the SQL, then DAOs are great. However, should you need to change the SQL, you'll probably have to change not only the DAO, but also the BMP EJB and any value objects that you pass between tiers.
If you do choose to put the SQL in a properties file, the easiest way to load that file is through the classpath.
Just my additional $0.02...
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic