From ee01650a7f08130607a87cb46c908eff322555a6 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 29 Nov 2023 09:47:57 +0100 Subject: [PATCH] Reuse `TypeInformation` during `PersistentPropertyPath` and `PersistentEntity` lookups. We now avoid Class -> TypeInformation conversion if we already have TypeInformation at hand. Closes #1679 --- .../data/jdbc/core/convert/MappingJdbcConverter.java | 4 ++-- .../data/jdbc/core/convert/SqlGenerator.java | 2 +- .../data/jdbc/core/convert/SqlParametersFactory.java | 2 +- .../core/conversion/MappingRelationalConverter.java | 2 +- .../data/relational/core/mapping/DefaultAggregatePath.java | 7 ++++--- .../core/mapping/PersistentPropertyPathExtension.java | 7 ++++--- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java index 0d444c1c..9d778824 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java @@ -112,7 +112,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements } @Nullable - private Class getEntityColumnType(Class type) { + private Class getEntityColumnType(TypeInformation type) { RelationalPersistentEntity persistentEntity = getMappingContext().getPersistentEntity(type); @@ -153,7 +153,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements } if (property.isEntity()) { - Class columnType = getEntityColumnType(property.getActualType()); + Class columnType = getEntityColumnType(property.getTypeInformation().getActualType()); if (columnType != null) { return columnType; diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java index 30581062..ded9e769 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java @@ -837,7 +837,7 @@ class SqlGenerator { } PersistentPropertyPath persistentPropertyPath = mappingContext - .getPersistentPropertyPath(order.getProperty(), entity.getType()); + .getPersistentPropertyPath(order.getProperty(), entity.getTypeInformation()); propertyToSortBy = persistentPropertyPath.getBaseProperty(); diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java index 752de547..85c9ed06 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java +++ b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlParametersFactory.java @@ -256,7 +256,7 @@ public class SqlParametersFactory { if (property.isEmbedded()) { Object value = propertyAccessor.getProperty(property); - RelationalPersistentEntity embeddedEntity = context.getPersistentEntity(property.getType()); + RelationalPersistentEntity embeddedEntity = context.getPersistentEntity(property.getTypeInformation()); SqlIdentifierParameterSource additionalParameters = getParameterSource((T) value, (RelationalPersistentEntity) embeddedEntity, prefix + property.getEmbeddedPrefix(), skipProperty); parameters.addAll(additionalParameters); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java index 94f2df11..91da5513 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java @@ -337,7 +337,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter impl return context.convert(documentAccessor, typeHint); } - RelationalPersistentEntity entity = getMappingContext().getPersistentEntity(rawType); + RelationalPersistentEntity entity = getMappingContext().getPersistentEntity(typeHint); if (entity == null) { throw new MappingException( diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java index 0c397562..cec97947 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/DefaultAggregatePath.java @@ -91,9 +91,9 @@ class DefaultAggregatePath implements AggregatePath { public AggregatePath append(RelationalPersistentProperty property) { PersistentPropertyPath newPath = isRoot() // - ? context.getPersistentPropertyPath(property.getName(), rootType.getType()) // + ? context.getPersistentPropertyPath(property.getName(), rootType.getTypeInformation()) // : context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(), - path.getBaseProperty().getOwner().getType()); + path.getBaseProperty().getOwner().getTypeInformation()); return context.getAggregatePath(newPath); } @@ -171,7 +171,8 @@ class DefaultAggregatePath implements AggregatePath { @Override public RelationalPersistentEntity getLeafEntity() { - return isRoot() ? rootType : context.getPersistentEntity(getRequiredLeafProperty().getActualType()); + return isRoot() ? rootType + : context.getPersistentEntity(getRequiredLeafProperty().getTypeInformation().getActualType()); } @Override diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java index 28dd8c12..34308868 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/PersistentPropertyPathExtension.java @@ -136,7 +136,8 @@ public class PersistentPropertyPathExtension { */ @Nullable public RelationalPersistentEntity getLeafEntity() { - return path == null ? entity : context.getPersistentEntity(path.getLeafProperty().getActualType()); + return path == null ? entity + : context.getPersistentEntity(path.getLeafProperty().getTypeInformation().getActualType()); } /** @@ -363,8 +364,8 @@ public class PersistentPropertyPathExtension { public PersistentPropertyPathExtension extendBy(RelationalPersistentProperty property) { PersistentPropertyPath newPath = path == null // - ? context.getPersistentPropertyPath(property.getName(), entity.getType()) // - : context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(), entity.getType()); + ? context.getPersistentPropertyPath(property.getName(), entity.getTypeInformation()) // + : context.getPersistentPropertyPath(path.toDotPath() + "." + property.getName(), entity.getTypeInformation()); return new PersistentPropertyPathExtension(context, newPath); }