/** * Get a JDBC Connection, either from the current transaction or a new one. * @return the JDBC Connection * @throws CannotGetJdbcConnectionException if the attempt to get a Connection failed * @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource) */ protected final Connection getConnection() throws CannotGetJdbcConnectionException { DataSource dataSource = getDataSource(); Assert.state(dataSource != null, "No DataSource set"); return DataSourceUtils.getConnection(dataSource); }
/** * Close the given JDBC Connection, created via this DAO's DataSource, * if it isn't bound to the thread. * @param con the Connection to close * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection */ protected final void releaseConnection(Connection con) { DataSourceUtils.releaseConnection(con, getDataSource()); }
@Test public void testJdbcDaoSupportWithDataSource() throws Exception { DataSource ds = mock(DataSource.class); final List<String> test = new ArrayList<>(); JdbcDaoSupport dao = new JdbcDaoSupport() { @Override protected void initDao() { test.add("test"); } }; dao.setDataSource(ds); dao.afterPropertiesSet(); assertEquals("Correct DataSource", ds, dao.getDataSource()); assertEquals("Correct JdbcTemplate", ds, dao.getJdbcTemplate().getDataSource()); assertEquals("initDao called", 1, test.size()); }
/** * Close the given JDBC Connection, created via this DAO's DataSource, * if it isn't bound to the thread. * @param con Connection to close * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection */ protected final void releaseConnection(Connection con) { DataSourceUtils.releaseConnection(con, getDataSource()); }
/** * Get a JDBC Connection, either from the current transaction or a new one. * @return the JDBC Connection * @throws CannotGetJdbcConnectionException if the attempt to get a Connection failed * @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource) */ protected final Connection getConnection() throws CannotGetJdbcConnectionException { return DataSourceUtils.getConnection(getDataSource()); }
/** * Get a JDBC Connection, either from the current transaction or a new one. * @return the JDBC Connection * @throws CannotGetJdbcConnectionException if the attempt to get a Connection failed * @see org.springframework.jdbc.datasource.DataSourceUtils#getConnection(javax.sql.DataSource) */ protected final Connection getConnection() throws CannotGetJdbcConnectionException { DataSource dataSource = getDataSource(); Assert.state(dataSource != null, "No DataSource set"); return DataSourceUtils.getConnection(dataSource); }