Search in sources :

Example 1 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project spring-boot by spring-projects.

the class DataSourceHealthIndicatorTests method init.

@Before
public void init() {
    EmbeddedDatabaseConnection db = EmbeddedDatabaseConnection.HSQL;
    this.dataSource = new SingleConnectionDataSource(db.getUrl() + ";shutdown=true", "sa", "", false);
    this.dataSource.setDriverClassName(db.getDriverClassName());
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) EmbeddedDatabaseConnection(org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConnection) Before(org.junit.Before)

Example 2 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project SimpleFlatMapper by arnaudroger.

the class JdbcTemplateCrudTest method setUp.

@Before
public void setUp() throws SQLException {
    Connection dbConnection;
    try {
        dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.MYSQL);
        dbConnection.createStatement().executeQuery("SELECT 1");
    } catch (Exception e) {
        dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.HSQLDB);
    }
    template = new JdbcTemplate(new SingleConnectionDataSource(dbConnection, true));
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) Connection(java.sql.Connection) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SQLException(java.sql.SQLException) Before(org.junit.Before)

Example 3 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project SimpleFlatMapper by arnaudroger.

the class MappingSqlQueryTest method setUp.

@Before
public void setUp() throws SQLException {
    Connection dbConnection = DbHelper.getDbConnection(DbHelper.TargetDB.HSQLDB);
    dataSource = new SingleConnectionDataSource(dbConnection, true);
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) Connection(java.sql.Connection) Before(org.junit.Before)

Example 4 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project ovirt-engine by oVirt.

the class DbConnectionUtilTest method testDBConnectionWithoutConnection.

/**
 * Ensures that the checkDBConnection method throws an Exception when connection is not valid
 */
@Test(expected = DataAccessException.class)
@DirtiesContext
public void testDBConnectionWithoutConnection() throws Exception {
    try (InputStream is = super.getClass().getResourceAsStream("/test-database.properties")) {
        Properties properties = new Properties();
        properties.load(is);
        ClassLoader.getSystemClassLoader().loadClass(properties.getProperty("database.driver"));
        DataSource dataSource = new SingleConnectionDataSource(properties.getProperty("database.url"), // connection
        "no-such-username", properties.getProperty("database.password"), true);
        final DbEngineDialect dbEngineDialect = DbFacadeLocator.loadDbEngineDialect();
        final JdbcTemplate jdbcTemplate = dbEngineDialect.createJdbcTemplate(dataSource);
        underTest = new DbConnectionUtil(jdbcTemplate, 666, 777);
        underTest.checkDBConnection();
    }
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) InputStream(java.io.InputStream) Properties(java.util.Properties) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) DataSource(javax.sql.DataSource) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 5 with SingleConnectionDataSource

use of org.springframework.jdbc.datasource.SingleConnectionDataSource in project spring-security by spring-projects.

the class BasicLookupStrategyTestsDbHelper method createDatabase.

public void createDatabase() throws Exception {
    // Use a different connection url so the tests can run in parallel
    String connectionUrl;
    String sqlClassPathResource;
    if (!this.withAclClassIdType) {
        connectionUrl = "jdbc:hsqldb:mem:lookupstrategytest";
        sqlClassPathResource = ACL_SCHEMA_SQL_FILE;
    } else {
        connectionUrl = "jdbc:hsqldb:mem:lookupstrategytestWithAclClassIdType";
        sqlClassPathResource = ACL_SCHEMA_SQL_FILE_WITH_ACL_CLASS_ID;
    }
    this.dataSource = new SingleConnectionDataSource(connectionUrl, "sa", "", true);
    this.dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
    this.jdbcTemplate = new JdbcTemplate(this.dataSource);
    Resource resource = new ClassPathResource(sqlClassPathResource);
    String sql = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
    this.jdbcTemplate.execute(sql);
}
Also used : SingleConnectionDataSource(org.springframework.jdbc.datasource.SingleConnectionDataSource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

SingleConnectionDataSource (org.springframework.jdbc.datasource.SingleConnectionDataSource)20 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)7 Connection (java.sql.Connection)6 DataSource (javax.sql.DataSource)4 Before (org.junit.Before)4 SQLException (java.sql.SQLException)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 KerberosTicketConfiguration (com.thinkbiganalytics.kerberos.KerberosTicketConfiguration)2 DataSetTemplate (com.thinkbiganalytics.kylo.catalog.rest.model.DataSetTemplate)2 DBSchemaParser (com.thinkbiganalytics.schema.DBSchemaParser)2 Nonnull (javax.annotation.Nonnull)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Extension (alfio.extension.Extension)1 ExtensionService (alfio.extension.ExtensionService)1 ScriptingExecutionService (alfio.extension.ScriptingExecutionService)1 ExternalConfiguration (alfio.manager.system.ExternalConfiguration)1 ExtensionLogRepository (alfio.repository.ExtensionLogRepository)1 ExtensionRepository (alfio.repository.ExtensionRepository)1 JdbcDriver (com.consol.citrus.db.driver.JdbcDriver)1