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??