Browse Source

Polishing.

Simplify code. Remove redundant calls.

Reformat code, remove trailing whitespaces, remove duplicate tests.

See #1802
Original pull request: #1810
pull/1816/head
Mark Paluch 2 years ago
parent
commit
702002a538
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 15
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java
  2. 3
      spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java
  3. 15
      spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/DefaultAggregatePathUnitTests.java

15
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java

@ -26,6 +26,7 @@ import java.util.function.Function; @@ -26,6 +26,7 @@ import java.util.function.Function;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.converter.Converter;
@ -45,7 +46,6 @@ import org.springframework.data.relational.core.mapping.AggregatePath; @@ -45,7 +46,6 @@ import org.springframework.data.relational.core.mapping.AggregatePath;
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.SqlIdentifier;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
@ -384,15 +384,14 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -384,15 +384,14 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
// references and possibly keys, that form an id
if (idDefiningParentPath.hasIdProperty()) {
Class<?> idType = idDefiningParentPath.getRequiredIdProperty().getActualType();
//
RelationalPersistentProperty requiredIdProperty = idDefiningParentPath.getRequiredIdProperty();
AggregatePath idPath = idDefiningParentPath.append(requiredIdProperty);
Object idValue = delegate.getValue(idPath);
RelationalPersistentProperty identifier = idDefiningParentPath.getRequiredIdProperty();
AggregatePath idPath = idDefiningParentPath.append(identifier);
Object value = delegate.getValue(idPath);
Assert.state(idValue != null, "idValue must not be null at this point");
Assert.state(value != null, "Identifier value must not be null at this point");
identifierToUse = Identifier.of(aggregatePath.getTableInfo().reverseColumnInfo().name(), idValue, idType);
identifierToUse = Identifier.of(aggregatePath.getTableInfo().reverseColumnInfo().name(), value,
identifier.getActualType());
}
Iterable<Object> allByPath = relationResolver.findAllByPath(identifierToUse,

3
spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/AbstractJdbcAggregateTemplateIntegrationTests.java

@ -18,6 +18,7 @@ package org.springframework.data.jdbc.core; @@ -18,6 +18,7 @@ package org.springframework.data.jdbc.core;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.SoftAssertions.*;
import static org.springframework.data.jdbc.testing.TestConfiguration.*;
import static org.springframework.data.jdbc.testing.TestDatabaseFeatures.Feature.*;
@ -1294,7 +1295,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests { @@ -1294,7 +1295,7 @@ abstract class AbstractJdbcAggregateTemplateIntegrationTests {
First first1Reloaded = template.findById(first1.id, First.class);
First first2Reloaded = template.findById(first2.id, First.class);
SoftAssertions.assertSoftly(softly ->{
assertSoftly(softly -> {
softly.assertThat(first1Reloaded).isEqualTo(first1);
softly.assertThat(first2Reloaded).isEqualTo(first2);
});

15
spring-data-relational/src/test/java/org/springframework/data/relational/core/mapping/DefaultAggregatePathUnitTests.java

@ -202,7 +202,6 @@ class DefaultAggregatePathUnitTests { @@ -202,7 +202,6 @@ class DefaultAggregatePathUnitTests {
softly.assertThat(path("second2.third").isEmbedded()).isFalse();
softly.assertThat(path("second2.third2").isEmbedded()).isTrue();
softly.assertThat(path("second2").isEmbedded()).isTrue();
});
}
@ -467,20 +466,6 @@ class DefaultAggregatePathUnitTests { @@ -467,20 +466,6 @@ class DefaultAggregatePathUnitTests {
});
}
@Test // GH-1802
void dingens() {
assertSoftly(softly -> {
AggregatePath.TableInfo tableInfo = path("withId.second.third").getTableInfo();
AggregatePath idDefiningParentPath = path("withId.second.third").getIdDefiningParentPath();
AggregatePath.TableInfo parentTable = idDefiningParentPath.getTableInfo();
softly.assertThat(tableInfo.effectiveIdColumnName())
.isEqualTo(quoted("WITH_ID"));
});
}
@Test // GH-1525
void getLength() {

Loading…
Cancel
Save