Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Refactor ContextualValueExpressionEvaluator into Function, refactor BindingContext into nested class.

Simplify tests. Rename tests to reflect what they are actually doing. Reformat code.
  • Loading branch information
mp911de committed Oct 23, 2024
1 parent 21a1551 commit abe69bc
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.data.repository.query.QueryMethod;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ResultProcessor;
import org.springframework.data.repository.query.ValueExpressionDelegate;
import org.springframework.ldap.core.LdapOperations;
import org.springframework.ldap.query.LdapQuery;
import org.springframework.util.Assert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
public class AnnotatedLdapRepositoryQuery extends AbstractLdapRepositoryQuery {

private final Query queryAnnotation;
private final ValueExpressionDelegate valueExpressionDelegate;
private final StringBasedQuery stringBasedQuery;
private final StringBasedQuery stringBasedBase;
private final StringBasedQuery query;
private final StringBasedQuery base;
private final ValueEvaluationContextProvider valueContextProvider;

/**
* Construct a new instance.
Expand Down Expand Up @@ -81,34 +81,32 @@ public AnnotatedLdapRepositoryQuery(LdapQueryMethod queryMethod, Class<?> entity
Assert.notNull(queryMethod.getQueryAnnotation(), "Annotation must be present");
Assert.hasLength(queryMethod.getQueryAnnotation().value(), "Query filter must be specified");

queryAnnotation = queryMethod.getRequiredQueryAnnotation();
this.valueExpressionDelegate = valueExpressionDelegate;
stringBasedQuery = new StringBasedQuery(queryAnnotation.value(), queryMethod.getParameters(), valueExpressionDelegate);
stringBasedBase = new StringBasedQuery(queryAnnotation.base(), queryMethod.getParameters(), valueExpressionDelegate);
this.queryAnnotation = queryMethod.getRequiredQueryAnnotation();
this.query = new StringBasedQuery(queryAnnotation.value(), queryMethod.getParameters(), valueExpressionDelegate);
this.base = new StringBasedQuery(queryAnnotation.base(), queryMethod.getParameters(), valueExpressionDelegate);
this.valueContextProvider = valueExpressionDelegate.createValueContextProvider(getQueryMethod().getParameters());
}

@Override
protected LdapQuery createQuery(LdapParameterAccessor parameters) {

ValueEvaluationContextProvider valueContextProvider = valueExpressionDelegate
.createValueContextProvider(getQueryMethod().getParameters());
String query = bind(parameters, valueContextProvider, this.query);
String base = bind(parameters, valueContextProvider, this.base);

String boundQuery = bind(parameters, valueContextProvider, stringBasedQuery);

String boundBase = bind(parameters, valueContextProvider, stringBasedBase);

return query().base(boundBase) //
return query().base(base) //
.searchScope(queryAnnotation.searchScope()) //
.countLimit(queryAnnotation.countLimit()) //
.timeLimit(queryAnnotation.timeLimit()) //
.filter(boundQuery);
.filter(query, parameters.getBindableParameterValues());
}

private String bind(LdapParameterAccessor parameters, ValueEvaluationContextProvider valueContextProvider, StringBasedQuery query) {

ValueEvaluationContext evaluationContext = valueContextProvider
.getEvaluationContext(parameters.getBindableParameterValues(), query.getExpressionDependencies());

return query.bindQuery(parameters,
new ContextualValueExpressionEvaluator(valueExpressionDelegate, evaluationContext));
expression -> expression.evaluate(evaluationContext));
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Mark Paluch
* @since 2.6
*/
interface LdapParameterAccessor extends ParameterAccessor {
public interface LdapParameterAccessor extends ParameterAccessor {

/**
* Returns the bindable parameter values of the underlying query method.
Expand Down
Loading

0 comments on commit abe69bc

Please sign in to comment.