Search in sources :

Example 71 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class SqlProducerJSONTest method setUp.

@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase2.sql").build();
    jdbcTemplate = new JdbcTemplate(db);
    super.setUp();
}
Also used : EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Example 72 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class SqlConsumerDeleteFailedTest method setUp.

@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
    jdbcTemplate = new JdbcTemplate(db);
    super.setUp();
}
Also used : EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Example 73 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class SqlConsumerDeleteTest method setUp.

@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
    jdbcTemplate = new JdbcTemplate(db);
    super.setUp();
}
Also used : EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Example 74 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class SqlConsumerDeleteTransformTest method setUp.

@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).addScript("sql/createAndPopulateDatabase.sql").build();
    jdbcTemplate = new JdbcTemplate(db);
    super.setUp();
}
Also used : EmbeddedDatabaseBuilder(org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Before(org.junit.Before)

Example 75 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project camel by apache.

the class AnnotatedBookServiceImpl method orderBook.

public void orderBook(String title) throws Exception {
    Transactional tx = this.getClass().getAnnotation(Transactional.class);
    if (tx == null) {
        throw new IllegalStateException("Spring annotation-driven should have instrumented this class as @Transactional");
    }
    if (!"REQUIRED".equals(tx.propagation().name())) {
        throw new IllegalStateException("Should be REQUIRED propagation");
    }
    if (title.startsWith("Donkey")) {
        throw new IllegalArgumentException("We don't have Donkeys, only Camels");
    }
    // create new local datasource to store in DB
    new JdbcTemplate(dataSource).update("insert into books (title) values (?)", title);
    template.sendBody(title);
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)124 Test (org.junit.Test)46 DataSource (javax.sql.DataSource)37 Before (org.junit.Before)19 SQLException (java.sql.SQLException)11 EmbeddedDatabaseBuilder (org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder)11 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)6 DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)6 Connection (java.sql.Connection)6 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)6 TransactionStatus (org.springframework.transaction.TransactionStatus)6 Test (org.testng.annotations.Test)6 SqlTemplate (com.alibaba.otter.node.etl.common.db.dialect.SqlTemplate)5 PreparedStatement (java.sql.PreparedStatement)5 Table (org.apache.ddlutils.model.Table)5 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 DataAccessException (org.springframework.dao.DataAccessException)5 AbstractDriverBasedDataSource (org.springframework.jdbc.datasource.AbstractDriverBasedDataSource)5 TransactionCallback (org.springframework.transaction.support.TransactionCallback)5