-
Notifications
You must be signed in to change notification settings - Fork 29
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
FMWK-224 Add support for id projection query via Repository #614
Conversation
// No projection - target class will be the entity class. | ||
return queryMethod.getEntityInformation().getJavaType(); | ||
} | ||
|
||
public Query createQuery(ParametersParameterAccessor accessor, PartTree tree) { | ||
Constructor<? extends AbstractQueryCreator<?, ?>> constructor = ClassUtils | ||
.getConstructorIfAvailable(queryCreator, PartTree.class, ParameterAccessor.class); |
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.
Add validation
Assert.notNull(constructor, "constructor must not be null");
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.
The same assertion is the first line inside BeanUtils.instantiateClass()
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.
Lines 89-93 use
if (query.getCriteria() instanceof SpelExpression spelExpression) {
EvaluationContext context = this.evaluationContextProvider.getEvaluationContext(queryMethod.getParameters(),
parameters);
spelExpression.setEvaluationContext(context);
}
@@ -46,6 +50,8 @@ protected BaseAerospikePartTreeQuery(QueryMethod queryMethod, | |||
this.queryMethod = queryMethod; | |||
this.evaluationContextProvider = evalContextProvider; | |||
this.queryCreator = queryCreator; | |||
this.sourceClass = queryMethod.getEntityInformation().getJavaType(); | |||
|
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.
Remove empty line
public Query createQuery(ParametersParameterAccessor accessor, PartTree tree) { | ||
Constructor<? extends AbstractQueryCreator<?, ?>> constructor = ClassUtils | ||
.getConstructorIfAvailable(queryCreator, PartTree.class, ParameterAccessor.class); | ||
return (Query) BeanUtils.instantiateClass(constructor, tree, accessor).createQuery(); | ||
} | ||
|
||
protected static boolean isIdProjectionQuery(Class<?> targetClass, Object[] params, AerospikeCriteria criteria) { | ||
return targetClass != null && params.length > 0 && Objects.equals(criteria.get(FIELD), "id"); |
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.
params
can be null here
@@ -52,11 +53,27 @@ public Object execute(Object[] parameters) { | |||
|
|||
Class<?> targetClass = getTargetClass(accessor); | |||
|
|||
if (isIdProjectionQuery(targetClass, parameters, (AerospikeCriteria) query.getCriteria())) { |
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.
- Add a comment explaining this block
- Is
query.getCriteria()
always an AerospikeCriteria?
// Dynamic projection | ||
if (accessor.getParameters().hasDynamicProjection()) { | ||
return accessor.findDynamicProjection(); | ||
if (isIdProjectionQuery(targetClass, parameters, (AerospikeCriteria) query.getCriteria())) { |
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.
Add a comment explaining this block
No description provided.