Skip to content

Commit d68605b

Browse files
committed
Adapt to API changes in Spring Data Common's PersistentPropertyPathAccessor.
Fixes #1477. Related ticket: spring-projects/spring-data-commons#2813.
1 parent 2ed2d2e commit d68605b

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/JdbcAggregateChangeExecutionContext.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import org.springframework.data.jdbc.core.convert.JdbcConverter;
2828
import org.springframework.data.jdbc.core.convert.JdbcIdentifierBuilder;
2929
import org.springframework.data.mapping.PersistentProperty;
30-
import org.springframework.data.mapping.PersistentPropertyAccessor;
3130
import org.springframework.data.mapping.PersistentPropertyPath;
31+
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
3232
import org.springframework.data.mapping.context.MappingContext;
3333
import org.springframework.data.relational.core.conversion.DbAction;
3434
import org.springframework.data.relational.core.conversion.DbActionExecutionResult;
@@ -290,7 +290,8 @@ private <S> Object setIdAndCascadingProperties(DbAction.WithEntity<S> action, @N
290290

291291
RelationalPersistentEntity<S> persistentEntity = (RelationalPersistentEntity<S>) context
292292
.getRequiredPersistentEntity(action.getEntityType());
293-
PersistentPropertyAccessor<S> propertyAccessor = converter.getPropertyAccessor(persistentEntity, originalEntity);
293+
PersistentPropertyPathAccessor<S> propertyAccessor = converter.getPropertyAccessor(persistentEntity,
294+
originalEntity);
294295

295296
if (IdValueSource.GENERATED.equals(action.getIdValueSource())) {
296297
propertyAccessor.setProperty(persistentEntity.getRequiredIdProperty(), generatedId);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public SqlIdentifier getMappedColumnName() {
754754
throw new IllegalStateException("Cannot obtain a single column name for embedded property");
755755
}
756756

757-
if (this.property != null && this.path != null) {
757+
if (this.property != null && this.path != null && this.path.getParentPath() != null) {
758758

759759
RelationalPersistentProperty owner = this.path.getParentPath().getLeafProperty();
760760

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.springframework.data.mapping.Parameter;
3333
import org.springframework.data.mapping.PersistentEntity;
3434
import org.springframework.data.mapping.PersistentProperty;
35-
import org.springframework.data.mapping.PersistentPropertyAccessor;
35+
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
3636
import org.springframework.data.mapping.context.MappingContext;
3737
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
3838
import org.springframework.data.mapping.model.EntityInstantiators;
@@ -120,9 +120,10 @@ public CustomConversions getConversions() {
120120
}
121121

122122
@Override
123-
public <T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<T, ?> persistentEntity, T instance) {
123+
public <T> PersistentPropertyPathAccessor<T> getPropertyAccessor(PersistentEntity<T, ?> persistentEntity,
124+
T instance) {
124125

125-
PersistentPropertyAccessor<T> accessor = persistentEntity.getPropertyAccessor(instance);
126+
PersistentPropertyPathAccessor<T> accessor = persistentEntity.getPropertyPathAccessor(instance);
126127
return new ConvertingPropertyAccessor<>(accessor, conversionService);
127128
}
128129

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.data.mapping.Parameter;
2222
import org.springframework.data.mapping.PersistentEntity;
2323
import org.springframework.data.mapping.PersistentPropertyAccessor;
24+
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
2425
import org.springframework.data.mapping.context.MappingContext;
2526
import org.springframework.data.mapping.model.EntityInstantiators;
2627
import org.springframework.data.mapping.model.ParameterValueProvider;
@@ -72,7 +73,7 @@ <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> entity,
7273
* @param instance the instance to operate on. Must not be {@code null}.
7374
* @return guaranteed to be not {@code null}.
7475
*/
75-
<T> PersistentPropertyAccessor<T> getPropertyAccessor(PersistentEntity<T, ?> persistentEntity, T instance);
76+
<T> PersistentPropertyPathAccessor<T> getPropertyAccessor(PersistentEntity<T, ?> persistentEntity, T instance);
7677

7778
/**
7879
* Read a relational value into the desired {@link TypeInformation destination type}.

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/WritingContext.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ private boolean isDirectlyReferencedByRootIgnoringEmbeddables(
230230

231231
PersistentPropertyPath<RelationalPersistentProperty> currentPath = path.getParentPath();
232232

233-
while (!currentPath.isEmpty()) {
233+
while (currentPath != null) {
234234

235-
if (!currentPath.getRequiredLeafProperty().isEmbedded()) {
235+
if (!currentPath.getLeafProperty().isEmbedded()) {
236236
return false;
237237
}
238238
currentPath = currentPath.getParentPath();
@@ -242,9 +242,9 @@ private boolean isDirectlyReferencedByRootIgnoringEmbeddables(
242242
}
243243

244244
@Nullable
245-
private Object getFromRootValue(PersistentPropertyPath<RelationalPersistentProperty> path) {
245+
private Object getFromRootValue(@Nullable PersistentPropertyPath<RelationalPersistentProperty> path) {
246246

247-
if (path.getLength() == 0) {
247+
if (path == null) {
248248
return root;
249249
}
250250

@@ -254,7 +254,7 @@ private Object getFromRootValue(PersistentPropertyPath<RelationalPersistentPrope
254254
}
255255

256256
return context.getRequiredPersistentEntity(parent.getClass()).getPropertyAccessor(parent)
257-
.getProperty(path.getRequiredLeafProperty());
257+
.getProperty(path.getLeafProperty());
258258
}
259259

260260
private List<PathNode> createNodes(PersistentPropertyPath<RelationalPersistentProperty> path,

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public PersistentPropertyPathExtension(
8383

8484
public static boolean isWritable(PersistentPropertyPath<? extends RelationalPersistentProperty> path) {
8585

86-
return path.isEmpty() || (path.getRequiredLeafProperty().isWritable() && isWritable(path.getParentPath()));
86+
return path == null || path.getLeafProperty().isWritable() && isWritable(path.getParentPath());
8787
}
8888

8989
/**

0 commit comments

Comments
 (0)