Search in sources :

Example 16 with SimpleDriverDataSource

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

the class DataSourceBuilderTests method buildWhenDerivedFromExistingDatabaseWithTypeChange.

// gh-26644
@Test
void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
    HikariDataSource dataSource = new HikariDataSource();
    dataSource.setUsername("test");
    dataSource.setPassword("secret");
    dataSource.setJdbcUrl("jdbc:postgresql://localhost:5432/postgres");
    DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
    SimpleDriverDataSource built = (SimpleDriverDataSource) builder.username("test2").password("secret2").build();
    assertThat(built.getUsername()).isEqualTo("test2");
    assertThat(built.getPassword()).isEqualTo("secret2");
    assertThat(built.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) Test(org.junit.jupiter.api.Test)

Example 17 with SimpleDriverDataSource

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

the class DataSourceBuilderTests method buildWhenDerivedFromCustomTypeWithTypeChange.

// gh-27295
@Test
void buildWhenDerivedFromCustomTypeWithTypeChange() {
    CustomDataSource dataSource = new CustomDataSource();
    dataSource.setUsername("test");
    dataSource.setPassword("secret");
    dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
    DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
    SimpleDriverDataSource testSource = (SimpleDriverDataSource) builder.build();
    assertThat(testSource.getUsername()).isEqualTo("test");
    assertThat(testSource.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
    assertThat(testSource.getPassword()).isEqualTo("secret");
}
Also used : SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) Test(org.junit.jupiter.api.Test)

Example 18 with SimpleDriverDataSource

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

the class LiquibaseAutoConfigurationTests method overrideUserWhenCustom.

@Test
void overrideUserWhenCustom() {
    this.contextRunner.withUserConfiguration(CustomDataSourceConfiguration.class).withPropertyValues("spring.liquibase.user:test", "spring.liquibase.password:secret").run((context) -> {
        String expectedName = context.getBean(CustomDataSourceConfiguration.class).name;
        SpringLiquibase liquibase = context.getBean(SpringLiquibase.class);
        SimpleDriverDataSource dataSource = (SimpleDriverDataSource) liquibase.getDataSource();
        assertThat(dataSource.getUrl()).contains(expectedName);
        assertThat(dataSource.getUsername()).isEqualTo("test");
    });
}
Also used : SpringLiquibase(liquibase.integration.spring.SpringLiquibase) SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) Test(org.junit.jupiter.api.Test)

Example 19 with SimpleDriverDataSource

use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project tutorials by eugenp.

the class TransactionalTestConfiguration method getDataSource.

@Bean
public DataSource getDataSource() {
    SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
    simpleDriverDataSource.setDriverClass(org.hsqldb.jdbcDriver.class);
    simpleDriverDataSource.setUrl("jdbc:hsqldb:mem:app-db");
    simpleDriverDataSource.setUsername("sa");
    simpleDriverDataSource.setPassword("");
    return simpleDriverDataSource;
}
Also used : SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) Bean(org.springframework.context.annotation.Bean)

Example 20 with SimpleDriverDataSource

use of org.springframework.jdbc.datasource.SimpleDriverDataSource in project cloudbreak by hortonworks.

the class DatabaseConfig method dataSource.

@Bean
public DataSource dataSource() throws SQLException {
    DatabaseUtil.createSchemaIfNeeded("postgresql", databaseAddress, dbName, dbUser, dbPassword, dbSchemaName);
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setDriverClass(Driver.class);
    if (ssl && Files.exists(Paths.get(certFile))) {
        Properties properties = new Properties();
        properties.setProperty("ssl", "true");
        properties.setProperty("sslfactory", "org.postgresql.ssl.SingleCertValidatingFactory");
        properties.setProperty("sslfactoryarg", "file://" + certFile);
        dataSource.setConnectionProperties(properties);
    }
    dataSource.setUrl(String.format("jdbc:postgresql://%s/%s?currentSchema=%s", databaseAddress, dbName, dbSchemaName));
    dataSource.setUsername(dbUser);
    dataSource.setPassword(dbPassword);
    return dataSource;
}
Also used : SimpleDriverDataSource(org.springframework.jdbc.datasource.SimpleDriverDataSource) Properties(java.util.Properties) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Aggregations

SimpleDriverDataSource (org.springframework.jdbc.datasource.SimpleDriverDataSource)20 Bean (org.springframework.context.annotation.Bean)8 Test (org.junit.jupiter.api.Test)6 Driver (java.sql.Driver)3 ProcessEngineFactoryBean (org.activiti.spring.ProcessEngineFactoryBean)3 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)3 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)3 Properties (java.util.Properties)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 DataSource (javax.sql.DataSource)1 SpringLiquibase (liquibase.integration.spring.SpringLiquibase)1 SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 ProcessEngineFactoryBean (org.camunda.bpm.engine.spring.ProcessEngineFactoryBean)1 Flyway (org.flywaydb.core.Flyway)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1 EmbeddedDatabase (org.springframework.jdbc.datasource.embedded.EmbeddedDatabase)1