Search in sources :

Example 51 with JdbcTemplate

use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.

the class RdbmsOperationTests method parameterPropagation.

@Test
public void parameterPropagation() {
    SqlOperation operation = new SqlOperation() {
    };
    DataSource ds = new DriverManagerDataSource();
    operation.setDataSource(ds);
    operation.setFetchSize(10);
    operation.setMaxRows(20);
    JdbcTemplate jt = operation.getJdbcTemplate();
    assertThat(jt.getDataSource()).isEqualTo(ds);
    assertThat(jt.getFetchSize()).isEqualTo(10);
    assertThat(jt.getMaxRows()).isEqualTo(20);
}
Also used : DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) DriverManagerDataSource(cn.taketoday.jdbc.datasource.DriverManagerDataSource) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Example 52 with JdbcTemplate

use of cn.taketoday.jdbc.core.JdbcTemplate in project today-infrastructure by TAKETODAY.

the class EmbeddedDatabaseFactoryBeanTests method testFactoryBeanLifecycle.

@Test
public void testFactoryBeanLifecycle() throws Exception {
    EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resource("db-schema.sql"), resource("db-test-data.sql"));
    bean.setDatabasePopulator(populator);
    bean.afterPropertiesSet();
    DataSource ds = bean.getObject();
    JdbcTemplate template = new JdbcTemplate(ds);
    assertThat(template.queryForObject("select NAME from T_TEST", String.class)).isEqualTo("Keith");
    bean.destroy();
}
Also used : ResourceDatabasePopulator(cn.taketoday.jdbc.datasource.init.ResourceDatabasePopulator) JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) DataSource(javax.sql.DataSource) Test(org.junit.jupiter.api.Test)

Aggregations

JdbcTemplate (cn.taketoday.jdbc.core.JdbcTemplate)52 Test (org.junit.jupiter.api.Test)34 DataSource (javax.sql.DataSource)18 AbstractDriverBasedDataSource (cn.taketoday.jdbc.datasource.AbstractDriverBasedDataSource)10 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)8 BadSqlGrammarException (cn.taketoday.jdbc.BadSqlGrammarException)6 ConfigurableApplicationContext (cn.taketoday.context.ConfigurableApplicationContext)4 EmbeddedDatabaseFactoryBean (cn.taketoday.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean)4 Transactional (cn.taketoday.transaction.annotation.Transactional)4 List (java.util.List)4 Autowired (cn.taketoday.beans.factory.annotation.Autowired)2 Bean (cn.taketoday.context.annotation.Bean)2 Primary (cn.taketoday.context.annotation.Primary)2 ConditionalOnMissingBean (cn.taketoday.context.condition.ConditionalOnMissingBean)2 ClassRelativeResourceLoader (cn.taketoday.core.io.ClassRelativeResourceLoader)2 CallableStatementCreator (cn.taketoday.jdbc.core.CallableStatementCreator)2 SqlReturnResultSet (cn.taketoday.jdbc.core.SqlReturnResultSet)2 NamedParameterJdbcTemplate (cn.taketoday.jdbc.core.namedparam.NamedParameterJdbcTemplate)2 DriverManagerDataSource (cn.taketoday.jdbc.datasource.DriverManagerDataSource)2 SimpleDriverDataSource (cn.taketoday.jdbc.datasource.SimpleDriverDataSource)2