Rename derivefrom to align with DataSourceBuilder

Rename the `derivefrom` method in `ConnectionFactoryBuilder` to
`derivedFrom` to align with `DataSourceBuilder`.

Fixes gh-26810
pull/26861/head
Phillip Webb 3 years ago
parent f8c3e0e5aa
commit b7ac1e6cd7

@ -50,7 +50,8 @@ class R2dbcInitializationConfiguration {
private static ConnectionFactory determineConnectionFactory(ConnectionFactory connectionFactory, String username, private static ConnectionFactory determineConnectionFactory(ConnectionFactory connectionFactory, String username,
String password) { String password) {
if (StringUtils.hasText(username) && StringUtils.hasText(password)) { if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
return ConnectionFactoryBuilder.derivefrom(connectionFactory).username(username).password(password).build(); return ConnectionFactoryBuilder.derivedFrom(connectionFactory).username(username).password(password)
.build();
} }
return connectionFactory; return connectionFactory;
} }

@ -92,8 +92,23 @@ public final class ConnectionFactoryBuilder {
* @param connectionFactory the connection factory whose options are to be used to * @param connectionFactory the connection factory whose options are to be used to
* initialize the builder * initialize the builder
* @return a new builder initialized with the options from the connection factory * @return a new builder initialized with the options from the connection factory
* @deprecated since 2.5.0 for removal in 2.7.0 in favor of
* {@link #derivedFrom(ConnectionFactory)}
*/ */
@Deprecated
public static ConnectionFactoryBuilder derivefrom(ConnectionFactory connectionFactory) { public static ConnectionFactoryBuilder derivefrom(ConnectionFactory connectionFactory) {
return derivedFrom(connectionFactory);
}
/**
* Initialize a new {@link ConnectionFactoryBuilder} derived from the options of the
* specified {@code connectionFactory}.
* @param connectionFactory the connection factory whose options are to be used to
* initialize the builder
* @return a new builder initialized with the options from the connection factory
* @since 2.5.1
*/
public static ConnectionFactoryBuilder derivedFrom(ConnectionFactory connectionFactory) {
ConnectionFactoryOptions options = extractOptionsIfPossible(connectionFactory); ConnectionFactoryOptions options = extractOptionsIfPossible(connectionFactory);
if (options == null) { if (options == null) {
throw new IllegalArgumentException( throw new IllegalArgumentException(

@ -141,8 +141,8 @@ class ConnectionFactoryBuilderTests {
.withUrl(EmbeddedDatabaseConnection.H2.getUrl(intialDatabaseName)).build(); .withUrl(EmbeddedDatabaseConnection.H2.getUrl(intialDatabaseName)).build();
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
String derivedDatabaseName = UUID.randomUUID().toString(); String derivedDatabaseName = UUID.randomUUID().toString();
ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(connectionFactory).database(derivedDatabaseName) ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory)
.build(); .database(derivedDatabaseName).build();
ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions(); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();
assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo(derivedDatabaseName); assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo(derivedDatabaseName);
assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT, assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT,
@ -156,7 +156,7 @@ class ConnectionFactoryBuilderTests {
ConnectionFactory connectionFactory = ConnectionFactoryBuilder ConnectionFactory connectionFactory = ConnectionFactoryBuilder
.withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build(); .withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build();
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(connectionFactory).username("admin") ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory).username("admin")
.password("secret").build(); .password("secret").build();
ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions(); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();
assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("admin"); assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("admin");
@ -173,7 +173,7 @@ class ConnectionFactoryBuilderTests {
ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions();
ConnectionPoolConfiguration poolConfiguration = ConnectionPoolConfiguration.builder(connectionFactory).build(); ConnectionPoolConfiguration poolConfiguration = ConnectionPoolConfiguration.builder(connectionFactory).build();
ConnectionPool pool = new ConnectionPool(poolConfiguration); ConnectionPool pool = new ConnectionPool(poolConfiguration);
ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(pool).username("admin").password("secret") ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(pool).username("admin").password("secret")
.build(); .build();
assertThat(derived).isNotInstanceOf(ConnectionPool.class).isInstanceOf(OptionsCapableConnectionFactory.class); assertThat(derived).isNotInstanceOf(ConnectionPool.class).isInstanceOf(OptionsCapableConnectionFactory.class);
ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions(); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();

Loading…
Cancel
Save