Example usage for org.springframework.jdbc.datasource SingleConnectionDataSource SingleConnectionDataSource

List of usage examples for org.springframework.jdbc.datasource SingleConnectionDataSource SingleConnectionDataSource

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource SingleConnectionDataSource SingleConnectionDataSource.

Prototype

public SingleConnectionDataSource() 

Source Link

Document

Constructor for bean-style configuration.

Usage

From source file:no.trank.openpipe.jdbc.SimpleJdbcDocumentProducerTest.java

protected void setUpDb() throws Exception {
    dataSource = new SingleConnectionDataSource();
    dataSource.setDriverClassName(jdbcDriver.class.getName());
    dataSource.setUrl("jdbc:hsqldb:mem:test");
    dataSource.setSuppressClose(true);//from   w  ww.j a v  a  2s .c  om
    jdbcTemplate = new JdbcTemplate(dataSource);
    jdbcTemplate.execute("CREATE TABLE documents (text VARCHAR(128), id INTEGER PRIMARY KEY, status SMALLINT)");
    jdbcTemplate.execute("CREATE TABLE status_count (status SMALLINT PRIMARY KEY, s_count INTEGER)");
    jdbcTemplate.execute(
            "CREATE TABLE status_ts (status SMALLINT PRIMARY KEY, done_ts TIMESTAMP, processed BOOLEAN)");
    final Random rnd = new Random();
    for (int i = 0; i < COUNT; i++) {
        final int r = rnd.nextInt(100);
        final short status = r >= 50 ? STATUS_ADD : r < 25 ? STATUS_DELETE : STATUS_MODIFY;
        statusCounts[status]++;
        insert(status);
    }
}

From source file:no.trank.openpipe.jdbc.store.StateDocumentProducerTest.java

@Override
protected void setUp() throws Exception {
    dataSource = new SingleConnectionDataSource();
    dataSource.setDriverClassName(jdbcDriver.class.getName());
    dataSource.setUrl("jdbc:hsqldb:mem:test");
    dataSource.setSuppressClose(true);//w w  w  . j ava2  s.c o  m
    jdbcTemplate = new SimpleJdbcTemplate(dataSource);
}

From source file:com.emc.ecs.sync.EndToEndTest.java

protected void verifyDb(TestObjectSource testSource, boolean truncateDb) {
    SingleConnectionDataSource ds = new SingleConnectionDataSource();
    ds.setUrl(SqliteDbService.JDBC_URL_BASE + dbFile.getPath());
    ds.setSuppressClose(true);/*w ww. j  av a 2 s .  c o m*/
    JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);

    long totalCount = verifyDbObjects(jdbcTemplate, testSource.getObjects());
    try {
        SqlRowSet rowSet = jdbcTemplate.queryForRowSet("SELECT count(source_id) FROM "
                + DbService.DEFAULT_OBJECTS_TABLE_NAME + " WHERE target_id != ''");
        Assert.assertTrue(rowSet.next());
        Assert.assertEquals(totalCount, rowSet.getLong(1));
        if (truncateDb)
            jdbcTemplate.update("DELETE FROM " + DbService.DEFAULT_OBJECTS_TABLE_NAME);
    } finally {
        try {
            ds.destroy();
        } catch (Throwable t) {
            log.warn("could not close datasource", t);
        }
    }
}

From source file:org.springframework.cloud.netflix.archaius.ArchaiusExternalConfiguration.java

@Bean
@Qualifier("dataSource")
public SingleConnectionDataSource initDataSource() {
    SingleConnectionDataSource dataSource = new SingleConnectionDataSource();
    dataSource.setDriverClassName("org.h2.Driver");
    dataSource.setUrl(/*from   ww  w.  java 2s. c  o  m*/
            "jdbc:h2:mem:test_archaius;AUTOCOMMIT=ON;DB_CLOSE_DELAY=-1;MODE=PostgreSQL;INIT=RUNSCRIPT FROM 'classpath:archaius_db_store.sql'");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    dataSource.setSuppressClose(true);
    return dataSource;
}