@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()); }
/** * Check mandatory properties. * * @see org.springframework.dao.support.DaoSupport#initDao() */ @Override protected void initDao() throws Exception { super.initDao(); Assert.notNull(incrementer, "DataFieldMaxValueIncrementer is required - set the incrementer property in the " + ClassUtils.getShortName(StagingItemWriter.class)); }
/** * Set the JDBC DataSource to be used by this DAO. */ public final void setDataSource(DataSource dataSource) { if (this.jdbcTemplate == null || dataSource != this.jdbcTemplate.getDataSource()) { this.jdbcTemplate = createJdbcTemplate(dataSource); initTemplateConfig(); } }
@Test public void testJdbcDaoSupportWithJdbcTemplate() throws Exception { JdbcTemplate template = new JdbcTemplate(); final List<String> test = new ArrayList<>(); JdbcDaoSupport dao = new JdbcDaoSupport() { @Override protected void initDao() { test.add("test"); } }; dao.setJdbcTemplate(template); dao.afterPropertiesSet(); assertEquals("Correct JdbcTemplate", dao.getJdbcTemplate(), template); assertEquals("initDao called", 1, test.size()); }
/** * Return the SQLExceptionTranslator of this DAO's JdbcTemplate, * for translating SQLExceptions in custom JDBC access code. * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator() */ protected final SQLExceptionTranslator getExceptionTranslator() { JdbcTemplate jdbcTemplate = getJdbcTemplate(); Assert.state(jdbcTemplate != null, "No JdbcTemplate set"); return jdbcTemplate.getExceptionTranslator(); }
/** * 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()); }
/** * Set the JdbcTemplate for this DAO explicitly, * as an alternative to specifying a DataSource. */ public final void setJdbcTemplate(@Nullable JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; initTemplateConfig(); }
/** * @return the jdbcTemplate that is currently in use, * allows for overriding and support DAO-4 (http://jira.sakaiproject.org/jira/browse/DAO-4) */ public JdbcTemplate getSpringJdbcTemplate() { return super.getJdbcTemplate(); }
/** * 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); }
/** * Set the JdbcTemplate for this DAO explicitly, * as an alternative to specifying a DataSource. */ public final void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; initTemplateConfig(); }
@Override protected void initDao() throws Exception { super.initDao(); insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES").usingColumns("player_id", "year_no", "team", "week", "opponent", " completes", "attempts", "passing_yards", "passing_td", "interceptions", "rushes", "rush_yards", "receptions", "receptions_yards", "total_td"); }
/** * Set the JDBC DataSource to be used by this DAO. */ public final void setDataSource(DataSource dataSource) { if (this.jdbcTemplate == null || dataSource != this.jdbcTemplate.getDataSource()) { this.jdbcTemplate = createJdbcTemplate(dataSource); initTemplateConfig(); } }
/** * Return the SQLExceptionTranslator of this DAO's JdbcTemplate, * for translating SQLExceptions in custom JDBC access code. * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator() */ protected final SQLExceptionTranslator getExceptionTranslator() { JdbcTemplate jdbcTemplate = getJdbcTemplate(); Assert.state(jdbcTemplate != null, "No JdbcTemplate set"); return jdbcTemplate.getExceptionTranslator(); }
/** * 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()); }
/** * Set the JdbcTemplate for this DAO explicitly, * as an alternative to specifying a DataSource. */ public final void setJdbcTemplate(@Nullable JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; initTemplateConfig(); }
@Override protected void initDao() throws Exception { super.initDao(); insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("GAMES").usingColumns("player_id", "year_no", "team", "week", "opponent", " completes", "attempts", "passing_yards", "passing_td", "interceptions", "rushes", "rush_yards", "receptions", "receptions_yards", "total_td"); }
/** * Set the JDBC DataSource to be used by this DAO. */ public final void setDataSource(DataSource dataSource) { if (this.jdbcTemplate == null || dataSource != this.jdbcTemplate.getDataSource()) { this.jdbcTemplate = createJdbcTemplate(dataSource); initTemplateConfig(); } }
/** * Return the SQLExceptionTranslator of this DAO's JdbcTemplate, * for translating SQLExceptions in custom JDBC access code. * @see org.springframework.jdbc.core.JdbcTemplate#getExceptionTranslator() */ protected final SQLExceptionTranslator getExceptionTranslator() { return getJdbcTemplate().getExceptionTranslator(); }
/** * 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()); }
@Override public void initDao() throws Exception { super.initDao(); }