public synchronized Object makeObject() { Object obj; try { PooledConnection pc = null; if (_username == null) { pc = _cpds.getPooledConnection(); } else { pc = _cpds.getPooledConnection(_username, _password); } if (pc == null) { throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); } // should we add this object as a listener or the pool. // consider the validateObject method in decision pc.addConnectionEventListener(this); obj = new PooledConnectionAndInfo(pc, _username, _password); pcMap.put(pc, obj); } catch (SQLException e) { throw new RuntimeException(e.getMessage()); } return obj; }
public void destroyObject(Object key, Object obj) throws Exception { if (obj instanceof PooledConnectionAndInfo) { PooledConnection pc = ((PooledConnectionAndInfo)obj).getPooledConnection(); pcMap.remove(pc); pc.close(); } }
_pool.returnObject(info.getUserPassKey(), info); } catch (Exception e) { System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL"); try { destroyObject(info.getUserPassKey(), info); } catch (Exception e2) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
if (!(null == password ? null == info.getPassword() : password.equals(info.getPassword()))) { // Password on PooledConnectionAndInfo does not match try { // See if password has changed by attempting connection testCPDS(username, password); final UserPassKey upkey = info.getUserPassKey(); final PooledConnectionManager manager = getConnectionManager(upkey); manager.invalidate(info.getPooledConnection()); // Destroy and remove from pool throw new SQLNestedException("Cannot borrow connection from pool", e); if (info != null && password.equals(info.getPassword())) { break; } else { if (info != null) { manager.invalidate(info.getPooledConnection()); Connection con = info.getPooledConnection().getConnection(); try { setupDefaults(con, username);
if (!(null == password ? null == info.getPassword() : password.equals(info.getPassword()))) { closeDueToException(info); throw new SQLException("Given password did not match password used" Connection con = info.getPooledConnection().getConnection(); setupDefaults(con, username); con.clearWarnings();
if (!(null == password ? null == info.getPassword() : password.equals(info.getPassword()))) { // Password on PooledConnectionAndInfo does not match try { // See if password has changed by attempting connection testCPDS(username, password); final UserPassKey upkey = info.getUserPassKey(); final PooledConnectionManager manager = getConnectionManager(upkey); manager.invalidate(info.getPooledConnection()); // Destroy and remove from pool throw new SQLNestedException("Cannot borrow connection from pool", e); if (info != null && password.equals(info.getPassword())) { break; } else { if (info != null) { manager.invalidate(info.getPooledConnection()); Connection con = info.getPooledConnection().getConnection(); try { setupDefaults(con, username);
public void destroyObject(Object obj) throws Exception { if (obj instanceof PooledConnectionAndInfo) { ((PooledConnectionAndInfo) obj).getPooledConnection().close(); } }
/** * Invalidates the PooledConnection in the pool. The KeyedCPDSConnectionFactory * closes the connection and pool counters are updated appropriately. * Also clears any idle instances associated with the username that was used * to create the PooledConnection. Connections associated with this user * are not affected and they will not be automatically closed on return to the pool. */ public void invalidate(PooledConnection pc) throws SQLException { PooledConnectionAndInfo info = (PooledConnectionAndInfo) pcMap.get(pc); if (info == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } UserPassKey key = info.getUserPassKey(); try { _pool.invalidateObject(key, info); // Destroy and update pool counters _pool.clear(key); // Remove any idle instances with this key } catch (Exception ex) { throw (SQLException) new SQLException("Error invalidating connection").initCause(ex); } }
public synchronized Object makeObject() { Object obj; try { PooledConnection pc = null; if (_username == null) { pc = _cpds.getPooledConnection(); } else { pc = _cpds.getPooledConnection(_username, _password); } // should we add this object as a listener or the pool. // consider the validateObject method in decision pc.addConnectionEventListener(this); obj = new PooledConnectionAndInfo(pc, _username, _password); pcMap.put(pc, obj); } catch (SQLException e) { throw new RuntimeException(e.getMessage()); } return obj; }
private void closeDueToException(PooledConnectionAndInfo info) { if (info != null) { try { info.getPooledConnection().getConnection().close(); } catch (Exception e) { // do not throw this exception because we are in the middle // of handling another exception. But record it because // it potentially leaks connections from the pool. getLogWriter().println("[ERROR] Could not return connection to " + "pool during exception handling. " + e.getMessage()); } } }
_pool.returnObject(info.getUserPassKey(), info); } catch (Exception e) { System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + pc.removeConnectionEventListener(this); try { _pool.invalidateObject(info.getUserPassKey(), info); } catch (Exception e3) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
public synchronized Object makeObject() { Object obj; try { PooledConnection pc = null; if (_username == null) { pc = _cpds.getPooledConnection(); } else { pc = _cpds.getPooledConnection(_username, _password); } if (pc == null) { throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); } // should we add this object as a listener or the pool. // consider the validateObject method in decision pc.addConnectionEventListener(this); obj = new PooledConnectionAndInfo(pc, _username, _password); pcMap.put(pc, obj); } catch (SQLException e) { throw new RuntimeException(e.getMessage()); } return obj; }
private void closeDueToException(PooledConnectionAndInfo info) { if (info != null) { try { info.getPooledConnection().getConnection().close(); } catch (Exception e) { // do not throw this exception because we are in the middle // of handling another exception. But record it because // it potentially leaks connections from the pool. getLogWriter().println("[ERROR] Could not return connection to " + "pool during exception handling. " + e.getMessage()); } } }
/** * Invalidates the PooledConnection in the pool. The KeyedCPDSConnectionFactory * closes the connection and pool counters are updated appropriately. * Also clears any idle instances associated with the username that was used * to create the PooledConnection. Connections associated with this user * are not affected and they will not be automatically closed on return to the pool. */ public void invalidate(PooledConnection pc) throws SQLException { PooledConnectionAndInfo info = (PooledConnectionAndInfo) pcMap.get(pc); if (info == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } UserPassKey key = info.getUserPassKey(); try { _pool.invalidateObject(key, info); // Destroy and update pool counters _pool.clear(key); // Remove any idle instances with this key } catch (Exception ex) { throw (SQLException) new SQLException("Error invalidating connection").initCause(ex); } }
/** * Creates a new {@link PooledConnectionAndInfo} from the given {@link UserPassKey}. * * @param key {@link UserPassKey} containing user credentials * @throws SQLException if the connection could not be created. * @see org.apache.commons.pool.KeyedPoolableObjectFactory#makeObject(java.lang.Object) */ public synchronized Object makeObject(Object key) throws Exception { Object obj = null; UserPassKey upkey = (UserPassKey)key; PooledConnection pc = null; String username = upkey.getUsername(); String password = upkey.getPassword(); if (username == null) { pc = _cpds.getPooledConnection(); } else { pc = _cpds.getPooledConnection(username, password); } if (pc == null) { throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); } // should we add this object as a listener or the pool. // consider the validateObject method in decision pc.addConnectionEventListener(this); obj = new PooledConnectionAndInfo(pc, username, password); pcMap.put(pc, obj); return obj; }
private void closeDueToException(PooledConnectionAndInfo info) { if (info != null) { try { info.getPooledConnection().getConnection().close(); } catch (Exception e) { // do not throw this exception because we are in the middle // of handling another exception. But record it because // it potentially leaks connections from the pool. getLogWriter().println("[ERROR] Could not return connection to " + "pool during exception handling. " + e.getMessage()); } } }
_pool.returnObject(info.getUserPassKey(), info); } catch (Exception e) { System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + pc.removeConnectionEventListener(this); try { _pool.invalidateObject(info.getUserPassKey(), info); } catch (Exception e3) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
/** * Creates a new {@link PooledConnectionAndInfo} from the given {@link UserPassKey}. * * @param key {@link UserPassKey} containing user credentials * @throws SQLException if the connection could not be created. * @see org.apache.commons.pool.KeyedPoolableObjectFactory#makeObject(java.lang.Object) */ public synchronized Object makeObject(Object key) throws Exception { Object obj = null; UserPassKey upkey = (UserPassKey)key; PooledConnection pc = null; String username = upkey.getUsername(); String password = upkey.getPassword(); if (username == null) { pc = _cpds.getPooledConnection(); } else { pc = _cpds.getPooledConnection(username, password); } if (pc == null) { throw new IllegalStateException("Connection pool data source returned null from getPooledConnection"); } // should we add this object as a listener or the pool. // consider the validateObject method in decision pc.addConnectionEventListener(this); obj = new PooledConnectionAndInfo(pc, username, password); pcMap.put(pc, obj); return obj; }
/** * Closes the PooledConnection and stops listening for events from it. */ public void destroyObject(Object obj) throws Exception { if (obj instanceof PooledConnectionAndInfo) { PooledConnection pc = ((PooledConnectionAndInfo)obj).getPooledConnection(); pc.removeConnectionEventListener(this); pcMap.remove(pc); pc.close(); } }
/** * If a fatal error occurs, close the underlying physical connection so as * not to be returned in the future */ public void connectionErrorOccurred(ConnectionEvent event) { PooledConnection pc = (PooledConnection)event.getSource(); if (null != event.getSQLException()) { System.err .println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")"); } pc.removeConnectionEventListener(this); PooledConnectionAndInfo info = (PooledConnectionAndInfo) pcMap.get(pc); if (info == null) { throw new IllegalStateException(NO_KEY_MESSAGE); } try { _pool.invalidateObject(info.getUserPassKey(), info); } catch (Exception e) { System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info); e.printStackTrace(); } }