Skip to content

Commit ee01650

Browse files
committed
Reuse TypeInformation during PersistentPropertyPath and PersistentEntity lookups.
We now avoid Class -> TypeInformation conversion if we already have TypeInformation at hand. Closes #1679
1 parent d15359b commit ee01650

File tree

6 files changed

+13
-11
lines changed

6 files changed

+13
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public MappingJdbcConverter(RelationalMappingContext context, RelationResolver r
112112
}
113113

114114
@Nullable
115-
private Class<?> getEntityColumnType(Class<?> type) {
115+
private Class<?> getEntityColumnType(TypeInformation<?> type) {
116116

117117
RelationalPersistentEntity<?> persistentEntity = getMappingContext().getPersistentEntity(type);
118118

@@ -153,7 +153,7 @@ private Class<?> doGetColumnType(RelationalPersistentProperty property) {
153153
}
154154

155155
if (property.isEntity()) {
156-
Class<?> columnType = getEntityColumnType(property.getActualType());
156+
Class<?> columnType = getEntityColumnType(property.getTypeInformation().getActualType());
157157

158158
if (columnType != null) {
159159
return columnType;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ private SqlIdentifier getColumnNameToSortBy(Sort.Order order) {
837837
}
838838

839839
PersistentPropertyPath<RelationalPersistentProperty> persistentPropertyPath = mappingContext
840-
.getPersistentPropertyPath(order.getProperty(), entity.getType());
840+
.getPersistentPropertyPath(order.getProperty(), entity.getTypeInformation());
841841

842842
propertyToSortBy = persistentPropertyPath.getBaseProperty();
843843

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ private <S, T> SqlIdentifierParameterSource getParameterSource(@Nullable S insta
256256
if (property.isEmbedded()) {
257257

258258
Object value = propertyAccessor.getProperty(property);
259-
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getType());
259+
RelationalPersistentEntity<?> embeddedEntity = context.getPersistentEntity(property.getTypeInformation());
260260
SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value,
261261
(RelationalPersistentEntity<T>) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty);
262262
parameters.addAll(additionalParameters);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ protected <S> S readAggregate(ConversionContext context, RowDocumentAccessor doc
337337
return context.convert(documentAccessor, typeHint);
338338
}
339339

340-
RelationalPersistentEntity<?> entity = getMappingContext().getPersistentEntity(rawType);
340+
RelationalPersistentEntity<?> entity = getMappingContext().getPersistentEntity(typeHint);
341341

342342
if (entity == null) {
343343
throw new MappingException(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ public AggregatePath getParentPath() {
9191
public AggregatePath append(RelationalPersistentProperty property) {
9292

9393
PersistentPropertyPath<? extends RelationalPersistentProperty> newPath = isRoot() //
94-
? context.getPersistentPropertyPath(property.getName(), rootType.getType()) //
94+
? context.getPersistentPropertyPath(property.getName(), rootType.getTypeInformation()) //
9595
: context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(),
96-
path.getBaseProperty().getOwner().getType());
96+
path.getBaseProperty().getOwner().getTypeInformation());
9797

9898
return context.getAggregatePath(newPath);
9999
}
@@ -171,7 +171,8 @@ public PersistentPropertyPath<RelationalPersistentProperty> getRequiredPersisten
171171

172172
@Override
173173
public RelationalPersistentEntity<?> getLeafEntity() {
174-
return isRoot() ? rootType : context.getPersistentEntity(getRequiredLeafProperty().getActualType());
174+
return isRoot() ? rootType
175+
: context.getPersistentEntity(getRequiredLeafProperty().getTypeInformation().getActualType());
175176
}
176177

177178
@Override

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ public boolean isMultiValued() {
136136
*/
137137
@Nullable
138138
public RelationalPersistentEntity<?> getLeafEntity() {
139-
return path == null ? entity : context.getPersistentEntity(path.getLeafProperty().getActualType());
139+
return path == null ? entity
140+
: context.getPersistentEntity(path.getLeafProperty().getTypeInformation().getActualType());
140141
}
141142

142143
/**
@@ -363,8 +364,8 @@ public Class<?> getQualifierColumnType() {
363364
public PersistentPropertyPathExtension extendBy(RelationalPersistentProperty property) {
364365

365366
PersistentPropertyPath<? extends RelationalPersistentProperty> newPath = path == null //
366-
? context.getPersistentPropertyPath(property.getName(), entity.getType()) //
367-
: context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(), entity.getType());
367+
? context.getPersistentPropertyPath(property.getName(), entity.getTypeInformation()) //
368+
: context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(), entity.getTypeInformation());
368369

369370
return new PersistentPropertyPathExtension(context, newPath);
370371
}

0 commit comments

Comments
 (0)