Search in sources :

Example 1 with ConnectionConfig

use of org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig in project spring-cloud-connectors by spring-cloud.

the class AbstractDataSourceCreatorTest method cloudDataSourceCreationWithConfig.

@Test
public void cloudDataSourceCreationWithConfig() throws Exception {
    SI relationalServiceInfo = createServiceInfo();
    PoolConfig poolConfig = new PoolConfig("5", 100);
    ConnectionConfig connectionConfig = new ConnectionConfig("foo=bar");
    List<String> pooledDataSource = Collections.singletonList(BasicDbcpPooledDataSourceCreator.class.getSimpleName());
    DataSourceConfig config = new DataSourceConfig(poolConfig, connectionConfig, pooledDataSource);
    DataSource dataSource = getCreator().create(relationalServiceInfo, config);
    assertDataSourceProperties(relationalServiceInfo, dataSource);
    DataSourceCloudConfigTestHelper.assertPoolProperties(dataSource, 5, 0, 100);
    Properties connectionProp = new Properties();
    connectionProp.put("foo", "bar");
    assertConnectionProperties(dataSource, connectionProp);
}
Also used : PoolConfig(org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig) Properties(java.util.Properties) ConnectionConfig(org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 2 with ConnectionConfig

use of org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig in project spring-cloud-connectors by spring-cloud.

the class PooledDataSourceCreatorsTest method pooledDataSourceCreationDefault.

@Test
public void pooledDataSourceCreationDefault() throws Exception {
    PoolConfig poolConfig = new PoolConfig(MIN_POOL_SIZE, MAX_POOL_SIZE, MAX_WAIT_TIME);
    ConnectionConfig connectionConfig = new ConnectionConfig(CONNECTION_PROPERTIES_STRING);
    DataSourceConfig config = new DataSourceConfig(poolConfig, connectionConfig);
    DataSource ds = createMysqlDataSource(config);
    assertTomcatJdbcDataSource(ds);
}
Also used : PoolConfig(org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig) ConnectionConfig(org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with ConnectionConfig

use of org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig in project spring-cloud-connectors by spring-cloud.

the class DatasourceConfigWithServiceConfig method dataSourceWithPoolAndConnectionConfig.

@Bean
public DataSource dataSourceWithPoolAndConnectionConfig() {
    PoolConfig poolConfig = new PoolConfig(20, 200);
    ConnectionConfig connectionConfig = new ConnectionConfig("sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8");
    DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, connectionConfig, basicDbcpConnectionPool());
    return connectionFactory().dataSource("my-service", serviceConfig);
}
Also used : DataSourceConfig(org.springframework.cloud.service.relational.DataSourceConfig) PoolConfig(org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig) ConnectionConfig(org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig) Bean(org.springframework.context.annotation.Bean)

Example 4 with ConnectionConfig

use of org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig in project spring-cloud-connectors by spring-cloud.

the class GenericServiceWithConnectorType method myServiceWithTypeWithServiceNameAndConfig.

@Bean
public DataSource myServiceWithTypeWithServiceNameAndConfig() {
    PoolConfig poolConfig = new PoolConfig(20, 200);
    ConnectionConfig connectionConfig = new ConnectionConfig("sessionVariables=sql_mode='ANSI';characterEncoding=UTF-8");
    DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, connectionConfig);
    return connectionFactory().service("my-service", DataSource.class, serviceConfig);
}
Also used : DataSourceConfig(org.springframework.cloud.service.relational.DataSourceConfig) PoolConfig(org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig) ConnectionConfig(org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig) Bean(org.springframework.context.annotation.Bean)

Example 5 with ConnectionConfig

use of org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig in project spring-cloud-connectors by spring-cloud.

the class PooledDataSourceCreatorsTest method createMysqlDataSourceWithPooledName.

private DataSource createMysqlDataSourceWithPooledName(String pooledDataSourceName) {
    List<String> dataSourceNames = Collections.singletonList(pooledDataSourceName);
    PoolConfig poolConfig = new PoolConfig(MIN_POOL_SIZE, MAX_POOL_SIZE, MAX_WAIT_TIME);
    ConnectionConfig connectionConfig = new ConnectionConfig(CONNECTION_PROPERTIES_STRING);
    DataSourceConfig config = new DataSourceConfig(poolConfig, connectionConfig, dataSourceNames);
    return createMysqlDataSource(config);
}
Also used : PoolConfig(org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig) ConnectionConfig(org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig)

Aggregations

PoolConfig (org.springframework.cloud.service.PooledServiceConnectorConfig.PoolConfig)5 ConnectionConfig (org.springframework.cloud.service.relational.DataSourceConfig.ConnectionConfig)5 DataSource (javax.sql.DataSource)2 Test (org.junit.Test)2 DataSourceConfig (org.springframework.cloud.service.relational.DataSourceConfig)2 Bean (org.springframework.context.annotation.Bean)2 Properties (java.util.Properties)1