Browse Source

DATAJDBC-142 - Using getName instead of getColumnName for constructing PropertyPaths.

pull/37/merge
Jens Schauder 8 years ago committed by Greg Turnquist
parent
commit
31eeba743f
No known key found for this signature in database
GPG Key ID: CB2FA4D512B5C413
  1. 2
      src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java
  2. 84
      src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java

2
src/main/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContext.java

@ -91,7 +91,7 @@ public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEnt @@ -91,7 +91,7 @@ public class JdbcMappingContext extends AbstractMappingContext<JdbcPersistentEnt
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));
}

84
src/test/java/org/springframework/data/jdbc/mapping/model/JdbcMappingContextUnitTests.java

@ -0,0 +1,84 @@ @@ -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<PropertyPath> 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<PropertyPath> 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;
}
}
Loading…
Cancel
Save