use of org.springframework.jdbc.core.JdbcTemplate in project spring-boot by spring-projects.
the class AbstractDataSourcePoolMetadataTests method getPoolSizeOneConnection.
@Test
public void getPoolSizeOneConnection() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(1));
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0.5F));
return null;
}
});
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-boot by spring-projects.
the class DataSourceInitializerTests method testDataSourceInitialized.
@Test
public void testDataSourceInitialized() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:true");
this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
assertThat(dataSource).isNotNull();
JdbcOperations template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject("SELECT COUNT(*) from BAR", Integer.class)).isEqualTo(1);
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-boot by spring-projects.
the class DataSourceInitializerTests method testDataSourceInitializedWithExplicitScript.
@Test
public void testDataSourceInitializedWithExplicitScript() throws Exception {
this.context.register(DataSourceAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.initialize:true", "spring.datasource.schema:" + ClassUtils.addResourcePathToPackagePath(getClass(), "schema.sql"), "spring.datasource.data:" + ClassUtils.addResourcePathToPackagePath(getClass(), "data.sql"));
this.context.refresh();
DataSource dataSource = this.context.getBean(DataSource.class);
assertThat(dataSource instanceof org.apache.tomcat.jdbc.pool.DataSource).isTrue();
assertThat(dataSource).isNotNull();
JdbcOperations template = new JdbcTemplate(dataSource);
assertThat(template.queryForObject("SELECT COUNT(*) from FOO", Integer.class)).isEqualTo(1);
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class JdbcDaoSupportTests method testJdbcDaoSupportWithJdbcTemplate.
@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", test.size(), 1);
}
use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.
the class StoredProcedureTests method testStoredProcedureSkippingResultsProcessing.
@Test
public void testStoredProcedureSkippingResultsProcessing() throws Exception {
given(callableStatement.execute()).willReturn(true);
given(callableStatement.getUpdateCount()).willReturn(-1);
given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}")).willReturn(callableStatement);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.setSkipResultsProcessing(true);
StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(jdbcTemplate);
Map<String, Object> res = sproc.execute();
assertEquals("incorrect number of returns", 0, res.size());
}
Aggregations