@Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override
@Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override
@Override public Connection getConnection() throws SQLException { final Connection connection = DataSourceUtils.doGetConnection(dataSource); return ConnectionWrapperFactory.wrap(connection, closeHandler); }
/** * 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()); } }
this.target = DataSourceUtils.doGetConnection(this.targetDataSource); actualTarget = DataSourceUtils.doGetConnection(this.targetDataSource);
@Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override
@Override public Connection getConnection() throws SQLException { // Return a transactional Connection, if any. return DataSourceUtils.doGetConnection(dataSource); } @Override
@Override public Connection getConnection(DataSource dataSource, ConnectionType connectionType) throws SQLException { Connection connection = DataSourceUtils.doGetConnection(dataSource); LOGGER.debug(() -> "Obtained a Spring-managed connection: [" + connection + "]"); return connection; }
@Override public JdbcMetaData getJdbcMetaData(DataSource dataSource) { Connection conn = null; try { conn = DataSourceUtils.doGetConnection(dataSource); DatabaseMetaData dbmd = conn.getMetaData(); return getJdbcMetaData(dbmd); } catch (Exception e) { throw new IllegalStateException(e); } finally { logger.trace("closing connection"); JdbcUtils.closeQuietly(dataSource, conn); } }
@Override public JdbcMetaData getJdbcMetaData(DataSource dataSource) { Connection conn = null; try { conn = DataSourceUtils.doGetConnection(dataSource); DatabaseMetaData dbmd = conn.getMetaData(); return getJdbcMetaData(dbmd); } catch (Exception e) { throw new IllegalStateException(e); } finally { logger.trace("closing connection"); JdbcUtils.closeQuietly(dataSource, conn); } }
/** * 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); } }
this.target = DataSourceUtils.doGetConnection(this.targetDataSource); actualTarget = DataSourceUtils.doGetConnection(this.targetDataSource);
this.target = DataSourceUtils.doGetConnection(this.targetDataSource); actualTarget = DataSourceUtils.doGetConnection(this.targetDataSource);
/** * 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()); } }
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; }
protected ExecutionStats executeSequentially(JdbcContext context) { Connection conn = null; Statement statement = null; try { long updateCount = 0; long statementCount = 0; conn = DataSourceUtils.doGetConnection(context.getDataSource()); boolean originalAutoCommitSetting = conn.getAutoCommit(); conn.setAutoCommit(false); statement = conn.createStatement(); List<SqlSupplier> suppliers = context.getSuppliers(); for (SqlSupplier supplier : suppliers) { if (supplier instanceof LocationSupplier) { logger.debug("Location: {}", ((LocationSupplier) supplier).getLocation()); } ExecutionStats stats = excecuteSupplier(statement, context, supplier); updateCount += stats.getUpdateCount(); statementCount += stats.getStatementCount(); conn.commit(); } conn.setAutoCommit(originalAutoCommitSetting); return new ExecutionStats(updateCount, statementCount); } catch (Exception e) { throw new IllegalStateException(e); } finally { JdbcUtils.closeQuietly(context.getDataSource(), conn, statement); } }
protected ExecutionStats executeSequentially(JdbcContext context) { Connection conn = null; Statement statement = null; try { long updateCount = 0; long statementCount = 0; conn = DataSourceUtils.doGetConnection(context.getDataSource()); boolean originalAutoCommitSetting = conn.getAutoCommit(); conn.setAutoCommit(false); statement = conn.createStatement(); List<SqlSupplier> suppliers = context.getSuppliers(); for (SqlSupplier supplier : suppliers) { if (supplier instanceof SqlLocationSupplier) { logger.debug("Location: {}", ((SqlLocationSupplier)supplier).getLocation()); } ExecutionStats stats = excecuteSupplier(statement, context, supplier); updateCount += stats.getUpdateCount(); statementCount += stats.getStatementCount(); conn.commit(); } conn.setAutoCommit(originalAutoCommitSetting); return new ExecutionStats(updateCount, statementCount); } catch (Exception e) { throw new IllegalStateException(e); } finally { JdbcUtils.closeQuietly(context.getDataSource(), conn, statement); } }
.doGetConnection(dataSource)); session.setUserConnection(springCon); } catch (SQLException ex) {