For Programmers: Free Programming Magazines  


Home > Archive > Java Help > July 2004 > EJB Problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author EJB Problem
Gabriel Epeldegui

2004-07-24, 3:56 am

Hi all!

I have a question:

I have a EJB (stateless). This EJB needs to access a data base via a
DataSource. The DataSource is variable and therefore that it invokes to
the EJB it is the one who informs to him as it is the DataSource.

My question is: How I can pass dynamically object DATASOURCE to the
EJB with no need to pass it like parameter of a method?. I can do using
it the context?

For example:

public class EJBInvoker {

public someMethod(DataSource ds) throws Exception {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");

props.put("MyDataSource", ds);

InitialContext ctx = new InitialContext(props);
MyHome home = (MyHome)ctx.lookup("MyEjb");
My my = home.create();

my.someMethod();
}


}

....

and the EJB:

public class MyEjb extends SessionBean {

private transient SessionContext context;

....

public void setSessionContext(SessionContext context) {
this.context = context;
}

....

public void someMethod()
{
// ?? (getEnvironment() is deprecated)
Properties props = this.context.getEnvironment();
DataSource ds = (DataSource)props.get("MyDataSource");

doOperation();
}
}

I can do something like that?.

Another alternative could be to assign a common method called
setDS(DataSource), but I prefer something like the raised thing previously.

excuse my English.

Any suggestions?

Thanks in advance.

PD: My application server is weblogic 6.1

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com