use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.
the class H2SequenceMaxValueIncrementerTests method assertIncrements.
private void assertIncrements(DataSource dataSource) {
assertThat(new JdbcTemplate(dataSource).queryForObject("values next value for SEQ", int.class)).isEqualTo(1);
H2SequenceMaxValueIncrementer incrementer = new H2SequenceMaxValueIncrementer(dataSource, "SEQ");
assertThat(incrementer.nextIntValue()).isEqualTo(2);
assertThat(incrementer.nextStringValue()).isEqualTo("3");
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.
the class JdbcDaoSupportTests method testJdbcDaoSupportWithJdbcTemplate.
@Test
public void testJdbcDaoSupportWithJdbcTemplate() throws Exception {
JdbcTemplate template = new JdbcTemplate();
final List<String> test = new ArrayList<>();
JdbcDataAccessObjectSupport dao = new JdbcDataAccessObjectSupport() {
@Override
protected void initDao() {
test.add("test");
}
};
dao.setJdbcTemplate(template);
dao.afterPropertiesSet();
assertThat(template).as("Correct JdbcTemplate").isEqualTo(dao.getJdbcTemplate());
assertThat(test.size()).as("initDao called").isEqualTo(1);
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.
the class JdbcNamespaceIntegrationTests method assertCorrectSetupAndCloseContext.
private void assertCorrectSetupAndCloseContext(String file, int count, String... dataSources) {
try (ConfigurableApplicationContext context = context(file)) {
for (String dataSourceName : dataSources) {
DataSource dataSource = context.getBean(dataSourceName, DataSource.class);
assertNumRowsInTestTable(new JdbcTemplate(dataSource), count);
assertThat(dataSource instanceof AbstractDriverBasedDataSource).isTrue();
AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
assertThat(adbDataSource.getUrl()).contains(dataSourceName);
}
}
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.
the class JdbcNamespaceIntegrationTests method assertCorrectSetupForSingleDataSource.
private void assertCorrectSetupForSingleDataSource(String file, Predicate<String> urlPredicate) {
try (ConfigurableApplicationContext context = context(file)) {
DataSource dataSource = context.getBean(DataSource.class);
assertNumRowsInTestTable(new JdbcTemplate(dataSource), 1);
assertThat(dataSource instanceof AbstractDriverBasedDataSource).isTrue();
AbstractDriverBasedDataSource adbDataSource = (AbstractDriverBasedDataSource) dataSource;
assertThat(urlPredicate.test(adbDataSource.getUrl())).isTrue();
}
}
use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.
the class JdbcNamespaceIntegrationTests method createAndDestroyNestedWithHsql.
@Test
void createAndDestroyNestedWithHsql() throws Exception {
try (ClassPathXmlApplicationContext context = context("jdbc-destroy-nested-config.xml")) {
DataSource dataSource = context.getBean(DataSource.class);
JdbcTemplate template = new JdbcTemplate(dataSource);
assertNumRowsInTestTable(template, 1);
context.getBean(EmbeddedDatabaseFactoryBean.class).destroy();
// Table has been dropped
assertThatExceptionOfType(BadSqlGrammarException.class).isThrownBy(() -> assertNumRowsInTestTable(template, 1));
}
}
Aggregations