private void closeConnectionAndIgnoreException(PooledConnection pconn) { try { pconn.close(); } catch (SQLException e) { log("Error while closing database connection: " + e.toString()); } }
/** Closes the PooledConnection and stops listening for events from it. */ @Override public void destroyObject(UserPassKey key, PooledObject<PooledConnectionAndInfo> p) throws Exception { PooledConnection pc = p.getObject().getPooledConnection(); pc.removeConnectionEventListener(this); pcMap.remove(pc); pc.close(); }
/** * Closes the PooledConnection and marks it for removal from the pcMap and for listener cleanup. * Adds it to muteMap so connectionClosed events generated by this or other actions are ignored. */ public void destroyObject(Object key, Object obj) throws Exception { if (obj instanceof PooledConnectionAndInfo) { PooledConnection pc = ((PooledConnectionAndInfo) obj).getPooledConnection(); cleanupMap.put(pc, null); // mark for cleanup muteMap.put(pc, null); // ignore events until listener is removed pc.close(); } }
private void testBug62452WithConnection(PooledConnection con) throws Exception { this.pstmt = con.getConnection().prepareStatement("SELECT 1"); this.rs = this.pstmt.executeQuery(); con.close(); // If PooledConnection is already closed by some reason a NullPointerException was thrown on the next line // because the closed connection has nulled out the list that it synchronises on when the closed event is fired. this.pstmt.close(); }
protected ConnectionPoolDataSource testCPDS(String username, String password) throws javax.naming.NamingException, SQLException { // The source of physical db connections ConnectionPoolDataSource cpds = this.dataSource; if (cpds == null) { Context ctx = null; if (jndiEnvironment == null) { ctx = new InitialContext(); } else { ctx = new InitialContext(jndiEnvironment); } Object ds = ctx.lookup(dataSourceName); if (ds instanceof ConnectionPoolDataSource) { cpds = (ConnectionPoolDataSource) ds; } else { throw new SQLException( "Illegal configuration: " + "DataSource " + dataSourceName + " (" + ds.getClass().getName() + ")" + " doesn't implement javax.sql.ConnectionPoolDataSource"); } } // try to get a connection with the supplied username/password PooledConnection conn = null; try { if (username != null) { conn = cpds.getPooledConnection(username, password); } else { conn = cpds.getPooledConnection(); } if (conn == null) { throw new SQLException("Cannot connect using the supplied username/password"); } } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { // at least we could connect } } } return cpds; }
/** Closes all unused pooled connections. */ public synchronized void dispose() throws SQLException { if (isDisposed) { return; } isDisposed = true; SQLException e = null; while (!recycledConnections.isEmpty()) { PooledConnection pconn = recycledConnections.remove(); try { pconn.close(); } catch (SQLException e2) { if (e == null) { e = e2; } } } if (e != null) { throw e; } }
@Override public void close() throws SQLException { passthru.close(); }