From b7ac1e6cd7bf50a5e25fa38c88dc98c4f7db7755 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 8 Jun 2021 15:00:29 -0700 Subject: [PATCH] Rename derivefrom to align with DataSourceBuilder Rename the `derivefrom` method in `ConnectionFactoryBuilder` to `derivedFrom` to align with `DataSourceBuilder`. Fixes gh-26810 --- .../init/R2dbcInitializationConfiguration.java | 3 ++- .../boot/r2dbc/ConnectionFactoryBuilder.java | 15 +++++++++++++++ .../boot/r2dbc/ConnectionFactoryBuilderTests.java | 8 ++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.java index 8bf8621337..5f413416f1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.java @@ -50,7 +50,8 @@ class R2dbcInitializationConfiguration { private static ConnectionFactory determineConnectionFactory(ConnectionFactory connectionFactory, String username, String 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; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilder.java index e51630d48e..9c13261b72 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilder.java @@ -92,8 +92,23 @@ public final class ConnectionFactoryBuilder { * @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 + * @deprecated since 2.5.0 for removal in 2.7.0 in favor of + * {@link #derivedFrom(ConnectionFactory)} */ + @Deprecated 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); if (options == null) { throw new IllegalArgumentException( diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilderTests.java index 5f8be73b91..443d9c80ea 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/r2dbc/ConnectionFactoryBuilderTests.java @@ -141,8 +141,8 @@ class ConnectionFactoryBuilderTests { .withUrl(EmbeddedDatabaseConnection.H2.getUrl(intialDatabaseName)).build(); ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); String derivedDatabaseName = UUID.randomUUID().toString(); - ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(connectionFactory).database(derivedDatabaseName) - .build(); + ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory) + .database(derivedDatabaseName).build(); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions(); assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.DATABASE)).isEqualTo(derivedDatabaseName); assertMatchingOptions(derivedOptions, initialOptions, ConnectionFactoryOptions.CONNECT_TIMEOUT, @@ -156,7 +156,7 @@ class ConnectionFactoryBuilderTests { ConnectionFactory connectionFactory = ConnectionFactoryBuilder .withUrl(EmbeddedDatabaseConnection.H2.getUrl(UUID.randomUUID().toString())).build(); ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); - ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(connectionFactory).username("admin") + ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(connectionFactory).username("admin") .password("secret").build(); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions(); assertThat(derivedOptions.getRequiredValue(ConnectionFactoryOptions.USER)).isEqualTo("admin"); @@ -173,7 +173,7 @@ class ConnectionFactoryBuilderTests { ConnectionFactoryOptions initialOptions = ((OptionsCapableConnectionFactory) connectionFactory).getOptions(); ConnectionPoolConfiguration poolConfiguration = ConnectionPoolConfiguration.builder(connectionFactory).build(); ConnectionPool pool = new ConnectionPool(poolConfiguration); - ConnectionFactory derived = ConnectionFactoryBuilder.derivefrom(pool).username("admin").password("secret") + ConnectionFactory derived = ConnectionFactoryBuilder.derivedFrom(pool).username("admin").password("secret") .build(); assertThat(derived).isNotInstanceOf(ConnectionPool.class).isInstanceOf(OptionsCapableConnectionFactory.class); ConnectionFactoryOptions derivedOptions = ((OptionsCapableConnectionFactory) derived).getOptions();