public synchronized void closePool(String name) throws SQLException { ObjectPool pool = (ObjectPool) _pools.get(name); if (pool != null) { _pools.remove(name); try { pool.close(); } catch (Exception e) { throw new SQLNestedException("Error closing pool " + name, e); } } }
/** * Constructs a new <code>SQLNestedException</code> with specified * detail message and nested <code>Throwable</code>. * * @param msg the error message * @param cause the exception or error that caused this exception to be * thrown */ public SQLNestedException(String msg, Throwable cause) { super(msg); if (cause != null){ initCause(cause); } } }
public void printStackTrace(PrintWriter s) { super.printStackTrace(s); if ((cause != null) && !hasThrowableCauseMethod()) { s.print("Caused by: "); this.cause.printStackTrace(s); } } }
/** * Create or obtain a {@link PreparedStatement} from my pool. * @return a {@link PoolablePreparedStatement} */ public PreparedStatement prepareStatement(String sql) throws SQLException { try { return(PreparedStatement)(_pstmtPool.borrowObject(createKey(sql))); } catch(NoSuchElementException e) { throw new SQLNestedException("MaxOpenPreparedStatements limit reached", e); } catch(RuntimeException e) { throw e; } catch(Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } }
/** * Constructs a new <code>SQLNestedException</code> with specified * detail message and nested <code>Throwable</code>. * * @param msg the error message * @param cause the exception or error that caused this exception to be * thrown */ public SQLNestedException(String msg, Throwable cause) { super(msg); if (cause != null){ initCause(cause); } } }
public void printStackTrace(PrintStream s) { super.printStackTrace(s); if ((cause != null) && !hasThrowableCauseMethod()) { s.print("Caused by: "); this.cause.printStackTrace(s); } }
/** * Create or obtain a {@link PreparedStatement} from my pool. * @return a {@link PoolablePreparedStatement} */ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { try { return(PreparedStatement)(_pstmtPool.borrowObject(createKey(sql,resultSetType,resultSetConcurrency))); } catch(NoSuchElementException e) { throw new SQLNestedException("MaxOpenPreparedStatements limit reached", e); } catch(RuntimeException e) { throw e; } catch(Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } }
/** * Sets the {*link ObjectPool} in which to pool {*link Connection}s. * @param pool the {*link ObjectPool} in which to pool those * {*link Connection}s */ public synchronized void setPool(ObjectPool pool) throws SQLException { if (null != _pool && pool != _pool) { try { _pool.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Cannot set the pool on this factory", e); } } _pool = pool; }
/** * Sets the {*link ObjectPool} in which to pool {*link Connection}s. * @param pool the {*link ObjectPool} in which to pool those {*link Connection}s */ synchronized public void setPool(KeyedObjectPool pool) throws SQLException { if (null != _pool && pool != _pool) { try { _pool.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Cannot set the pool on this factory", e); } } _pool = pool; }
/** * Create or obtain a {@link CallableStatement} from the pool. * @param sql the sql string used to define the CallableStatement * @return a {@link PoolableCallableStatement} * @throws SQLException * @since 1.3 */ public CallableStatement prepareCall(String sql) throws SQLException { try { return (CallableStatement) (_pstmtPool.borrowObject(createKey(sql, STATEMENT_CALLABLESTMT))); } catch (NoSuchElementException e) { throw new SQLNestedException("MaxOpenCallableStatements limit reached", e); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow callableStatement from pool failed", e); } }
/** * Create or obtain a {@link CallableStatement} from the pool. * @param sql the sql string used to define the CallableStatement * @return a {@link PoolableCallableStatement} * @throws SQLException * @since 1.3 */ public CallableStatement prepareCall(String sql) throws SQLException { try { return (CallableStatement) (_pstmtPool.borrowObject(createKey(sql, STATEMENT_CALLABLESTMT))); } catch (NoSuchElementException e) { throw new SQLNestedException("MaxOpenCallableStatements limit reached", e); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow callableStatement from pool failed", e); } }
/** * Create or obtain a {@link CallableStatement} from the pool. * @param sql the sql string used to define the CallableStatement * @param resultSetType result set type * @param resultSetConcurrency result set concurrency * @return a {@link PoolableCallableStatement} * @throws SQLException * @since 1.3 */ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { try { return (CallableStatement) (_pstmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency, STATEMENT_CALLABLESTMT))); } catch (NoSuchElementException e) { throw new SQLNestedException("MaxOpenCallableStatements limit reached", e); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow callableStatement from pool failed", e); } }
/** * Create or obtain a {@link CallableStatement} from the pool. * @param sql the sql string used to define the CallableStatement * @param resultSetType result set type * @param resultSetConcurrency result set concurrency * @return a {@link PoolableCallableStatement} * @throws SQLException * @since 1.3 */ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { try { return (CallableStatement) (_pstmtPool.borrowObject(createKey(sql, resultSetType, resultSetConcurrency, STATEMENT_CALLABLESTMT))); } catch (NoSuchElementException e) { throw new SQLNestedException("MaxOpenCallableStatements limit reached", e); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow callableStatement from pool failed", e); } }
/** * Close and release all connections that are currently stored in the * connection pool associated with our data source. * * @throws SQLException if a database error occurs */ public synchronized void close() throws SQLException { GenericObjectPool oldpool = connectionPool; connectionPool = null; dataSource = null; try { if (oldpool != null) { oldpool.close(); } } catch(SQLException e) { throw e; } catch(RuntimeException e) { throw e; } catch(Exception e) { throw new SQLNestedException("Cannot close connection pool", e); } }
PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException { if (pstmtPool == null) { return connection.prepareStatement(sql, columnNames); } else { try { return (PreparedStatement) pstmtPool.borrowObject( createKey(sql, columnNames)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } } }
PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { if (pstmtPool == null) { return connection.prepareStatement(sql, columnIndexes); } else { try { return (PreparedStatement) pstmtPool.borrowObject( createKey(sql, columnIndexes)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } } }
PreparedStatement prepareStatement(String sql, int columnIndexes[]) throws SQLException { if (pstmtPool == null) { return connection.prepareStatement(sql, columnIndexes); } else { try { return (PreparedStatement) pstmtPool.borrowObject( createKey(sql, columnIndexes)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } } }
throw e; } catch(Exception e) { throw new SQLNestedException("Cannot close connection pool", e);
PreparedStatement prepareStatement(String sql, String columnNames[]) throws SQLException { if (pstmtPool == null) { return connection.prepareStatement(sql, columnNames); } else { try { return (PreparedStatement) pstmtPool.borrowObject( createKey(sql, columnNames)); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new SQLNestedException("Borrow prepareStatement from pool failed", e); } } }
throw e; } catch(Exception e) { throw new SQLNestedException("Cannot close connection pool", e);