Search in sources :

Example 1 with SourceParameterExpressionImpl

use of io.micronaut.data.processor.model.criteria.impl.SourceParameterExpressionImpl in project micronaut-data by micronaut-projects.

the class RepositoryTypeElementVisitor method bindAdditionalParameters.

private void bindAdditionalParameters(MatchContext matchContext, SourcePersistentEntity entity, List<QueryParameterBinding> parameterBinding, ParameterElement[] parameters, Map<String, String> params) {
    if (CollectionUtils.isNotEmpty(params)) {
        Map<String, DataType> configuredDataTypes = Utils.getConfiguredDataTypes(matchContext.getRepositoryClass());
        for (Map.Entry<String, String> param : params.entrySet()) {
            ParameterElement parameter = Arrays.stream(parameters).filter(p -> p.stringValue(Parameter.class).orElse(p.getName()).equals(param.getValue())).findFirst().orElse(null);
            if (parameter == null) {
                throw new MatchFailedException("A @Where(..) definition requires a parameter called [" + param.getValue() + "] which is not present in the method signature.");
            }
            PersistentPropertyPath propertyPath = entity.getPropertyPath(parameter.getName());
            BindingParameter.BindingContext bindingContext = BindingParameter.BindingContext.create().name(param.getKey()).incomingMethodParameterProperty(propertyPath).outgoingQueryParameterProperty(propertyPath);
            QueryParameterBinding binding = new SourceParameterExpressionImpl(configuredDataTypes, matchContext.parameters, parameter, false).bind(bindingContext);
            parameterBinding.add(binding);
        }
    }
}
Also used : QueryParameterBinding(io.micronaut.data.model.query.builder.QueryParameterBinding) SourceParameterExpressionImpl(io.micronaut.data.processor.model.criteria.impl.SourceParameterExpressionImpl) PersistentPropertyPath(io.micronaut.data.model.PersistentPropertyPath) BindingParameter(io.micronaut.data.model.query.BindingParameter) DataType(io.micronaut.data.model.DataType) Parameter(io.micronaut.context.annotation.Parameter) BindingParameter(io.micronaut.data.model.query.BindingParameter) DataMethodQueryParameter(io.micronaut.data.intercept.annotation.DataMethodQueryParameter) ParameterElement(io.micronaut.inject.ast.ParameterElement) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

Parameter (io.micronaut.context.annotation.Parameter)1 DataMethodQueryParameter (io.micronaut.data.intercept.annotation.DataMethodQueryParameter)1 DataType (io.micronaut.data.model.DataType)1 PersistentPropertyPath (io.micronaut.data.model.PersistentPropertyPath)1 BindingParameter (io.micronaut.data.model.query.BindingParameter)1 QueryParameterBinding (io.micronaut.data.model.query.builder.QueryParameterBinding)1 SourceParameterExpressionImpl (io.micronaut.data.processor.model.criteria.impl.SourceParameterExpressionImpl)1 ParameterElement (io.micronaut.inject.ast.ParameterElement)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1