This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing arguements to an EJB  RSS feed

 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering if there is a way to pass arguements to an EJB. Just like we would pass arguements to a class w/ a main...

java -blah com.blah.myClass options

What I am trying to get at here is. Our sys admin doesn't believe that grabbing a datasource out of JNDI is a viable option. Because the DS name is coded into some bean somewhere...

I know, if you want your DS to point at another DB, you just point connection url to another DB in your DS file. For instance oracle-ds.xml in JBoss.

Our sys admin isn't happy with just changing the *-ds.xml file. He is demanding that he is allowed to have 6 *-ds.xml files. Then somehow, we as programmers programatically tell the EJB's which file to use.

Has anyone done this before? To be truthful, I think this is a bit redundant. Building a config file to determine which *-ds.xml config file to use.

Besides putting logic into our UI to pass an arguement to a session bean to then get the proper data from a uber-config file, to then get the proper datasource. This approach in my opinion is prohibitive, it would involve alot of refactoring of code.

Any insights into this would be greatly appreciated.


Thank you.
 
Franck Smith
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that it's not a good idea to do that. EJB don't have to be linked with configurations files neither to chose wich JDBC URL use. EJB just point a Datasource (that the name can be configure in a property file) with its jndi name and the deployer have to change the connexion linked by this datasource if needed (It's its role). In JBoss indeed he have to change the datasource configuration file.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's get one thing straight: a DataSource should be used (and can be essential in some cases) and is best obtained from the JNDI tree. So, the sys admin has to support it.

He does not understand what EJBs are about. A basic design philosophy is that the Bean Provider, who writes the EJBs, is deemed to know nothing about the real JNDI name of the DB (and certainly won't know the real name of the DB). So, the BP makes up a fake JNDI name which is declared in the <resource-ref> element in the ejb-jar.xml deployment descriptor. The person who performs the Deployer role then maps the fake JNDI name to the real JNDI name under which the DataSource is registered in a vendor-specific way.

Your sys admin is making a big fuss about nothing. Typically, the only times the vendor file (like oracle-ds.xml) will need to change is during development and UAT because a different DB is needed, and even then it doesn't have to be done by him. It's not an issue during production as you won't normally change the DB.
 
Mark Spritzler
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill, basically everyone is correct. You sys admin doesn't understand the best practices of J2EE, and that actually using the Data Source, and just changing your JNDI properties file to switch between 6 xml files is actually the easiest approach for you and him, since you only change it in one place really fast.

Mark
 
Bill White
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everyone,

Thank you for your replies and insight. I knew that a programmatic approach to this was not the correct approach.

It is more then apparent that our Sys Admin does not understand what J2EE is all about.

I will be the first to admit that I don't know everything about J2EE (Who really does.) But, to give him the benefit of the doubt, I opted to come here to a community of experts, and see if this was a viable option.

Again, thank you, everyone.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!