Mark,
On 6/27/2016 1:07 PM, Mark Thomas wrote:
On 27/06/2016 17:44, Jerry Malcolm wrote:
I'm assuming that context.lookup(...) simply locates the "jdbc/myDB"
<Resource> tag in the context.xml file, pulls all of the parms out of
that tag, creates a DataSource object utilizing the parms, and returns
it. If that's the case, couldn't I create a variation/subclass of the
Context object that modifies the url parm that it found in the resource
tag and puts the desired db name into the url before constructing the
DataSource?
Sure.
You need to implement the appropriate factory and then specify your
factory class explicitly in the Resource element using the factory
attribute.
You probably want to start here for ideas on how to code up your factory:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/naming/factory/
or for a more specific example:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/dbcp/dbcp2/BasicDataSourceFactory.java?view=annotate
Mark
Thanks so much. This looks doable. Just to make sure I have the big
picture correct....
1) I will define a new custom resource that returns a custom context
object that I write.
2) On the <Resource> tag for my custom context resource I can put all of
the standard DataSource parms
3) I then call lookup() on this custom context passing the dbName in
4) This custom context will build an appropriate Reference object with
all the parms, instantiate a BasicDataSourceFactory, and call
getInstance(.....) on the factory.
When I need an instance of the datasource:
Context initContext = new InitialContext();
Context envContext =
(Context)initContext.lookup("java:/comp/env");
MyDataSourceContext dsContext = (MyDataSourceContext)
envContext.lookup( "dsContext/myDSContext" );
DataSource myDS = (DataSource) dsContext.getInstance( "dbName" );
Am I getting close?
Thx.
Jerry
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]