Search in sources :

Example 56 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project spring-framework by spring-projects.

the class EmbeddedDatabaseBuilderTests method createSameSchemaTwiceWithGeneratedUniqueDbNames.

@Test
public void createSameSchemaTwiceWithGeneratedUniqueDbNames() throws Exception {
    EmbeddedDatabase db1 = //
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql", //
    "db-test-data.sql").generateUniqueName(//
    true).build();
    JdbcTemplate template1 = new JdbcTemplate(db1);
    assertNumRowsInTestTable(template1, 1);
    template1.update("insert into T_TEST (NAME) values ('Sam')");
    assertNumRowsInTestTable(template1, 2);
    EmbeddedDatabase db2 = //
    new EmbeddedDatabaseBuilder(new ClassRelativeResourceLoader(getClass())).addScripts("db-schema-without-dropping.sql", //
    "db-test-data.sql").generateUniqueName(//
    true).build();
    assertDatabaseCreated(db2);
    db1.shutdown();
    db2.shutdown();
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Test(org.junit.Test)

Example 57 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project uPortal by Jasig.

the class SqlPortalDataFunction method setDataSource.

@Required
public void setDataSource(DataSource dataSource) {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.afterPropertiesSet();
    this.jdbcOperations = jdbcTemplate;
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Required(org.springframework.beans.factory.annotation.Required)

Example 58 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project uPortal by Jasig.

the class ProfilesDataFunction method setDataSource.

@Required
public void setDataSource(DataSource dataSource) {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.afterPropertiesSet();
    this.jdbcOperations = jdbcTemplate;
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Required(org.springframework.beans.factory.annotation.Required)

Example 59 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project uPortal by Jasig.

the class PermissionSetsDataFunction method setDataSource.

@Required
public void setDataSource(DataSource dataSource) {
    final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.afterPropertiesSet();
    this.jdbcOperations = jdbcTemplate;
}
Also used : JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) Required(org.springframework.beans.factory.annotation.Required)

Example 60 with JdbcTemplate

use of org.springframework.jdbc.core.JdbcTemplate in project opennms by OpenNMS.

the class JdbcEventdServiceManager method dataSourceSync.

/* (non-Javadoc)
     * @see org.opennms.netmgt.eventd.EventdServiceManager#dataSourceSync()
     */
/**
 * <p>dataSourceSync</p>
 */
@Override
public synchronized void dataSourceSync() {
    m_serviceMap.clear();
    new JdbcTemplate(m_dataSource).query(SQL_DB_SVC_TABLE_READ, new RowCallbackHandler() {

        @Override
        public void processRow(ResultSet resultSet) throws SQLException {
            m_serviceMap.put(resultSet.getString(2), resultSet.getInt(1));
        }
    });
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) RowCallbackHandler(org.springframework.jdbc.core.RowCallbackHandler)

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