diff --git a/pom.xml b/pom.xml index ebd3103251..9ad5010b18 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-relational-parent - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT pom Spring Data Relational Parent diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml index b3c39e64c3..c0cf7c24a7 100644 --- a/spring-data-jdbc-distribution/pom.xml +++ b/spring-data-jdbc-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT ../pom.xml diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index e61fd64020..753b0846d2 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-jdbc - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT diff --git a/spring-data-r2dbc/pom.xml b/spring-data-r2dbc/pom.xml index 3ee76fd3c1..f228bc9bcb 100644 --- a/spring-data-r2dbc/pom.xml +++ b/spring-data-r2dbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-r2dbc - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT Spring Data R2DBC Spring Data module for R2DBC @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT diff --git a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/R2dbcMappingContext.java b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/R2dbcMappingContext.java index 5053291be6..3a9fdf3604 100644 --- a/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/R2dbcMappingContext.java +++ b/spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/mapping/R2dbcMappingContext.java @@ -32,7 +32,7 @@ public class R2dbcMappingContext extends RelationalMappingContext { * Create a new {@link R2dbcMappingContext}. */ public R2dbcMappingContext() { - setForceQuote(false); + setForceQuote(true); } /** @@ -41,8 +41,10 @@ public R2dbcMappingContext() { * @param namingStrategy must not be {@literal null}. */ public R2dbcMappingContext(NamingStrategy namingStrategy) { + super(namingStrategy); - setForceQuote(false); + + setForceQuote(true); } @Override diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java index 77b855b6bf..e187dca08a 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/core/ReactiveDataAccessStrategyTestSupport.java @@ -185,7 +185,7 @@ void shouldNotWriteReadOnlyFields() { toSave.readOnlyField = "readonly"; toSave.readOnlyArrayField = "readonly_array".getBytes(); - assertThat(getStrategy().getOutboundRow(toSave)).containsOnlyKeys(SqlIdentifier.unquoted("writable_field")); + assertThat(getStrategy().getOutboundRow(toSave)).containsOnlyKeys(SqlIdentifier.quoted("writable_field")); } private void testType(BiConsumer setter, Function getter, T testValue, @@ -201,7 +201,7 @@ private void testType(BiConsumer setter, Function ?[$5]))"); + "(person.\"NAME\" = ?[$1]) AND (person.\"NAME\" = ?[$2] OR person.age < ?[$3] OR (person.\"NAME\" != ?[$4] AND person.age > ?[$5]))"); } @Test // gh-289 @@ -150,7 +152,7 @@ void shouldMapFrom() { BoundCondition bindings = map(criteria); assertThat(bindings.getCondition()) - .hasToString("person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3])"); + .hasToString("person.\"NAME\" = ?[$1] AND (person.\"NAME\" = ?[$2] OR person.age < ?[$3])"); } @Test // gh-383 @@ -160,13 +162,13 @@ void shouldMapFromConcat() { .or("age").lessThan(49)); assertThat(map(criteria).getCondition()) - .hasToString("(person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3]))"); + .hasToString("(person.\"NAME\" = ?[$1] AND (person.\"NAME\" = ?[$2] OR person.age < ?[$3]))"); criteria = Criteria.from(Criteria.where("name").is("Foo"), Criteria.where("name").is("Bar") // .or("age").lessThan(49), Criteria.where("foo").is("bar")); assertThat(map(criteria).getCondition()) - .hasToString("(person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3]) AND (person.foo = ?[$4]))"); + .hasToString("(person.\"NAME\" = ?[$1] AND (person.\"NAME\" = ?[$2] OR person.age < ?[$3]) AND (person.foo = ?[$4]))"); } @Test // gh-64 @@ -176,7 +178,7 @@ void shouldMapSimpleCriteria() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" = ?[$1]"); bindings.getBindings().apply(bindTarget); verify(bindTarget).bind(0, "foo"); @@ -218,7 +220,7 @@ void shouldMapExpression() { Expression mappedObject = mapper.getMappedObject(table.column("alternative").as("my_aliased_col"), mapper.getMappingContext().getRequiredPersistentEntity(Person.class)); - assertThat(mappedObject).hasToString("my_aliased_table.another_name AS my_aliased_col"); + assertThat(mappedObject).hasToString("my_aliased_table.\"another_name\" AS my_aliased_col"); } @Test // gh-300 @@ -229,7 +231,7 @@ void shouldMapCountFunction() { Expression mappedObject = mapper.getMappedObject(Functions.count(table.column("alternative")), mapper.getMappingContext().getRequiredPersistentEntity(Person.class)); - assertThat(mappedObject).hasToString("COUNT(my_aliased_table.another_name)"); + assertThat(mappedObject).hasToString("COUNT(my_aliased_table.\"another_name\")"); } @Test // gh-300 @@ -260,7 +262,7 @@ void shouldMapSimpleNullableCriteria() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" = ?[$1]"); bindings.getBindings().apply(bindTarget); verify(bindTarget).bindNull(0, Integer.class); @@ -273,7 +275,7 @@ void shouldConsiderColumnName() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.another_name = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"another_name\" = ?[$1]"); } @Test // gh-64 @@ -283,7 +285,7 @@ void shouldMapAndCriteria() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name = ?[$1] AND person.bar = ?[$2]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" = ?[$1] AND person.bar = ?[$2]"); bindings.getBindings().apply(bindTarget); verify(bindTarget).bind(0, "foo"); @@ -297,7 +299,7 @@ void shouldMapOrCriteria() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name = ?[$1] OR person.bar = ?[$2]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" = ?[$1] OR person.bar = ?[$2]"); } @Test // gh-64 @@ -311,7 +313,7 @@ void shouldMapAndOrCriteria() { BoundCondition bindings = map(criteria); assertThat(bindings.getCondition()).hasToString( - "person.name = ?[$1] AND person.name IS NOT NULL OR person.bar = ?[$2] AND person.anotherOne = ?[$3]"); + "person.\"NAME\" = ?[$1] AND person.\"NAME\" IS NOT NULL OR person.bar = ?[$2] AND person.anotherOne = ?[$3]"); } @Test // gh-64 @@ -321,7 +323,7 @@ void shouldMapNeq() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name != ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" != ?[$1]"); } @Test // gh-64 @@ -331,7 +333,7 @@ void shouldMapIsNull() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name IS NULL"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" IS NULL"); } @Test // gh-64 @@ -341,7 +343,7 @@ void shouldMapIsNotNull() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name IS NOT NULL"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" IS NOT NULL"); } @Test // gh-64 @@ -351,7 +353,7 @@ void shouldMapIsIn() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name IN (?[$1], ?[$2], ?[$3])"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" IN (?[$1], ?[$2], ?[$3])"); } @Test // gh-64, gh-177 @@ -361,7 +363,7 @@ void shouldMapIsNotIn() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name NOT IN (?[$1], ?[$2], ?[$3])"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" NOT IN (?[$1], ?[$2], ?[$3])"); } @Test @@ -374,7 +376,7 @@ void shouldMapIsNotInWithCollectionToStringConverter() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name NOT IN (?[$1], ?[$2], ?[$3])"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" NOT IN (?[$1], ?[$2], ?[$3])"); } @Test // gh-64 @@ -384,7 +386,7 @@ void shouldMapIsGt() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name > ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" > ?[$1]"); } @Test // gh-64 @@ -394,7 +396,7 @@ void shouldMapIsGte() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name >= ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" >= ?[$1]"); } @Test // gh-64 @@ -404,7 +406,7 @@ void shouldMapIsLt() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name < ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" < ?[$1]"); } @Test // gh-64 @@ -414,7 +416,7 @@ void shouldMapIsLte() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name <= ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" <= ?[$1]"); } @Test // gh-64 @@ -424,7 +426,7 @@ void shouldMapIsLike() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.name LIKE ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"NAME\" LIKE ?[$1]"); } @Test // GH-1507 @@ -493,7 +495,7 @@ void mapQueryForEnumArrayShouldMapToStringList() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.enum_value IN (?[$1], ?[$2])"); + assertThat(bindings.getCondition()).hasToString("person.\"ENUM_VALUE\" IN (?[$1], ?[$2])"); } @Test // gh-733 @@ -503,7 +505,7 @@ void shouldMapBooleanConditionProperly() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.state = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"STATE\" = ?[$1]"); assertThat(bindings.getBindings().iterator().next().getValue()).isEqualTo(false); } @@ -515,7 +517,7 @@ void shouldMapAndConvertBooleanConditionProperly() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.state = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"STATE\" = ?[$1]"); assertThat(bindings.getBindings().iterator().next().getValue()).isEqualTo((byte) 1); } @@ -526,7 +528,7 @@ void shouldMapJsonNodeToString() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.json_node = ?[$1]"); + assertThat(bindings.getCondition()).hasToString("person.\"JSON_NODE\" = ?[$1]"); assertThat(bindings.getBindings().iterator().next().getValue()).isEqualTo("foo"); } @@ -537,7 +539,7 @@ void shouldMapJsonNodeListToString() { BoundCondition bindings = map(criteria); - assertThat(bindings.getCondition()).hasToString("person.json_node IN (?[$1], ?[$2])"); + assertThat(bindings.getCondition()).hasToString("person.\"JSON_NODE\" IN (?[$1], ?[$2])"); assertThat(bindings.getBindings().iterator().next().getValue()).isEqualTo("foo"); } diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/query/UpdateMapperUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/query/UpdateMapperUnitTests.java index 6bb448d4b3..1a9eed2727 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/query/UpdateMapperUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/query/UpdateMapperUnitTests.java @@ -60,7 +60,7 @@ void shouldMapFieldNamesInUpdate() { Map assignments = mapped.getAssignments().stream().map(it -> (AssignValue) it) .collect(Collectors.toMap(k -> k.getColumn().getName(), AssignValue::getValue)); - assertThat(assignments).containsEntry(SqlIdentifier.unquoted("another_name"), SQL.bindMarker("$1")); + assertThat(assignments).containsEntry(SqlIdentifier.quoted("another_name"), SQL.bindMarker("$1")); } @Test // gh-64 @@ -73,7 +73,7 @@ void shouldUpdateToSettableValue() { Map assignments = mapped.getAssignments().stream().map(it -> (AssignValue) it) .collect(Collectors.toMap(k -> k.getColumn().getName(), AssignValue::getValue)); - assertThat(assignments).containsEntry(SqlIdentifier.unquoted("another_name"), SQL.bindMarker("$1")); + assertThat(assignments).containsEntry(SqlIdentifier.quoted("another_name"), SQL.bindMarker("$1")); mapped.getBindings().apply(bindTarget); verify(bindTarget).bindNull(0, String.class); @@ -87,7 +87,7 @@ void shouldUpdateToNull() { BoundAssignments mapped = map(update); assertThat(mapped.getAssignments()).hasSize(1); - assertThat(mapped.getAssignments().get(0).toString()).isEqualTo("person.another_name = NULL"); + assertThat(mapped.getAssignments().get(0).toString()).isEqualTo("person.\"another_name\" = NULL"); mapped.getBindings().apply(bindTarget); verifyNoInteractions(bindTarget); diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java index d631130d17..48074d7ab1 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java @@ -77,9 +77,9 @@ @MockitoSettings(strictness = Strictness.LENIENT) class PartTreeR2dbcQueryUnitTests { - private static final String TABLE = "users"; - private static final String[] ALL_FIELDS_ARRAY = new String[] { ".id", ".first_name", ".last_name", ".date_of_birth", - ".age", ".active" }; + private static final String TABLE = "\"users\""; + private static final String[] ALL_FIELDS_ARRAY = new String[] { ".\"id\"", ".\"first_name\"", ".\"last_name\"", ".\"date_of_birth\"", + ".\"age\"", ".\"active\"" }; private static final String[] ALL_FIELDS_ARRAY_PREFIXED = Arrays.stream(ALL_FIELDS_ARRAY).map(f -> TABLE + f) .toArray(String[]::new); private static final String ALL_FIELDS = String.join(", ", ALL_FIELDS_ARRAY_PREFIXED); @@ -121,7 +121,7 @@ void createsQueryToFindAllEntitiesByStringAttribute() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name = $1"); + .where(TABLE + ".\"first_name\" = $1"); } @Test // GH-282 @@ -134,7 +134,7 @@ void createsQueryWithIsNullCondition() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name IS NULL"); + .where(TABLE + ".\"first_name\" IS NULL"); } @Test // GH-282 @@ -145,9 +145,9 @@ void createsQueryWithLimitForExistsProjection() throws Exception { PreparedOperation query = createQuery(queryMethod, r2dbcQuery, "John"); PreparedOperationAssert.assertThat(query) // - .selects(TABLE + ".id") // + .selects(TABLE + ".\"id\"") // .from(TABLE) // - .where(TABLE + ".first_name = $1 LIMIT 1"); + .where(TABLE + ".\"first_name\" = $1 LIMIT 1"); } @Test // GH-282 @@ -161,7 +161,7 @@ void createsQueryToFindAllEntitiesByTwoStringAttributes() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".last_name = $1 AND (" + TABLE + ".first_name = $2)"); + .where(TABLE + ".\"last_name\" = $1 AND (" + TABLE + ".\"first_name\" = $2)"); } @Test // GH-282 @@ -175,7 +175,7 @@ void createsQueryToFindAllEntitiesByOneOfTwoStringAttributes() throws Exception PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".last_name = $1 OR (" + TABLE + ".first_name = $2)"); + .where(TABLE + ".\"last_name\" = $1 OR (" + TABLE + ".\"first_name\" = $2)"); } @Test // GH-282, GH-349 @@ -191,7 +191,7 @@ void createsQueryToFindAllEntitiesByDateAttributeBetween() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".date_of_birth BETWEEN $1 AND $2"); + .where(TABLE + ".\"date_of_birth\" BETWEEN $1 AND $2"); BindTarget bindTarget = mock(BindTarget.class); preparedOperation.bindTo(bindTarget); @@ -211,7 +211,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeLessThan() throws Exception PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age < $1"); + .where(TABLE + ".\"age\" < $1"); } @Test // GH-282 @@ -225,7 +225,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeLessThanEqual() throws Excep PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age <= $1"); + .where(TABLE + ".\"age\" <= $1"); } @Test // GH-282 @@ -239,7 +239,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeGreaterThan() throws Excepti PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age > $1"); + .where(TABLE + ".\"age\" > $1"); } @Test // GH-282 @@ -253,7 +253,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeGreaterThanEqual() throws Ex PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age >= $1"); + .where(TABLE + ".\"age\" >= $1"); } @Test // GH-282 @@ -267,7 +267,7 @@ void createsQueryToFindAllEntitiesByDateAttributeAfter() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".date_of_birth > $1"); + .where(TABLE + ".\"date_of_birth\" > $1"); } @Test // GH-282 @@ -280,7 +280,7 @@ void createsQueryToFindAllEntitiesByDateAttributeBefore() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".date_of_birth < $1"); + .where(TABLE + ".\"date_of_birth\" < $1"); } @Test // GH-282 @@ -294,7 +294,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeIsNull() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age IS NULL"); + .where(TABLE + ".\"age\" IS NULL"); } @Test // GH-282 @@ -308,7 +308,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeIsNotNull() throws Exception PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age IS NOT NULL"); + .where(TABLE + ".\"age\" IS NOT NULL"); } @Test // GH-282 @@ -322,7 +322,7 @@ void createsQueryToFindAllEntitiesByStringAttributeLike() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name LIKE $1"); + .where(TABLE + ".\"first_name\" LIKE $1"); } @Test // GH-282 @@ -336,7 +336,7 @@ void createsQueryToFindAllEntitiesByStringAttributeNotLike() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name NOT LIKE $1"); + .where(TABLE + ".\"first_name\" NOT LIKE $1"); } @Test // GH-282 @@ -350,7 +350,7 @@ void createsQueryToFindAllEntitiesByStringAttributeStartingWith() throws Excepti PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name LIKE $1"); + .where(TABLE + ".\"first_name\" LIKE $1"); } @Test // GH-282 @@ -377,7 +377,7 @@ void createsQueryToFindAllEntitiesByStringAttributeEndingWith() throws Exception PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name LIKE $1"); + .where(TABLE + ".\"first_name\" LIKE $1"); } @Test // GH-282 @@ -404,7 +404,7 @@ void createsQueryToFindAllEntitiesByStringAttributeContaining() throws Exception PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name LIKE $1"); + .where(TABLE + ".\"first_name\" LIKE $1"); } @Test // GH-282 @@ -431,7 +431,7 @@ void createsQueryToFindAllEntitiesByStringAttributeNotContaining() throws Except PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name NOT LIKE $1"); + .where(TABLE + ".\"first_name\" NOT LIKE $1"); } @Test // GH-282 @@ -457,8 +457,8 @@ void createsQueryToFindAllEntitiesByIntegerAttributeWithDescendingOrderingByStri PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age = $1") // - .orderBy("users.last_name DESC"); + .where(TABLE + ".\"age\" = $1") // + .orderBy("\"users\".\"last_name\" DESC"); } @Test // GH-282 @@ -472,8 +472,8 @@ void createsQueryToFindAllEntitiesByIntegerAttributeWithAscendingOrderingByStrin PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age = $1") // - .orderBy("users.last_name ASC"); + .where(TABLE + ".\"age\" = $1") // + .orderBy("\"users\".\"last_name\" ASC"); } @Test // GH-282 @@ -487,7 +487,7 @@ void createsQueryToFindAllEntitiesByStringAttributeNot() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".last_name != $1"); + .where(TABLE + ".\"last_name\" != $1"); } @Test // GH-282 @@ -502,7 +502,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeIn() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age IN ($1)"); + .where(TABLE + ".\"age\" IN ($1)"); } @Test // GH-282 @@ -517,7 +517,7 @@ void createsQueryToFindAllEntitiesByIntegerAttributeNotIn() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".age NOT IN ($1)"); + .where(TABLE + ".\"age\" NOT IN ($1)"); } @Test // GH-282, GH-698 @@ -531,7 +531,7 @@ void createsQueryToFindAllEntitiesByBooleanAttributeTrue() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".active = $1"); + .where(TABLE + ".\"active\" = $1"); } @Test // GH-282, GH-698 @@ -545,7 +545,7 @@ void createsQueryToFindAllEntitiesByBooleanAttributeFalse() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".active = $1"); + .where(TABLE + ".\"active\" = $1"); } @Test // GH-282 @@ -559,7 +559,7 @@ void createsQueryToFindAllEntitiesByStringAttributeIgnoringCase() throws Excepti PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where("UPPER(" + TABLE + ".first_name) = UPPER($1)"); + .where("UPPER(" + TABLE + ".\"first_name\") = UPPER($1)"); } @Test // GH-282 @@ -608,7 +608,7 @@ void allowsSortingByNonDomainProperties() throws Exception { PreparedOperation preparedOperation = createQuery(queryMethod, r2dbcQuery, "foo", Sort.by("foobar")); PreparedOperationAssert.assertThat(preparedOperation) // - .orderBy("users.foobar ASC"); + .orderBy("\"users\".foobar ASC"); preparedOperation = createQuery(queryMethod, r2dbcQuery, "foo", SqlSort.unsafe(Direction.ASC, "sum(foobar)")); PreparedOperationAssert.assertThat(preparedOperation) // @@ -636,7 +636,7 @@ void createsQueryWithLimitToFindEntitiesByStringAttribute() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name = $1 LIMIT 3"); + .where(TABLE + ".\"first_name\" = $1 LIMIT 3"); } @Test // GH-282 @@ -650,7 +650,7 @@ void createsQueryToFindFirstEntityByStringAttribute() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .selects(ALL_FIELDS_ARRAY_PREFIXED) // .from(TABLE) // - .where(TABLE + ".first_name = $1 LIMIT 1"); + .where(TABLE + ".\"first_name\" = $1 LIMIT 1"); } @Test // GH-341 @@ -664,7 +664,7 @@ void createsQueryToDeleteByFirstName() throws Exception { PreparedOperationAssert.assertThat(preparedOperation) // .deletes() // .from(TABLE) // - .where(TABLE + ".first_name = $1"); + .where(TABLE + ".\"first_name\" = $1"); } @Test // GH-344 @@ -675,7 +675,7 @@ void createsQueryToFindAllEntitiesByStringAttributeWithDistinct() throws Excepti PreparedOperation preparedOperation = createQuery(queryMethod, r2dbcQuery, "John"); PreparedOperationAssert.assertThat(preparedOperation) // - .selectsDistinct(TABLE + ".first_name", TABLE + ".foo") // + .selectsDistinct(TABLE + ".\"first_name\"", TABLE + ".foo") // .from(TABLE); } @@ -688,7 +688,7 @@ void createsQueryToFindByOpenProjection() throws Exception { PreparedOperation preparedOperation = createQuery(queryMethod, r2dbcQuery); PreparedOperationAssert.assertThat(preparedOperation) // - .selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") // + .selects("\"users\".\"id\"", "\"users\".\"first_name\"", "\"users\".\"last_name\"", "\"users\".\"date_of_birth\"", "\"users\".\"age\"", "\"users\".\"active\"") // .from(TABLE); } @@ -701,7 +701,7 @@ void createsDtoProjectionQuery() throws Exception { PreparedOperation preparedOperation = createQuery(queryMethod, r2dbcQuery, 42); PreparedOperationAssert.assertThat(preparedOperation) // - .selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") // + .selects("\"users\".\"id\"", "\"users\".\"first_name\"", "\"users\".\"last_name\"", "\"users\".\"date_of_birth\"", "\"users\".\"age\"", "\"users\".\"active\"") // .from(TABLE); } @@ -713,9 +713,9 @@ void createsQueryForCountProjection() throws Exception { PreparedOperation query = createQuery(queryMethod, r2dbcQuery, "John"); PreparedOperationAssert.assertThat(query) // - .selects("COUNT(users.id)") // + .selects("COUNT(\"users\".\"id\")") // .from(TABLE) // - .where(TABLE + ".first_name = $1"); + .where(TABLE + ".\"first_name\" = $1"); } @Test // GH-1041 @@ -730,9 +730,9 @@ void createQueryWithPessimisticWriteLock() throws Exception { PreparedOperation query = createQuery(queryMethod, r2dbcQuery, firstname, lastname); PreparedOperationAssert.assertThat(query) // - .selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") // + .selects("\"users\".\"id\"", "\"users\".\"first_name\"", "\"users\".\"last_name\"", "\"users\".\"date_of_birth\"", "\"users\".\"age\"", "\"users\".\"active\"") // .from(TABLE) // - .where("users.first_name = $1 AND (users.last_name = $2) FOR UPDATE OF users"); + .where("\"users\".\"first_name\" = $1 AND (\"users\".\"last_name\" = $2) FOR UPDATE OF \"users\""); } @Test // GH-1041 @@ -747,9 +747,9 @@ void createQueryWithPessimisticReadLock() throws Exception { PreparedOperation query = createQuery(queryMethod, r2dbcQuery, firstname, age); PreparedOperationAssert.assertThat(query) // - .selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") // + .selects("\"users\".\"id\"", "\"users\".\"first_name\"", "\"users\".\"last_name\"", "\"users\".\"date_of_birth\"", "\"users\".\"age\"", "\"users\".\"active\"") // .from(TABLE) // - .where("users.first_name = $1 AND (users.age = $2) FOR SHARE OF users"); + .where("\"users\".\"first_name\" = $1 AND (\"users\".\"age\" = $2) FOR SHARE OF \"users\""); } @Test // GH-1285 @@ -776,7 +776,7 @@ void createsQueryWithoutIdForCountProjection() throws Exception { PreparedOperationAssert.assertThat(query) // .selects("COUNT(1)") // .from(TABLE) // - .where(TABLE + ".first_name = $1"); + .where(TABLE + ".\"first_name\" = $1"); } @Test // GH-1310 @@ -789,7 +789,7 @@ void createsQueryWithoutIdForExistsProjection() throws Exception { PreparedOperationAssert.assertThat(query) // .selects("1") // .from(TABLE) // - .where(TABLE + ".first_name = $1 LIMIT 1"); + .where(TABLE + ".\"first_name\" = $1 LIMIT 1"); } private PreparedOperation createQuery(R2dbcQueryMethod queryMethod, PartTreeR2dbcQuery r2dbcQuery, diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java index b15c9b8d36..7ae04c1aec 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/R2dbcQueryMethodUnitTests.java @@ -67,7 +67,7 @@ void detectsCollectionFromReturnTypeIfReturnTypeAssignable() throws Exception { RelationalEntityMetadata metadata = queryMethod.getEntityInformation(); assertThat(metadata.getJavaType()).isAssignableFrom(Contact.class); - assertThat(metadata.getTableName()).isEqualTo(SqlIdentifier.unquoted("contact")); + assertThat(metadata.getTableName()).isEqualTo(SqlIdentifier.quoted("CONTACT")); } @Test // gh-235 @@ -93,7 +93,7 @@ void detectsTableNameFromRepoTypeIfReturnTypeNotAssignable() throws Exception { RelationalEntityMetadata metadata = queryMethod.getEntityInformation(); assertThat(metadata.getJavaType()).isAssignableFrom(Address.class); - assertThat(metadata.getTableName()).isEqualTo(SqlIdentifier.unquoted("contact")); + assertThat(metadata.getTableName()).isEqualTo(SqlIdentifier.quoted("CONTACT")); } @Test diff --git a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/SqlInspectingR2dbcRepositoryUnitTests.java b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/SqlInspectingR2dbcRepositoryUnitTests.java index 4e2a430e9f..2f505d5e71 100644 --- a/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/SqlInspectingR2dbcRepositoryUnitTests.java +++ b/spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/support/SqlInspectingR2dbcRepositoryUnitTests.java @@ -85,7 +85,7 @@ private static boolean isSelect(String sql) { } interface MyPersonRepository extends Repository { - @Query("select * from #{#tableName +'x'}") + @Query("select * from #{#tableName + 'x'}") Mono findBySpel(); } diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml index 8fd6d7a6f0..59e576e23d 100644 --- a/spring-data-relational/pom.xml +++ b/spring-data-relational/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-relational - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT Spring Data Relational Spring Data Relational support @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 4.0.0-SNAPSHOT + 4.0.0-1993-force-quoting-SNAPSHOT diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java index a06b4e3b25..edc9600d95 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/dialect/PostgresDialect.java @@ -34,6 +34,7 @@ import org.springframework.data.relational.core.sql.SimpleFunction; import org.springframework.data.relational.core.sql.SqlIdentifier; import org.springframework.data.relational.core.sql.TableLike; +import org.springframework.util.Assert; /** * An SQL dialect for Postgres. @@ -102,7 +103,7 @@ public LimitClause limit() { return LIMIT_CLAUSE; } - private final PostgresLockClause LOCK_CLAUSE = new PostgresLockClause(this.getIdentifierProcessing()); + private final PostgresLockClause LOCK_CLAUSE = new PostgresLockClause(); @Override public LockClause lock() { @@ -121,12 +122,6 @@ public Collection getConverters() { static class PostgresLockClause implements LockClause { - private final IdentifierProcessing identifierProcessing; - - PostgresLockClause(IdentifierProcessing identifierProcessing) { - this.identifierProcessing = identifierProcessing; - } - @Override public String getLock(LockOptions lockOptions) { @@ -144,7 +139,7 @@ public String getLock(LockOptions lockOptions) { } // without schema - String tableName = last.toSql(this.identifierProcessing); + String tableName = last.toSql(PostgresDialect.identifierProcessing); return switch (lockOptions.getLockMode()) { case PESSIMISTIC_WRITE -> "FOR UPDATE OF " + tableName; diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DerivedSqlIdentifier.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DerivedSqlIdentifier.java index 945793f8fa..c3bd07e1dd 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DerivedSqlIdentifier.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DerivedSqlIdentifier.java @@ -42,6 +42,7 @@ class DerivedSqlIdentifier implements SqlIdentifier { DerivedSqlIdentifier(String name, boolean quoted) { Assert.hasText(name, "A database object must have at least on name part."); + this.name = name; this.quoted = quoted; this.toString = quoted ? toSql(IdentifierProcessing.ANSI) : this.name; diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/DefaultSqlIdentifier.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/DefaultSqlIdentifier.java index f8de07d72a..085dc107b2 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/DefaultSqlIdentifier.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/sql/DefaultSqlIdentifier.java @@ -63,10 +63,11 @@ public SqlIdentifier transform(UnaryOperator transformationFunction) { public String toSql(IdentifierProcessing processing) { // using a local copy of volatile this.sqlName to ensure thread safety. - CachedSqlName sqlName = this.sqlName; + DefaultSqlIdentifier.CachedSqlName sqlName = this.sqlName; if (sqlName == null || sqlName.processing != processing) { - this.sqlName = sqlName = new CachedSqlName(processing, quoted ? processing.quote(name) : name); + String normalized = processing.standardizeLetterCase(name); + this.sqlName = sqlName = new CachedSqlName(processing, quoted ? processing.quote(normalized) : normalized); return sqlName.sqlName(); } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/dialect/PostgresDialectRenderingUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/dialect/PostgresDialectRenderingUnitTests.java index 2a5bbe98ed..3136c08ec9 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/dialect/PostgresDialectRenderingUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/dialect/PostgresDialectRenderingUnitTests.java @@ -68,7 +68,7 @@ public void shouldApplyNamingStrategy() { String sql = SqlRenderer.create(factory.createRenderContext()).render(select); - assertThat(sql).isEqualTo("SELECT FOO.* FROM FOO"); + assertThat(sql).isEqualTo("SELECT foo.* FROM foo"); } @Test // DATAJDBC-278 diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SqlIdentifierUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SqlIdentifierUnitTests.java index e035df66e4..fa51860404 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SqlIdentifierUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/SqlIdentifierUnitTests.java @@ -40,7 +40,7 @@ public void quotedSimpleObjectIdentifier() { SqlIdentifier identifier = quoted("someName"); - assertThat(identifier.toSql(BRACKETS_LOWER_CASE)).isEqualTo("[someName]"); + assertThat(identifier.toSql(BRACKETS_LOWER_CASE)).isEqualTo("[somename]"); assertThat(identifier.getReference()).isEqualTo("someName"); } @@ -50,7 +50,7 @@ public void unquotedSimpleObjectIdentifier() { SqlIdentifier identifier = unquoted("someName"); String sql = identifier.toSql(BRACKETS_LOWER_CASE); - assertThat(sql).isEqualTo("someName"); + assertThat(sql).isEqualTo("somename"); assertThat(identifier.getReference()).isEqualTo("someName"); } @@ -60,7 +60,7 @@ public void quotedMultipartObjectIdentifier() { SqlIdentifier identifier = SqlIdentifier.from(quoted("some"), quoted("name")); String sql = identifier.toSql(IdentifierProcessing.ANSI); - assertThat(sql).isEqualTo("\"some\".\"name\""); + assertThat(sql).isEqualTo("\"SOME\".\"NAME\""); } @Test // DATAJDBC-386 @@ -69,7 +69,7 @@ public void unquotedMultipartObjectIdentifier() { SqlIdentifier identifier = SqlIdentifier.from(unquoted("some"), unquoted("name")); String sql = identifier.toSql(IdentifierProcessing.ANSI); - assertThat(sql).isEqualTo("some.name"); + assertThat(sql).isEqualTo("SOME.NAME"); } @Test // DATAJDBC-386 diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java index 4f2121656e..ab68e71beb 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/core/sql/render/SelectRendererUnitTests.java @@ -606,7 +606,7 @@ void rendersLockAndOffsetUsingDialect() { String rendered = SqlRenderer.create(new RenderContextFactory(PostgresDialect.INSTANCE).createRenderContext()) .render(select); - assertThat(rendered).isEqualTo("SELECT User.name FROM User LIMIT 3 OFFSET 6 FOR UPDATE OF User"); + assertThat(rendered).isEqualTo("SELECT user.name FROM user LIMIT 3 OFFSET 6 FOR UPDATE OF user"); } @Test // GH-1007 diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/support/TableNameQueryPreprocessorUnitTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/support/TableNameQueryPreprocessorUnitTests.java index d1e6fdbc96..3ff29c3d71 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/repository/support/TableNameQueryPreprocessorUnitTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/repository/support/TableNameQueryPreprocessorUnitTests.java @@ -36,11 +36,11 @@ void transform() { softly.assertThat(preprocessor.transform("someString")).isEqualTo("someString"); softly.assertThat(preprocessor.transform("someString#{#tableName}restOfString")) - .isEqualTo("someString\"some_table_name\"restOfString"); + .isEqualTo("someString\"SOME_TABLE_NAME\"restOfString"); softly.assertThat(preprocessor.transform("select from #{#tableName} where x = :#{#some other spel}")) - .isEqualTo("select from \"some_table_name\" where x = :#{#some other spel}"); + .isEqualTo("select from \"SOME_TABLE_NAME\" where x = :#{#some other spel}"); softly.assertThat(preprocessor.transform("select from #{#qualifiedTableName}")) - .isEqualTo("select from \"qualified_table_name\""); + .isEqualTo("select from \"QUALIFIED_TABLE_NAME\""); }); } }