Search in sources :

Example 11 with JdbcTemplate

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

the class AbstractDatabaseInitializationTests method setUp.

@BeforeEach
void setUp() {
    db = new EmbeddedDatabaseBuilder().setType(getEmbeddedDatabaseType()).build();
    jdbcTemplate = new JdbcTemplate(db);
}
Also used : EmbeddedDatabaseBuilder(cn.taketoday.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with JdbcTemplate

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

the class InferredDataSourceSqlScriptsTests method database1.

@Test
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
void database1() {
    TransactionAssert.assertThatTransaction().isNotActive();
    assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test)

Example 13 with JdbcTemplate

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

the class InferredDataSourceTransactionalSqlScriptsTests method database2.

@Test
@Transactional("txMgr2")
@Sql(scripts = "data-add-catbert.sql", config = @SqlConfig(transactionManager = "txMgr2"))
void database2() {
    assertThatTransaction().isActive();
    assertUsers(new JdbcTemplate(dataSource2), "Dilbert", "Catbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 14 with JdbcTemplate

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

the class InferredDataSourceTransactionalSqlScriptsTests method database1.

@Test
@Transactional("txMgr1")
@Sql(scripts = "data-add-dogbert.sql", config = @SqlConfig(transactionManager = "txMgr1"))
void database1() {
    assertThatTransaction().isActive();
    assertUsers(new JdbcTemplate(dataSource1), "Dilbert", "Dogbert");
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Test(org.junit.jupiter.api.Test) Transactional(cn.taketoday.transaction.annotation.Transactional)

Example 15 with JdbcTemplate

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

the class AbstractTransactionalAnnotatedConfigClassTests method setDataSource.

@Autowired
public void setDataSource(DataSource dataSource) {
    this.dataSourceViaInjection = dataSource;
    this.jdbcTemplate = new JdbcTemplate(dataSource);
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) Autowired(cn.taketoday.beans.factory.annotation.Autowired)

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