Search in sources :

Example 26 with JdbcTemplate

use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework 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 27 with JdbcTemplate

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

the class InferredDataSourceSqlScriptsTests method database2.

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

Example 28 with JdbcTemplate

use of cn.taketoday.jdbc.core.JdbcTemplate in project today-framework 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 29 with JdbcTemplate

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

the class JdbcDataAccessObjectSupport method getExceptionTranslator.

/**
 * Return the SQLExceptionTranslator of this DAO's JdbcTemplate,
 * for translating SQLExceptions in custom JDBC access code.
 *
 * @see cn.taketoday.jdbc.core.JdbcTemplate#getExceptionTranslator()
 */
protected final SQLExceptionTranslator getExceptionTranslator() {
    JdbcTemplate jdbcTemplate = getJdbcTemplate();
    Assert.state(jdbcTemplate != null, "No JdbcTemplate set");
    return jdbcTemplate.getExceptionTranslator();
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate)

Example 30 with JdbcTemplate

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

the class JdbcTemplateConfiguration method jdbcTemplate.

@Bean
@Primary
JdbcTemplate jdbcTemplate(DataSource dataSource, JdbcProperties properties) {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    JdbcProperties.Template template = properties.getTemplate();
    jdbcTemplate.setFetchSize(template.getFetchSize());
    jdbcTemplate.setMaxRows(template.getMaxRows());
    if (template.getQueryTimeout() != null) {
        jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
    }
    return jdbcTemplate;
}
Also used : JdbcTemplate(cn.taketoday.jdbc.core.JdbcTemplate) NamedParameterJdbcTemplate(cn.taketoday.jdbc.core.namedparam.NamedParameterJdbcTemplate) Primary(cn.taketoday.context.annotation.Primary) Bean(cn.taketoday.context.annotation.Bean) ConditionalOnMissingBean(cn.taketoday.context.condition.ConditionalOnMissingBean)

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