org.springframework.cloud.service.relational.DataSourceConfig Java Examples
The following examples show how to use
org.springframework.cloud.service.relational.DataSourceConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudDataSourceFactoryBeanTest.java From multiapps-controller with Apache License 2.0 | 6 votes |
@Test public void testReadConfiguration() { final int DB_CONNECTIONS = 15; final String SERVICE_NAME = "abc"; when(configurationMock.getDbConnectionThreads()).thenReturn(DB_CONNECTIONS); ArgumentMatcher<DataSourceConfig> dataSourceConfigMatcher = new LambdaArgumentMatcher<>((Object input) -> DB_CONNECTIONS == ((DataSourceConfig) input).getPoolConfig() .getMaxTotal()); when(springCloudMock.getServiceConnector(eq(SERVICE_NAME), eq(DataSource.class), argThat(dataSourceConfigMatcher))).thenReturn(createdDataSource); testedFactory.setDefaultDataSource(defaultDataSource); testedFactory.setServiceName(SERVICE_NAME); testedFactory.setConfiguration(configurationMock); testedFactory.afterPropertiesSet(); verify(springCloudMock, atLeastOnce()).getServiceConnector(any(), any(), any()); assertEquals(testedFactory.getObject(), createdDataSource); }
Example #2
Source File: CloudDataSourceFactoryBean.java From multiapps-controller with Apache License 2.0 | 5 votes |
private DataSource getCloudDataSource(String serviceName) { DataSource cloudDataSource = null; try { if (serviceName != null && !serviceName.isEmpty()) { int maxPoolSize = configuration.getDbConnectionThreads(); DataSourceConfig config = new DataSourceConfig(new PoolConfig(maxPoolSize, 30000), null); cloudDataSource = getSpringCloud().getServiceConnector(serviceName, DataSource.class, config); } } catch (CloudException e) { // Do nothing } return cloudDataSource; }
Example #3
Source File: DataSourceCloudConfig.java From spring-cloud-dataflow-server-cloudfoundry with Apache License 2.0 | 5 votes |
@Bean public DataSource scdfCloudDataSource( CloudFoundryServerConfigurationProperties cloudFoundryServerConfigurationProperties) { PooledServiceConnectorConfig.PoolConfig poolConfig = new PooledServiceConnectorConfig.PoolConfig( cloudFoundryServerConfigurationProperties.getMaxPoolSize(), cloudFoundryServerConfigurationProperties.getMaxWaitTime()); DataSourceConfig dbConfig = new DataSourceConfig(poolConfig, null); return connectionFactory().dataSource(dbConfig); }
Example #4
Source File: CloudDataSourceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); BeanDefinitionBuilder dataSourceConfigBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(DataSourceConfig.class.getName()); BeanDefinition cloudConnectionConfiguration = null; Element connectionElement = DomUtils.getChildElementByTagName(element, ELEMENT_CONNECTION); if (connectionElement != null) { cloudConnectionConfiguration = parseConnectionElement(connectionElement); } BeanDefinition cloudPoolConfiguration = null; Element poolElement = DomUtils.getChildElementByTagName(element, ELEMENT_POOL); if (poolElement != null) { cloudPoolConfiguration = parsePoolElement(poolElement, parserContext); } List<?> dataSourceNames = null; Element dataSourceNamesElement = DomUtils.getChildElementByTagName(element, ELEMENT_DATASOURCE_NAMES); if (dataSourceNamesElement != null) { dataSourceNames = parserContext.getDelegate(). parseListElement(dataSourceNamesElement, dataSourceConfigBeanBuilder.getRawBeanDefinition()); } Map<?, ?> properties = null; Element propertiesElement = DomUtils.getChildElementByTagName(element, ELEMENT_CONNECTION_PROPERTIES); if (propertiesElement != null) { properties = parserContext.getDelegate().parseMapElement(propertiesElement, builder.getRawBeanDefinition()); } dataSourceConfigBeanBuilder.addConstructorArgValue(cloudPoolConfiguration); dataSourceConfigBeanBuilder.addConstructorArgValue(cloudConnectionConfiguration); dataSourceConfigBeanBuilder.addConstructorArgValue(dataSourceNames); dataSourceConfigBeanBuilder.addConstructorArgValue(properties); builder.addConstructorArgValue(dataSourceConfigBeanBuilder.getBeanDefinition()); }
Example #5
Source File: CloudDataSourceFactoryParser.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
private BeanDefinition parseConnectionElement(Element element) { BeanDefinitionBuilder cloudConnectionConfigurationBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(DataSourceConfig.ConnectionConfig.class.getName()); String connectionProperties = element.getAttribute("properties"); if (StringUtils.hasText(connectionProperties)) { cloudConnectionConfigurationBeanBuilder.addConstructorArgValue(connectionProperties); } return cloudConnectionConfigurationBeanBuilder.getBeanDefinition(); }
Example #6
Source File: GenericServiceJavaConfigTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@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); }
Example #7
Source File: DataSourceJavaConfigTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@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); }
Example #8
Source File: DataSourceJavaConfigTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Bean public DataSource dataSourceWithConnectionPropertiesConfig() { Map<String, Object> properties = new HashMap<String, Object>(); properties.put("driverClassName", "test.driver"); properties.put("validationQuery", "test validation query"); properties.put("testOnBorrow", false); DataSourceConfig serviceConfig = new DataSourceConfig(null, null, basicDbcpConnectionPool(), properties); return connectionFactory().dataSource("my-service", serviceConfig); }
Example #9
Source File: DataSourceJavaConfigTest.java From spring-cloud-connectors with Apache License 2.0 | 4 votes |
@Bean public DataSource dataSourceWithPoolConfig() { PoolConfig poolConfig = new PoolConfig(5, 30, 3000); DataSourceConfig serviceConfig = new DataSourceConfig(poolConfig, null, basicDbcpConnectionPool()); return connectionFactory().dataSource("my-service", serviceConfig); }
Example #10
Source File: CloudServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | 2 votes |
/** * Get the {@link DataSource} object associated with the only relational database service bound to the app. * * This is equivalent to the {@code <cloud:data-source/>} element. * * @return data source * @throws CloudException * if there are either 0 or more than 1 relational database services. */ @Override public DataSource dataSource() { return dataSource((DataSourceConfig) null); }
Example #11
Source File: CloudServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | 2 votes |
/** * Get the {@link DataSource} object associated with the only relational database service bound to the app * configured as specified. * * This is equivalent to the {@code <cloud:data-source>} element with nested {@code <cloud:connection>} and/or * {@code <cloud:pool>} elements. * * @param dataSourceConfig * configuration for the data source created * @return data source * @throws CloudException * if there are either 0 or more than 1 relational database services. */ @Override public DataSource dataSource(DataSourceConfig dataSourceConfig) { return cloud.getSingletonServiceConnector(DataSource.class, dataSourceConfig); }
Example #12
Source File: CloudServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | 2 votes |
/** * Get the {@link DataSource} object for the specified relational database service configured as specified. * * This is equivalent to the {@code <cloud:data-source service-id="serviceId"/>} element with * nested {@code <cloud:connection>} and/or {@code <cloud:pool>} elements. * * @param serviceId * the name of the service * @param dataSourceConfig * configuration for the data source created * @return data source * @throws CloudException * if the specified service doesn't exist */ @Override public DataSource dataSource(String serviceId, DataSourceConfig dataSourceConfig) { return cloud.getServiceConnector(serviceId, DataSource.class, dataSourceConfig); }
Example #13
Source File: ServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | votes |
DataSource dataSource(DataSourceConfig dataSourceConfig);
Example #14
Source File: ServiceConnectionFactory.java From spring-cloud-connectors with Apache License 2.0 | votes |
DataSource dataSource(String serviceId, DataSourceConfig dataSourceConfig);