Are you trying to transport a connection pool from one VM to another?
DBCP is not designed to support this.
Its JNDI implementation is for container like deployment where the container create and binds the pool and the (web)application does the lookup.


-- Dirk

MALET, CREIGHTON C (SBCSI) wrote:

[Repost - should have gone to the mailing list.]

Here is what I'm doing, no doubt wrong, which is why I was hunting for
an example:

Server side:
                SharedPoolDataSource connectionPoolO = new
SharedPoolDataSource();
                try {
                          DriverAdapterCPDS opds = new
DriverAdapterCPDS();
        
opds.setDriver("oracle.jdbc.driver.OracleDriver");
        
opds.setUrl("jdbc:oracle:thin:@somehost.sbc.com:1521:dbname");
        
connectionPoolO.setConnectionPoolDataSource(opds);

                          InitialContext ic = new InitialContext();
                                // Factory is:
com.sun.jndi.fscontext.RefFSContextFactory
                          ic.bind("jdbc/oDS", connectionPoolO);
                }
                catch ...

Client side
                try {
                        InitialContext aic = new InitialContext();
                        DataSource ds = (DataSource)
aic.lookup("jdbc/oDS");
                        connection = ds.getConnection("name",
"password");
                        ...

When I run the client this I get:

javax.naming.NamingException: unexpected exception.  Root exception is
java.lang.InstantiationException:
org/apache/commons/dbcp/datasources/InstanceKeyObjectFactory
        at java.lang.Class.newInstance0(Native Method)
        at java.lang.Class.newInstance(Class.java:262)
        at
javax.naming.spi.NamingManager.getObjectFactoryFromReference(NamingManag
er.java:158)
        at
javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:311)
        at
com.sun.jndi.fscontext.RefFSContext.lookup(RefFSContext.java:146)
        at com.sun.jndi.fscontext.FSContext.lookup(FSContext.java:127)
        at javax.naming.InitialContext.lookup(InitialContext.java:359)
        at com.sbc.cm2159.ds.BOTHWorker.doOr(BOTHWorker.java:74)
        at com.sbc.cm2159.ds.BOTHWorker.run(BOTHWorker.java:47)
        at java.lang.Thread.run(Thread.java:512)

I debugged this to the getReference() method in InstanceKeyDataSource

public Reference getReference() throws NamingException {
Reference ref = new Reference(getClass().getName(), InstanceKeyObjectFactory.class.getName(), null);
ref.add(new StringRefAddr("instanceKey", instanceKey));
return ref;
}


- the factory is specified as InstanceKeyObjectFactory.class.getName()
which is what the JNDI API is trying to instantiate but the class is
abstract.

So I extended InstanceKeyDataSource and InstanceKeyObjectFactory to
overrride the getReference() method and the isCorrectClass() method that
verifies the datasource class. I use an extension of
SharedPoolDataSourceFactory as the factory and it all works great.  But
probably not as designed.

o this may be something to do with the InitialContextFactory
implementation - I'm using SUN's file based JNDI to test - probably
would normally use LDAP.
o I don't know if anything is necessarily wrong - it may be what I'm
doing - which is why I was looking for an example that did a bind in
JNDI.

Thanks

------------
Creighton Malet
SBC Services, Inc.
(925)823-1463
[EMAIL PROTECTED]


-----Original Message-----
From: Dirk Verbeeck [mailto:[EMAIL PROTECTED] Sent: Wednesday, June 09, 2004 9:51 AM
To: Jakarta Commons Users List
Subject: Re: [DBCP] Example of SharedPooledDataSource with JNDI



If you send me what you have already then maybe I can help you.
I did some debugging with the JNDI setup in Tomcat but not yet in a standalone program.


So if you start with the testcase then I'll take a look at it.

-- Dirk

MALET, CREIGHTON C (SBCSI) wrote:

Where can I find an example of the use of SharedPooledDataSource with
JNDI?

In my attempts at this I get an exception from the JNDI API because
InstanceKeyDataSource (from which SharedPoolDataSource inherits the
implementation of Referenceable) specifies in the getReference()

method

that
InstanceKeyObjectFactory is the factory. However that is an abstract
class and cannot be instantiated by the JNDI API implementation. I
worked around this by extending SharedPoolDataSource to overload
getReference() and SharedPoolDataSourceFactory to overload
isCorrectClass() but that doesn't seem like the correct mechanism. I

am

using DriverAdapterCPDS as the connection pool datasource for
SharedDataSource.

A example (with binding to JNDI) would help a lot. I have gone through
all the examples I can find but haven't seen one that actually binds
into the JNDI.

Thanks

------------
Creighton Malet
(925)823-1463
[EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to