public static SQLException generateSQLException(String reason, Throwable t) { // slow, but this is for very exceptional cases only try { // try JDK6/7 style constructor if (sqlExceptionClass == null){ // yes there's a chance this can race but nothing bad happens except for a performance hit... sqlExceptionClass = (Class<Throwable>) Class.forName(exceptionClass); } return (SQLException)sqlExceptionClass.getConstructor(String.class, Throwable.class).newInstance(reason, t); } catch (Exception e) { // fallback to JDK5 return new SQLException(PoolUtil.stringifyException(t)); } }
/** * @throws SQLException * */ private void maybeInit() throws SQLException { try { if (this.getDriverClass() != null) { this.loadClass(this.getDriverClass()); } } catch (final ClassNotFoundException e) { throw new SQLException(PoolUtil.stringifyException(e)); } BoneCPDataSource.logger.debug(this.toString()); this.pool = new FinalWrapper<BoneCP>(new BoneCP(this)); }
/** * {@inheritDoc} * * @see javax.sql.DataSource#getConnection() */ public Connection getConnection() throws SQLException { FinalWrapper<BoneCP> wrapper = this.pool; if (wrapper == null) { synchronized (this) { if (this.pool == null) { try{ if (this.getDriverClass() != null){ loadClass(this.getDriverClass()); } logger.debug(this.toString()); this.pool = new FinalWrapper<BoneCP>(new BoneCP(this)); } catch (ClassNotFoundException e) { throw new SQLException(PoolUtil.stringifyException(e)); } } wrapper = this.pool; } } return wrapper.value.getConnection(); }
config.getConnectionHook().onAcquireFail(e, acquireConfig); throw PoolUtil.generateSQLException(String.format(ERROR_TEST_CONNECTION, config.getJdbcUrl(), config.getUsername(), PoolUtil.stringifyException(e)), e);
config.getConnectionHook().onAcquireFail(e, acquireConfig); throw PoolUtil.generateSQLException(String.format(ERROR_TEST_CONNECTION, config.getJdbcUrl(), config.getUsername(), PoolUtil.stringifyException(e)), e);