From a9de60f164b64a9dd997fea5ccfb2a8ff48d8b93 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 11 Jun 2021 08:26:19 +0200 Subject: [PATCH] Polishing. Rename method to renderForGeneratedValues to reflect its intended usage and enhance documentation. Tweak Javadoc. Closes: #483 Original pull request: #602. --- .../r2dbc/core/DefaultReactiveDataAccessStrategy.java | 4 ++-- .../data/r2dbc/core/R2dbcEntityTemplate.java | 2 +- .../data/r2dbc/core/ReactiveDataAccessStrategy.java | 10 ++++++---- .../springframework/data/r2dbc/dialect/H2Dialect.java | 2 +- .../data/r2dbc/dialect/MySqlDialect.java | 2 +- .../data/r2dbc/dialect/R2dbcDialect.java | 9 +++++---- ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 2 +- ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 5 ++--- ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 11 +++++------ ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 8 +++++--- ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 8 ++++---- ...cRepositoryWithMixedCaseNamesIntegrationTests.java | 6 +++--- .../data/r2dbc/testing/ExternalDatabase.java | 4 ++-- 13 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/springframework/data/r2dbc/core/DefaultReactiveDataAccessStrategy.java b/src/main/java/org/springframework/data/r2dbc/core/DefaultReactiveDataAccessStrategy.java index 506ef9b..c218aac 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/DefaultReactiveDataAccessStrategy.java +++ b/src/main/java/org/springframework/data/r2dbc/core/DefaultReactiveDataAccessStrategy.java @@ -362,8 +362,8 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra } @Override - public String renderForGeneratedKeys(SqlIdentifier identifier) { - return dialect.renderForGeneratedKeys(identifier); + public String renderForGeneratedValues(SqlIdentifier identifier) { + return dialect.renderForGeneratedValues(identifier); } private RelationalPersistentEntity getRequiredPersistentEntity(Class typeToRead) { diff --git a/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java b/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java index 12e9974..875d4a3 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java +++ b/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java @@ -605,7 +605,7 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw return statement.returnGeneratedValues(); } - return statement.returnGeneratedValues(dataAccessStrategy.renderForGeneratedKeys(identifierColumns.get(0))); + return statement.returnGeneratedValues(dataAccessStrategy.renderForGeneratedValues(identifierColumns.get(0))); }) .map(this.dataAccessStrategy.getConverter().populateIdIfNecessary(entity)) // .all() // diff --git a/src/main/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategy.java b/src/main/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategy.java index 8eda6ff..9bfac8b 100644 --- a/src/main/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategy.java +++ b/src/main/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategy.java @@ -138,14 +138,16 @@ public interface ReactiveDataAccessStrategy { String toSql(SqlIdentifier identifier); /** - * Render a {@link SqlIdentifier} in a way suitable for registering it as a generated key with a statement. - * + * Render a {@link SqlIdentifier} in a way suitable for registering it as a generated key with a statement through + * {@code Statement#returnGeneratedValues}. + * * @param identifier to render. Must not be {@literal null}. * @return rendered identifier. Guaranteed to be not {@literal null}. + * @since 1.3.2 */ - default String renderForGeneratedKeys(SqlIdentifier identifier) { + default String renderForGeneratedValues(SqlIdentifier identifier) { - Assert.notNull(identifier, "Indentifier must not be null."); + Assert.notNull(identifier, "SqlIdentifier must not be null."); return identifier.toSql(IdentifierProcessing.NONE); } diff --git a/src/main/java/org/springframework/data/r2dbc/dialect/H2Dialect.java b/src/main/java/org/springframework/data/r2dbc/dialect/H2Dialect.java index fad08d8..b95f8ff 100644 --- a/src/main/java/org/springframework/data/r2dbc/dialect/H2Dialect.java +++ b/src/main/java/org/springframework/data/r2dbc/dialect/H2Dialect.java @@ -16,7 +16,7 @@ public class H2Dialect extends PostgresDialect { public static final H2Dialect INSTANCE = new H2Dialect(); @Override - public String renderForGeneratedKeys(SqlIdentifier identifier) { + public String renderForGeneratedValues(SqlIdentifier identifier) { return identifier.getReference(getIdentifierProcessing()); } } diff --git a/src/main/java/org/springframework/data/r2dbc/dialect/MySqlDialect.java b/src/main/java/org/springframework/data/r2dbc/dialect/MySqlDialect.java index f71ffbc..76a98b0 100644 --- a/src/main/java/org/springframework/data/r2dbc/dialect/MySqlDialect.java +++ b/src/main/java/org/springframework/data/r2dbc/dialect/MySqlDialect.java @@ -106,7 +106,7 @@ public class MySqlDialect extends org.springframework.data.relational.core.diale } @Override - public String renderForGeneratedKeys(SqlIdentifier identifier) { + public String renderForGeneratedValues(SqlIdentifier identifier) { return identifier.getReference(getIdentifierProcessing()); } diff --git a/src/main/java/org/springframework/data/r2dbc/dialect/R2dbcDialect.java b/src/main/java/org/springframework/data/r2dbc/dialect/R2dbcDialect.java index 1eddac9..a1c47e6 100644 --- a/src/main/java/org/springframework/data/r2dbc/dialect/R2dbcDialect.java +++ b/src/main/java/org/springframework/data/r2dbc/dialect/R2dbcDialect.java @@ -62,14 +62,15 @@ public interface R2dbcDialect extends Dialect { } /** - * Render a {@link SqlIdentifier} in a way suitable for registering it as a generated key with a statement. The - * default implementation renders it as it would render a SQL representation of the identifier, i.e. with quotes where - * applicable. + * Render a {@link SqlIdentifier} in a way suitable for registering it as a generated key with a statement through + * {@code Statement#returnGeneratedValues}. The default implementation renders it as it would render a SQL + * representation of the identifier, i.e. with quotes where applicable. * * @param identifier to render. Must not be {@literal null}. * @return rendered identifier. Guaranteed to be not {@literal null}. + * @since 1.3.2 */ - default String renderForGeneratedKeys(SqlIdentifier identifier) { + default String renderForGeneratedValues(SqlIdentifier identifier) { return identifier.toSql(getIdentifierProcessing()); } } diff --git a/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index 743d744..aa25725 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/H2R2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -36,7 +36,7 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain * upper and lower case + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case * characters against H2. * * @author Jens Schauder diff --git a/src/test/java/org/springframework/data/r2dbc/repository/MariaDbR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/MariaDbR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index 5227204..bf281ba 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/MariaDbR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/MariaDbR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -38,11 +38,10 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain * upper and lower case + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case * characters against MariaDb. * - * @author Mark Paluch - * @author Zsombor Gegesy + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @ContextConfiguration diff --git a/src/test/java/org/springframework/data/r2dbc/repository/MySqlR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/MySqlR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index e8a5d24..b8f4b14 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/MySqlR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/MySqlR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -23,15 +23,15 @@ import javax.sql.DataSource; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; import org.springframework.data.r2dbc.convert.R2dbcCustomConversions; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; -import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; import org.springframework.data.r2dbc.testing.ExternalDatabase; import org.springframework.data.r2dbc.testing.MySqlTestSupport; import org.springframework.data.relational.core.mapping.NamingStrategy; @@ -39,11 +39,10 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain - * * upper and lower case characters against MySql. + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case + * characters against MySql. * - * @author Mark Paluch - * @author Zsombor Gegesy + * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @ContextConfiguration diff --git a/src/test/java/org/springframework/data/r2dbc/repository/OracleR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/OracleR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index 68c09c2..b2560e1 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/OracleR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/OracleR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -23,6 +23,7 @@ import javax.sql.DataSource; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; @@ -31,7 +32,7 @@ import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; import org.springframework.data.r2dbc.convert.R2dbcCustomConversions; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; -import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; +import org.springframework.data.r2dbc.testing.EnabledOnClass; import org.springframework.data.r2dbc.testing.ExternalDatabase; import org.springframework.data.r2dbc.testing.OracleTestSupport; import org.springframework.data.relational.core.mapping.NamingStrategy; @@ -39,13 +40,14 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain - * * upper and lower case characters against Oracle. + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case + * characters against Oracle. * * @author Jens Schauder */ @ExtendWith(SpringExtension.class) @ContextConfiguration +@EnabledOnClass("oracle.r2dbc.impl.OracleConnectionFactoryProviderImpl") public class OracleR2dbcRepositoryWithMixedCaseNamesIntegrationTests extends AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests { diff --git a/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index 4dce8f7..226d1e1 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/PostgresR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -23,15 +23,15 @@ import javax.sql.DataSource; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; import org.springframework.data.r2dbc.convert.R2dbcCustomConversions; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; -import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; import org.springframework.data.r2dbc.testing.ExternalDatabase; import org.springframework.data.r2dbc.testing.PostgresTestSupport; import org.springframework.data.relational.core.mapping.NamingStrategy; @@ -39,8 +39,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain - * * upper and lower case characters against Postgres. + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case + * characters against Postgres. * * @author Jens Schauder */ diff --git a/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java b/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java index fa05057..8012610 100644 --- a/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java +++ b/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java @@ -23,6 +23,7 @@ import javax.sql.DataSource; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.context.annotation.Configuration; @@ -31,7 +32,6 @@ import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; import org.springframework.data.r2dbc.convert.R2dbcCustomConversions; import org.springframework.data.r2dbc.mapping.R2dbcMappingContext; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; -import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory; import org.springframework.data.r2dbc.testing.ExternalDatabase; import org.springframework.data.r2dbc.testing.SqlServerTestSupport; import org.springframework.data.relational.core.mapping.NamingStrategy; @@ -39,8 +39,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; /** - * Integration tests for {@link LegoSetRepository} with table and column names that contain - * * upper and lower case characters against SQL-Server. + * Integration tests for {@link LegoSetRepository} with table and column names that contain upper and lower case + * characters against SQL-Server. * * @author Jens Schauder */ diff --git a/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java b/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java index 74d363b..6e3c704 100644 --- a/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java +++ b/src/test/java/org/springframework/data/r2dbc/testing/ExternalDatabase.java @@ -222,7 +222,7 @@ public abstract class ExternalDatabase implements BeforeAllCallback { */ @Override public String getHostname() { - return "unknown"; + throw new UnsupportedOperationException(getClass().getSimpleName()); } /* (non-Javadoc) @@ -230,7 +230,7 @@ public abstract class ExternalDatabase implements BeforeAllCallback { */ @Override public int getPort() { - return -99999; + throw new UnsupportedOperationException(getClass().getSimpleName()); } /* (non-Javadoc)