public static SQLException newSQLTransientConnectionException(String reason, String SQLState, int vendorCode) { return new SQLTransientConnectionException(reason, SQLState, vendorCode); }
/** * Create a timeout exception (specifically, {@link SQLTransientConnectionException}) to be thrown, because a * timeout occurred when trying to acquire a Connection from the pool. If there was an underlying cause for the * timeout, e.g. a SQLException thrown by the driver while trying to create a new Connection, then use the * SQL State from that exception as our own and additionally set that exception as the "next" SQLException inside * of our exception. * * As a side-effect, log the timeout failure at DEBUG, and record the timeout failure in the metrics tracker. * * @param startTime the start time (timestamp) of the acquisition attempt * @return a SQLException to be thrown from {@link #getConnection()} */ private SQLException createTimeoutException(long startTime) { logPoolState("Timeout failure "); metricsTracker.recordConnectionTimeout(); String sqlState = null; final Throwable originalException = getLastConnectionFailure(); if (originalException instanceof SQLException) { sqlState = ((SQLException) originalException).getSQLState(); } final SQLException connectionException = new SQLTransientConnectionException(poolName + " - Connection is not available, request timed out after " + elapsedMillis(startTime) + "ms.", sqlState, originalException); if (originalException instanceof SQLException) { connectionException.setNextException((SQLException) originalException); } return connectionException; }
/** {@inheritDoc} */ public Connection getConnection() throws SQLException { if (connectionDelay > 0) { try { TimeUnit.MILLISECONDS.sleep(connectionDelay); } catch (InterruptedException e) { throw new SQLTransientConnectionException(); } } return new StubConnection(); }
/** * Obtain connection from data source. * * @return a Connection connection */ Connection newConnection() throws Exception { Connection connection = null; try { String username = config.getUsername(); String password = config.getPassword(); connection = (username == null) ? dataSource.getConnection() : dataSource.getConnection(username, password); if (connection == null) { throw new SQLTransientConnectionException("DataSource returned null unexpectedly"); } setupConnection(connection); lastConnectionFailure.set(null); return connection; } catch (Exception e) { if (connection != null) { quietlyCloseConnection(connection, "(Failed to create/setup connection)"); } else if (getLastConnectionFailure() == null) { LOGGER.debug("{} - Failed to create/setup connection: {}", poolName, e.getMessage()); } lastConnectionFailure.set(e); throw e; } }
private SQLException createTimeoutException(long startTime) { logPoolState("Timeout failure "); metricsTracker.recordConnectionTimeout(); String sqlState = null; final Throwable originalException = getLastConnectionFailure(); if (originalException instanceof SQLException) { sqlState = ((SQLException) originalException).getSQLState(); } final SQLException connectionException = new SQLTransientConnectionException(poolName + " - Connection is not available, request timed out after " + clockSource.elapsedMillis(startTime) + "ms.", sqlState, originalException); if (originalException instanceof SQLException) { connectionException.setNextException((SQLException) originalException); } return connectionException; }
throw new SQLTransientConnectionException(L.l("{0}:{1} is not an accessible host", _host, _port)); } finally {
throw new SQLTransientConnectionException(e);
throw new SQLTransientConnectionException(e);
return new SQLTransientConnectionException("Could not send query: query size is >= to max_allowed_packet (" + writer.getMaxAllowedPacket() + ")" + getTraces(), UNDEFINED_SQLSTATE.getSqlState(), initialException);
return new SQLTransientConnectionException("Could not send query: query size is >= to max_allowed_packet (" + writer.getMaxAllowedPacket() + ")" + getTraces(), UNDEFINED_SQLSTATE.getSqlState(), initialException);