Skip to content
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

Merged
merged 6 commits into from
Aug 13, 2023

Conversation

agrgr
Copy link

@agrgr agrgr commented Aug 10, 2023

No description provided.

@agrgr agrgr requested a review from reugn August 10, 2023 14:37
// 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);
Copy link
Member

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");

Copy link
Author

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()

Copy link
Member

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();

Copy link
Member

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");
Copy link
Member

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())) {
Copy link
Member

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())) {
Copy link
Member

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

@agrgr agrgr merged commit f5eaebd into main Aug 13, 2023
@agrgr agrgr deleted the FMWK-224-id-projection-query-via-repository branch August 13, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants