From 20b3888334b6789f7d5a7950833a631733b84a95 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 6 Feb 2018 10:30:06 +0100 Subject: [PATCH 1/2] DATAJDBC-142 - Prepare branch --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 37b3d78c8c..0b4cb6273d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-jdbc - 1.0.0.BUILD-SNAPSHOT + 1.0.0.DATAJDBC-142-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. From 67b42cebc94208af23ed14232ca62f0d4072f79f Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 6 Feb 2018 10:52:00 +0100 Subject: [PATCH 2/2] DATAJDBC-142 - Using getName instead of getColumnName for constructing PropertyPaths. --- .../mapping/model/JdbcMappingContext.java | 2 +- .../model/JdbcMappingContextUnitTests.java | 84 +++++++++++++++++++ 2 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java diff --git a/src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java b/src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java index 570d4a8f92..d718d7dab0 100644 --- a/src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java +++ b/src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java @@ -83,7 +83,7 @@ public List referencedEntities(Class rootType, PropertyPath pat if (property.isEntity()) { PropertyPath nextPath = path == null ? PropertyPath.from(property.getName(), rootType) - : path.nested(property.getColumnName()); + : path.nested(property.getName()); paths.add(nextPath); paths.addAll(referencedEntities(rootType, nextPath)); } diff --git a/src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java b/src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java new file mode 100644 index 0000000000..0bdcd9fd75 --- /dev/null +++ b/src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java @@ -0,0 +1,84 @@ +/* + * Copyright 2018 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.jdbc.mapping.model; + +import org.junit.Test; +import org.springframework.data.mapping.PropertyPath; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; + +/** + * Unit tests for {@link JdbcMappingContext}. + * + * @author Jens Schauder + */ +public class JdbcMappingContextUnitTests { + + NamingStrategy namingStrategy = new DefaultNamingStrategy(); + NamedParameterJdbcOperations jdbcTemplate = mock(NamedParameterJdbcOperations.class); + ConversionCustomizer customizer = mock(ConversionCustomizer.class); + + @Test // DATAJDBC-142 + public void referencedEntitiesGetFound() { + + JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer); + + List propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null); + + assertThat(propertyPaths) // + .extracting(PropertyPath::toDotPath) // + .containsExactly( // + "one.two", // + "one" // + ); + } + + @Test // DATAJDBC-142 + public void propertyPathDoesNotDependOnNamingStrategy() { + + namingStrategy = mock(NamingStrategy.class); + + JdbcMappingContext mappingContext = new JdbcMappingContext(namingStrategy, jdbcTemplate, customizer); + + List propertyPaths = mappingContext.referencedEntities(DummyEntity.class, null); + + assertThat(propertyPaths) // + .extracting(PropertyPath::toDotPath) // + .containsExactly( // + "one.two", // + "one" // + ); + } + + private static class DummyEntity { + + String simpleProperty; + + LevelOne one; + } + + private static class LevelOne { + LevelTwo two; + } + + private static class LevelTwo { + String someValue; + } +} \ No newline at end of file