/** * Obtain a Connection from the given DataSource. Translates SQLExceptions into * the Spring hierarchy of unchecked generic data access exceptions, simplifying * calling code and making any exception that is thrown more meaningful. * <p>Is aware of a corresponding Connection bound to the current thread, for example * when using {@link DataSourceTransactionManager}. Will bind a Connection to the * thread if transaction synchronization is active, e.g. when running within a * {@link org.springframework.transaction.jta.JtaTransactionManager JTA} transaction). * @param dataSource the DataSource to obtain Connections from * @return a JDBC Connection from the given DataSource * @throws org.springframework.jdbc.CannotGetJdbcConnectionException * if the attempt to get a Connection failed * @see #releaseConnection */ public static Connection getConnection(DataSource dataSource) throws CannotGetJdbcConnectionException { try { return doGetConnection(dataSource); } catch (SQLException ex) { throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection", ex); } catch (IllegalStateException ex) { throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection: " + ex.getMessage()); } }
con = this.dataSource.getConnection(); if (con == null) { throw new CannotGetJdbcConnectionException("Failed to execute validation query: " + "DataSource returned null from getConnection(): " + this.dataSource); throw new CannotGetJdbcConnectionException( "Database has not started up within " + this.timeout + " seconds", latestEx);
/** * For DataAccessException * * @throws DataAccessException */ @ExceptionHandler(DataAccessException.class) public void handleDataAccessException(HttpServletResponse response, DataAccessException ex) throws DataAccessException { MetricsMonitor.getDbException().increment(); throw new CannotGetJdbcConnectionException(ex.getMessage()); }
/** * Obtain a Connection from the given DataSource. Translates SQLExceptions into * the Spring hierarchy of unchecked generic data access exceptions, simplifying * calling code and making any exception that is thrown more meaningful. * <p>Is aware of a corresponding Connection bound to the current thread, for example * when using {@link DataSourceTransactionManager}. Will bind a Connection to the * thread if transaction synchronization is active, e.g. when running within a * {@link org.springframework.transaction.jta.JtaTransactionManager JTA} transaction). * @param dataSource the DataSource to obtain Connections from * @return a JDBC Connection from the given DataSource * @throws org.springframework.jdbc.CannotGetJdbcConnectionException * if the attempt to get a Connection failed * @see #releaseConnection */ public static Connection getConnection(DataSource dataSource) throws CannotGetJdbcConnectionException { try { return doGetConnection(dataSource); } catch (SQLException ex) { throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection", ex); } catch (IllegalStateException ex) { throw new CannotGetJdbcConnectionException("Failed to obtain JDBC Connection: " + ex.getMessage()); } }
/** * Obtain a Connection from the given DataSource. Translates SQLExceptions into * the Spring hierarchy of unchecked generic data access exceptions, simplifying * calling code and making any exception that is thrown more meaningful. * <p>Is aware of a corresponding Connection bound to the current thread, for example * when using {@link DataSourceTransactionManager}. Will bind a Connection to the * thread if transaction synchronization is active, e.g. when running within a * {@link org.springframework.transaction.jta.JtaTransactionManager JTA} transaction). * @param dataSource the DataSource to obtain Connections from * @return a JDBC Connection from the given DataSource * @throws org.springframework.jdbc.CannotGetJdbcConnectionException * if the attempt to get a Connection failed * @see #releaseConnection */ public static Connection getConnection(DataSource dataSource) throws CannotGetJdbcConnectionException { try { return doGetConnection(dataSource); } catch (SQLException ex) { throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex); } }
/** * For DataAccessException * * @throws DataAccessException */ @ExceptionHandler(DataAccessException.class) public void handleDataAccessException(HttpServletResponse response, DataAccessException ex) throws DataAccessException { MetricsMonitor.getDbException().increment(); throw new CannotGetJdbcConnectionException(ex.getMessage()); }
throw new CannotGetJdbcConnectionException( "Database has not started up within " + this.timeout + " seconds", latestEx);
con = this.dataSource.getConnection(); if (con == null) { throw new CannotGetJdbcConnectionException("Failed to execute validation query: " + "DataSource returned null from getConnection(): " + this.dataSource); throw new CannotGetJdbcConnectionException( "Database has not started up within " + this.timeout + " seconds", latestEx);
private List<RequestDepository> fetchConnectionsAndDepositForLaterUse( List<ConcurrentRequest> requests) { List<RequestDepository> depos = new ArrayList<RequestDepository>(); for (ConcurrentRequest request : requests) { DataSource dataSource = request.getDataSource(); Connection springCon = null; boolean transactionAware = (dataSource instanceof TransactionAwareDataSourceProxy); try { springCon = (transactionAware ? dataSource.getConnection() : DataSourceUtils .doGetConnection(dataSource)); } catch (SQLException ex) { throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex); } RequestDepository depo = new RequestDepository(); depo.setOriginalRequest(request); depo.setConnectionToUse(springCon); depo.setTransactionAware(transactionAware); depos.add(depo); } return depos; }
@Override public int update(JdbcTemplate jdbcTemplate, String sql) { LOGGER.debug("sql = " + sql); if (CASE_1_SQL.equals(sql)) { return 1; } else if (CASE_2_SQL.equals(sql)) { throw new DataIntegrityViolationException("test", new SQLException("test DataIntegrityViolationException cause")); } else if (CASE_3_SQL.equals(sql)) { throw new CannotGetJdbcConnectionException("test", new SQLException("test CannotGetJdbcConnectionException cause")); } return 0; }
throw new CannotGetJdbcConnectionException("Failed to acquire connection for virtual shard " + shardIds.get(0) + " for " + name, e);
session.setUserConnection(springCon); } catch (SQLException ex) { throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", ex);
protected Object executeWith(Connection connection, SqlMapClientCallback action) { SqlMapSession session = getSqlMapClient().openSession(); try { try { session.setUserConnection(connection); } catch (SQLException e) { throw new CannotGetJdbcConnectionException("Could not get JDBC Connection", e); } try { return action.doInSqlMapClient(session); } catch (SQLException ex) { throw new SQLErrorCodeSQLExceptionTranslator().translate("SqlMapClient operation", null, ex); } } finally { session.close(); } }