@Override protected Connection getConnectionInternal() throws SQLException { ConnectionHandle result = pollConnection(); // we still didn't find an empty one, wait forever (or as per config) until our partition is free if (result == null) { int partition = (int) (Thread.currentThread().getId() % this.pool.partitionCount); ConnectionPartition connectionPartition = this.pool.partitions[partition]; try { result = connectionPartition.getFreeConnections().poll(this.pool.connectionTimeoutInMs, TimeUnit.MILLISECONDS); if (result == null){ if (this.pool.nullOnConnectionTimeout){ return null; } // 08001 = The application requester is unable to establish the connection. throw new SQLException("Timed out waiting for a free available connection.", "08001"); } } catch (InterruptedException e) { if (this.pool.nullOnConnectionTimeout){ return null; } throw PoolUtil.generateSQLException(e.getMessage(), e); } } return result; }
/** * {@inheritDoc} * * @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) */ public Connection getConnection(String username, String password) throws SQLException { try { return this.multiDataSource.get(new UsernamePassword(username, password)).getConnection(); } catch (ExecutionException e) { throw PoolUtil.generateSQLException("Unable to obtain connection", e); } }
throw PoolUtil.generateSQLException("ConnectionHandle is gone!", new IllegalStateException()); throw PoolUtil.generateSQLException(failedThrowable.getMessage(), failedThrowable);
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);