aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Open Property File  from EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Open Property File  from EJB" Watch "Open Property File  from EJB" New topic
Author

Open Property File from EJB

Andrei Montchik
Greenhorn

Joined: Jul 02, 2002
Posts: 24
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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Jul 02, 2002
Posts: 24
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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Aug 29, 2002
Posts: 47
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

Joined: Jul 02, 2002
Posts: 24
Thank you, gentlemen. I think I will select BMP + DAO for current project.
Andrei Montchik.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Open Property File from EJB