-
Notifications
You must be signed in to change notification settings - Fork 391
Caching path resolution #2336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schauder
wants to merge
2
commits into
main
Choose a base branch
from
issue/2335
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Caching path resolution #2336
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,20 +22,17 @@ | |
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import org.springframework.data.core.PropertyPath; | ||
| import org.springframework.data.core.PropertyReferenceException; | ||
| import org.springframework.data.core.TypeInformation; | ||
| import org.springframework.data.domain.Sort; | ||
| import org.springframework.data.jdbc.core.mapping.JdbcValue; | ||
| import org.springframework.data.jdbc.support.JdbcUtil; | ||
| import org.springframework.data.mapping.MappingException; | ||
| import org.springframework.data.mapping.PersistentPropertyAccessor; | ||
| import org.springframework.data.mapping.PersistentPropertyPath; | ||
| import org.springframework.data.mapping.context.MappingContext; | ||
| import org.springframework.data.relational.core.mapping.PropertyPathResolver; | ||
| import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; | ||
| import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; | ||
| import org.springframework.data.relational.core.query.CriteriaDefinition; | ||
|
|
@@ -63,6 +60,7 @@ public class QueryMapper { | |
|
|
||
| private final JdbcConverter converter; | ||
| private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext; | ||
| private final PropertyPathResolver propertyPathResolver; | ||
|
|
||
| /** | ||
| * Creates a new {@link QueryMapper} with the given {@link JdbcConverter}. | ||
|
|
@@ -75,6 +73,7 @@ public QueryMapper(JdbcConverter converter) { | |
|
|
||
| this.converter = converter; | ||
| this.mappingContext = converter.getMappingContext(); | ||
| this.propertyPathResolver = new PropertyPathResolver(this.mappingContext); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -305,7 +304,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc | |
|
|
||
| // IN/NOT_IN with collection of composite/embedded values: expand to (… AND …) OR (…) | ||
| if ((Comparator.IN.equals(comparator) || Comparator.NOT_IN.equals(comparator)) | ||
| && value instanceof Collection<?> collection) { | ||
| && value instanceof Collection<?> collection) { | ||
|
|
||
| Condition condition = null; | ||
|
|
||
|
|
@@ -760,6 +759,7 @@ public Comparator getComparator() { | |
| public boolean isIgnoreCase() { | ||
| return delegate.isIgnoreCase(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isGroup() { | ||
| return false; | ||
|
|
@@ -776,7 +776,6 @@ public SqlIdentifier getColumn() { | |
| return null; | ||
| } | ||
|
|
||
|
|
||
| @Nullable | ||
| @Override | ||
| public Object getValue() { | ||
|
|
@@ -863,7 +862,7 @@ public SQLType getSqlType() { | |
| /** | ||
| * Extension of {@link Field} to be backed with mapping metadata. | ||
| */ | ||
| protected static class MetadataBackedField extends Field { | ||
| protected class MetadataBackedField extends Field { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: removing |
||
|
|
||
| private final RelationalPersistentEntity<?> entity; | ||
| private final MappingContext<? extends RelationalPersistentEntity<?>, RelationalPersistentProperty> mappingContext; | ||
|
|
@@ -891,7 +890,7 @@ protected MetadataBackedField(SqlIdentifier name, RelationalPersistentEntity<?> | |
| this.entity = entity; | ||
| this.mappingContext = context; | ||
|
|
||
| this.path = getPath(name.getReference()); | ||
| this.path = propertyPathResolver.resolve(entity, name.getReference()); | ||
|
|
||
| RelationalPersistentProperty persistentProperty = null; | ||
| if (this.path != null) { | ||
|
|
@@ -923,39 +922,6 @@ public SqlIdentifier getMappedColumnName() { | |
| return this.property == null ? super.getMappedColumnName() : this.property.getColumnName(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the {@link PersistentPropertyPath} for the given {@code pathExpression}. | ||
| */ | ||
| @Nullable | ||
| private PersistentPropertyPath<RelationalPersistentProperty> getPath(String pathExpression) { | ||
|
|
||
| try { | ||
|
|
||
| PropertyPath path = forName(pathExpression); | ||
|
|
||
| if (isPathToJavaLangClassProperty(path)) { | ||
| return null; | ||
| } | ||
|
|
||
| return this.mappingContext.getPersistentPropertyPath(path); | ||
| } catch (MappingException | PropertyReferenceException e) { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private PropertyPath forName(String path) { | ||
|
|
||
| if (entity.getPersistentProperty(path) != null) { | ||
| return PropertyPath.from(Pattern.quote(path), entity.getTypeInformation()); | ||
| } | ||
|
|
||
| return PropertyPath.from(path, entity.getTypeInformation()); | ||
| } | ||
|
|
||
| private boolean isPathToJavaLangClassProperty(PropertyPath path) { | ||
| return path.getType().equals(Class.class) && path.getLeafProperty().getOwningType().getType().equals(Class.class); | ||
| } | ||
|
|
||
| @Nullable | ||
| public PersistentPropertyPath<RelationalPersistentProperty> getPath() { | ||
| return path; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QueryMapperis created quite frequently (e.g.AggregateReader.createCondition,StatementFactoryviaPartTreeJdbcQuery.executeorcreateDeleteQueries), therefore we create many instances of a cache that do not survive long enough to establish meaningful caching.