Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

UCP PoolDataSourceImpl with ConnectionInitializationCallback

andymcApr 8 2014 — edited Oct 15 2014

Hello,

I am attempting to configure a UCP PoolDataSourceImpl with a ConnectionInitializationCallback.  Here's my configuration:

private static DataSource createDataSource(Properties properties) throws SQLException, UniversalConnectionPoolException {

        UniversalConnectionPoolManager ucpm = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();

        PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource();

        final String editionName = properties.getProperty("jdbc.editionName", "ora$base");

        pds.registerConnectionInitializationCallback(new oracle.ucp.jdbc.ConnectionInitializationCallback() {

            public void initialize(Connection connection) throws SQLException {

                LOG.debug("Attempting to set edition to: {}", editionName);

                try (Statement statement = connection.createStatement()) {

                    statement.executeUpdate("ALTER SESSION SET EDITION = " + editionName);

                }

                LOG.debug("Edition set to: {}", editionName);

            }

        });

        pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");

        pds.setUser(properties.getProperty("jdbc.username"));

        pds.setPassword(properties.getProperty("jdbc.password"));

        pds.setURL(properties.getProperty("jdbc.url"));

        pds.setConnectionPoolName("demo-pool");

        pds.setInitialPoolSize(3);

        pds.setMaxPoolSize(3);

        pds.setValidateConnectionOnBorrow(true);

        LOG.debug("Created DataSource Pool");

        ucpm.createConnectionPool((UniversalConnectionPoolAdapter)pds);

        ucpm.startConnectionPool("demo-pool");

        return pds;

}

However the initialize method is never called.  I'm using java 1.7.0_51 with the following Oracle jars:

ojdbc6.jar - v12.1.0.1.0

ucp.jar - v12.1.0.0.0


I have managed to make this work by removing the call to "registerConnectionInitializationCallback" and replacing it with a call to "registerConnectionLabelingCallback" but from my understanding this will exeute the ALTER SESSION each time a connection is requested from the pool rather then when it is actually created.

Any help with getting the ConnectionInitializationCallback to work would be much appreciated.

Kind Regards

Andy

registerConnectionInitializationCallbackAny

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 3 2014
Added on Apr 8 2014
3 comments
433 views