use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryOptionsInitializer method initializeRegularOptions.
private ConnectionFactoryOptions.Builder initializeRegularOptions(R2dbcProperties properties) {
ConnectionFactoryOptions urlOptions = ConnectionFactoryOptions.parse(properties.getUrl());
Builder optionsBuilder = urlOptions.mutate();
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.USER, properties::getUsername, StringUtils::hasText);
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.PASSWORD, properties::getPassword, StringUtils::hasText);
configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.DATABASE, () -> determineDatabaseName(properties), StringUtils::hasText);
if (properties.getProperties() != null) {
properties.getProperties().forEach((key, value) -> optionsBuilder.option(Option.valueOf(key), value));
}
return optionsBuilder;
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration.
@ParameterizedTest
@SuppressWarnings({ "rawtypes", "unchecked" })
@MethodSource("primitivePoolingConnectionProviderOptions")
void stringlyTypedOptionIsMappedWhenCreatingPoolConfiguration(Option option) {
String url = "r2dbc:pool:h2:mem:///" + UUID.randomUUID();
ExpectedOption expectedOption = ExpectedOption.get(option);
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl(url).configure((builder) -> builder.option(PoolingConnectionFactoryProvider.POOL_NAME, "defaultName").option(option, expectedOption.value.toString())).buildOptions();
ConnectionPoolConfiguration configuration = new PoolingAwareOptionsCapableWrapper().connectionPoolConfiguration(options, mock(ConnectionFactory.class));
assertThat(configuration).extracting(expectedOption.property).isEqualTo(expectedOption.value);
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildOptionsWithBasicUrlShouldExposeOptions.
@Test
void buildOptionsWithBasicUrlShouldExposeOptions() {
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl("r2dbc:simple://:pool:").buildOptions();
assertThat(options.hasOption(ConnectionFactoryOptions.USER)).isFalse();
assertThat(options.hasOption(ConnectionFactoryOptions.PASSWORD)).isFalse();
assertThat(options.getRequiredValue(ConnectionFactoryOptions.DRIVER)).isEqualTo("simple");
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildOptionsWithDriverPropertiesShouldExposeOptions.
@Test
void buildOptionsWithDriverPropertiesShouldExposeOptions() {
ConnectionFactoryOptions options = ConnectionFactoryBuilder.withUrl("r2dbc:simple://user:password@myhost").configure((o) -> o.option(Option.valueOf("simpleOne"), "one").option(Option.valueOf("simpleTwo"), "two")).buildOptions();
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleOne"))).isEqualTo("one");
assertThat(options.getRequiredValue(Option.<String>valueOf("simpleTwo"))).isEqualTo("two");
}
use of io.r2dbc.spi.ConnectionFactoryOptions in project spring-boot by spring-projects.
the class ConnectionFactoryBuilderTests method buildWhenDerivedWithNewCredentialsReturnsNewConnectionFactory.
@Test
void buildWhenDerivedWithNewCredentialsReturnsNewConnectionFactory() {
ConnectionFactory connectionFactory = ConnectionFactoryBuilder.withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build();
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory).username("admin").password("secret").build();
ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();
assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("admin");
assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.PASSWORD)).isEqualTo("secret");
assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT, ConnectionFactoryOptions.DATABASE, ConnectionFactoryOptions.DRIVER, ConnectionFactoryOptions.HOST, ConnectionFactoryOptions.PORT, ConnectionFactoryOptions.PROTOCOL, ConnectionFactoryOptions.SSL);
}
Aggregations