From 95d3b63b1004de0be62af6178ebfbc2ecd594914 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 14 Dec 2023 08:07:29 +0100 Subject: [PATCH] Polishing. Remove duplicate and unused code. See #1695 --- .../data/jdbc/core/convert/QueryMapper.java | 1 - .../data/jdbc/core/convert/SqlContext.java | 3 +- .../SqlGeneratorEmbeddedUnitTests.java | 43 ++++++++++--------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java index 669564719..429d2c939 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/QueryMapper.java @@ -416,7 +416,6 @@ public class QueryMapper { PersistentPropertyAccessor embeddedAccessor = persistentEntity.getPropertyAccessor(criteria.getValue()); - String prefix = embeddedProperty.getEmbeddedPrefix(); Condition condition = null; for (RelationalPersistentProperty nestedProperty : persistentEntity) { diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlContext.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlContext.java index dbfa93497..49bdf3907 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlContext.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlContext.java @@ -61,8 +61,7 @@ class SqlContext { Column getColumn(AggregatePath path) { AggregatePath.ColumnInfo columnInfo = path.getColumnInfo(); - AggregatePath.ColumnInfo columnInfo1 = path.getColumnInfo(); - return getTable(path).column(columnInfo1.name()).as(columnInfo.alias()); + return getTable(path).column(columnInfo.name()).as(columnInfo.alias()); } Column getReverseColumn(AggregatePath path) { diff --git a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java index 6ce89c4da..900d9983a 100644 --- a/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java +++ b/spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlGeneratorEmbeddedUnitTests.java @@ -42,16 +42,16 @@ import org.springframework.lang.Nullable; * @author Bastian Wilhelm * @author Mark Paluch */ -public class SqlGeneratorEmbeddedUnitTests { +class SqlGeneratorEmbeddedUnitTests { private final RelationalMappingContext context = new JdbcMappingContext(); - JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> { + private JdbcConverter converter = new MappingJdbcConverter(context, (identifier, path) -> { throw new UnsupportedOperationException(); }); private SqlGenerator sqlGenerator; @BeforeEach - public void setUp() { + void setUp() { this.context.setForceQuote(false); this.sqlGenerator = createSqlGenerator(DummyEntity.class); } @@ -62,7 +62,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-111 - public void findOne() { + void findOne() { final String sql = sqlGenerator.getFindOne(); assertSoftly(softly -> { @@ -85,7 +85,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-111 - public void findAll() { + void findAll() { final String sql = sqlGenerator.getFindAll(); assertSoftly(softly -> { @@ -108,7 +108,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-111 - public void findAllInList() { + void findAllInList() { final String sql = sqlGenerator.getFindAllInList(); assertSoftly(softly -> { @@ -131,7 +131,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-111 - public void insert() { + void insert() { final String sql = sqlGenerator.getInsert(emptySet()); assertSoftly(softly -> { @@ -153,7 +153,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-111 - public void update() { + void update() { final String sql = sqlGenerator.getUpdate(); assertSoftly(softly -> { @@ -176,7 +176,7 @@ public class SqlGeneratorEmbeddedUnitTests { @Test // DATAJDBC-340 @Disabled // this is just broken right now - public void deleteByPath() { + void deleteByPath() { final String sql = sqlGenerator .createDeleteByPath(PersistentPropertyPathTestUtils.getPath("embedded.other", DummyEntity2.class, context)); @@ -193,7 +193,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void noJoinForEmbedded() { + void noJoinForEmbedded() { SqlGenerator.Join join = generateJoin("embeddable", DummyEntity.class); @@ -201,7 +201,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void columnForEmbeddedProperty() { + void columnForEmbeddedProperty() { assertThat(generatedColumn("embeddable.test", DummyEntity.class)) // .extracting( // @@ -217,20 +217,20 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // GH-1695 - public void columnForEmbeddedPropertyWithPrefix() { + void columnForEmbeddedPropertyWithPrefix() { assertThat(generatedColumn("nested.childId", WithEmbeddedAndAggregateReference.class)) .hasToString("a.nested_child_id AS nested_child_id"); } @Test // DATAJDBC-340 - public void noColumnForEmbedded() { + void noColumnForEmbedded() { assertThat(generatedColumn("embeddable", DummyEntity.class)) // .isNull(); } @Test // DATAJDBC-340 - public void noJoinForPrefixedEmbedded() { + void noJoinForPrefixedEmbedded() { SqlGenerator.Join join = generateJoin("prefixedEmbeddable", DummyEntity.class); @@ -238,7 +238,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void columnForPrefixedEmbeddedProperty() { + void columnForPrefixedEmbeddedProperty() { assertThat(generatedColumn("prefixedEmbeddable.test", DummyEntity.class)) // .extracting( // @@ -254,7 +254,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void noJoinForCascadedEmbedded() { + void noJoinForCascadedEmbedded() { SqlGenerator.Join join = generateJoin("embeddable.embeddable", DummyEntity.class); @@ -262,7 +262,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void columnForCascadedEmbeddedProperty() { + void columnForCascadedEmbeddedProperty() { assertThat(generatedColumn("embeddable.embeddable.attr1", DummyEntity.class)) // .extracting(c -> c.getName(), c -> c.getTable().getName(), c -> getAlias(c.getTable()), this::getAlias) @@ -271,7 +271,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void joinForEmbeddedWithReference() { + void joinForEmbeddedWithReference() { SqlGenerator.Join join = generateJoin("embedded.other", DummyEntity2.class); @@ -286,7 +286,7 @@ public class SqlGeneratorEmbeddedUnitTests { } @Test // DATAJDBC-340 - public void columnForEmbeddedWithReferenceProperty() { + void columnForEmbeddedWithReferenceProperty() { assertThat(generatedColumn("embedded.other.value", DummyEntity2.class)) // .extracting( // @@ -362,14 +362,15 @@ public class SqlGeneratorEmbeddedUnitTests { } @Table("a") + private record WithEmbeddedAndAggregateReference(@Id long id, @Embedded.Nullable(prefix = "nested_") WithAggregateReference nested) { } - record WithAggregateReference(AggregateReference childId) { + private record WithAggregateReference(AggregateReference childId) { } - record Child(@Id long id) { + private record Child(@Id long id) { }