dear all,
i have a question about running multiple identical
database in an ASP (application service provider) environment.
we currently use stateless session beans only and
handle database connection pooling ourselves.
this allows us to have a single ejb server
connection to 1 of several identical databases.
new clients have a new database created for
them, and their config information entered into our own config
file.
based on their login, we run the ejb method using a
connection from a connection pool pointing at their db.
how would we do the equivalent to this if we were
to rewrite some parts of the system as entity beans?
the problem is that i can't see how their login
information would get propagated down to entity bean level so that i could get a
reference to the correct datasource. it's easy enough when you're just using
SLSB's.
e.g. pseudo code for what we do
currently.
public someMethod( Identity id )
{
get
connection from pool based on id.databaseId
pass the
connection down as a parameter to each method that requires db
access
return
connection to pool
}
how would this work with entity beans?
e.g. dodgy code, but just to show you roughly what
i mean.
private Connection getConnection() throws
SQLException, RemoteException {
DataSource ds =
null;
// <<<Somehow get db
that user should be accessing here>>>
// e.g. int databaseId =
entityContext.getDBId()
try {
Context ic = new InitialContext(); ds = (DataSource)ic.lookup( "jdbc/MyAppDS" + databaseId ); } catch(NamingException e) { e.printStackTrace(); throw new RemoteException("Could not obtain DataSource: " + e); } return ds.getConnection(); } thanks,
greg.
|