0
votes

We are migrating our app servers from Weblogic to JBoss, we are facing a an issue with Datasource managed by Jboss which is not closing the Ironjacamar wrapped connection.

Environament : Jboss 7.2 , Ironjacamar 1.0.15 ,Oracle 11G

While getting connection from the Oracle datasource we wrapping the connection to Oracle Connection using the appserver(Weblogic/Jboss) specific wrapper like below.If we don't wrap this we wont be able to use oracle features like ArrayDescriptors.We should change our applications such way that they work in both weblogic and jboss.

Connectionutil.java:

public static Connection getConnection(String jndiName) throws NamingException, SQLException {
    InitialContext initContext = new InitialContext();
    Context envContext = (Context) initContext.lookup("java:/comp/env");
    DataSource dataSource = (DataSource) envContext.lookup(jndiName);
    Connection connection = dataSource.getConnection();
    connection= unwrapConnection(connection);
    return connection;
}



private static Connection  unwrapConnection(Connection connection) throws SQLException {
    if(isWeblogic) {
        if(connection instanceof weblogic.jdbc.extensions.WLConnection) {
            System.out.println("Datasource is maintained by Weblogc so Unwarping Weblogic JDBC Connection to oracle.jdbc.OracleConnection. Driver name is " + connection.getMetaData().getDriverName());
            return (oracle.jdbc.OracleConnection) ((weblogic.jdbc.extensions.WLConnection) connection).getVendorConnection();
        }
    } else if(isJboss) {
        if(connection instanceof org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6) {
            System.out.println("Datasource is maintained by Jboss so Unwarping Jboss JDBC Connection to oracle.jdbc.OracleConnection. Driver name is " + connection.getMetaData().getDriverName());
            return (oracle.jdbc.OracleConnection) ((org.jboss.jca.adapters.jdbc.jdk6.WrappedConnectionJDK6) connection).getUnderlyingConnection();
        }
    }

    // log.debug("{called getConnection(non weblogic type) - " + connection.getMetaData().getDriverName() + "}");
    return connection;
}

Whenever a connection is required we will call Datasource like below :

//some code 
connection = Connectionutil.getConnection("jdbc/SomeDS");


finally()
{
connection.close();//closing the connection
}

Problem here is even after closing the connection from client the connection is not freed by jboss pool if a new connection is requested , pool is giving other available connection untill the pool exhausts(maxCOnnections) with out reusing the closed connections. I expected that jboss connection pool manager would take care of managing connection it did not happened.

I found a solution to a problem similar to above in Jboss Community : https://community.jboss.org/thread/72958?start=0&tstart=0 and we able to resolved the issue for standalone applications like below.

   Connection logicalConnection= dataSource.getConnection();//got the connection from DS

Connection oracleConnection= Connectionutil.unwrapConnection(connection );//unwrapping and wrappig to oracle connection

//some code 

    {
    finally()
    {
    logicalConnection.close;// here closing logical connection instead of oracle connection. Then jboss is reusing the connections.
    }

But in case of J2EE application which use frameworks like spring who manages connection opening and closing , i did not understand how to get container wrapped connection instead of oracle connection like above in such cases?

Can anyone suggest me better way to solve the above issue??

1
you get container wrapper connection automatically, you shouldn't need oracleConnection if you use Spring or other framework. I don't see the issue here, or maybe you didn't add the actual problem with the last solution?eis
(you might consider renaming unwrapIfWLConnection to unwrapConnection to match what it is actually doing)eis
sorry eis my question might confused you , you are correct , spring gives wrapper connection but at our end we needed it to wrap to oracle connection for many Array descriptor operation so we implemented a javax.sql.DataSource getConnection method and configured spring to get this connection using org.springframework.jndi.JndiObjectFactoryBean so spring is closing oracle connection which ,i think , is causing the issue.Shankar

1 Answers

1
votes

spring gives wrapper connection but at our end we needed it to wrap to oracle connection for many Array descriptor operation so we implemented a javax.sql.DataSource getConnection method and configured spring to get this connection using org.springframework.jndi.JndiObjectFactoryBean so spring is closing oracle connection which ,i think , is causing the issue.

Indeed, that is causing the issue. Don't do this.

Instead, let Spring and other frameworks get the wrapped connection. Only unwrap the connection when you need array descriptors in your app, in the code, otherwise let everything use the wrapped connections provided by the container.