Forum Stats

  • 3,781,158 Users
  • 2,254,484 Discussions
  • 7,879,596 Comments

Discussions

UCP PoolDataSourceImpl with ConnectionInitializationCallback

andymc
andymc Member Posts: 67

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

Tagged:

Answers

  • However the initialize method is never called.

    Post the rest of the code; especially the part that checks connections out of the pool (since that is when the 'initialize' method will get called).

    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.

    Huh? It is that 'registerConnectionInitializationCallback' that executes 'each time a connection is requesteds from the pool' - NOT when a connection is created.

    See the API for Interface oracle.ucp.jdbc.ConnectionInitializationCallback:

    http://docs.oracle.com/cd/E23943_01/apirefs.1111/e13941/oracle/ucp/jdbc/ConnectionInitializationCallback.html

    Method Summary
    void<strong><a href="http://docs.oracle.com/cd/E23943_01/apirefs.1111/e13941/oracle/ucp/jdbc/ConnectionInitializationCallback.html#initialize(java.sql.Connection)">initialize</a></strong>(<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/sql/Connection.html" title="class or interface in java.sql">Connection</a> connection)
              Invoked at every connection check out from the pool as well as each successful reconnect following a recoverable error at replay.
  • user9943227
    user9943227 Member Posts: 1
    edited Jun 5, 2014 7:31AM

    Hi.
    I have working class with callback for Oracle12c.
    Do you need this?

  • No need to ask - if you have a contribution to make that might help OP and others that experience the same problem then just post the code.

This discussion has been closed.