All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.data.runtime.query.internal.StoredQueryParameter Maven / Gradle / Ivy

There is a newer version: 4.10.5
Show newest version
/*
 * Copyright 2017-2022 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.data.runtime.query.internal;

import io.micronaut.core.annotation.Internal;
import io.micronaut.data.model.DataType;
import io.micronaut.data.model.JsonDataType;
import io.micronaut.data.model.runtime.QueryParameterBinding;

import java.util.Arrays;
import java.util.List;

/**
 * The stored query parameter.
 *
 * @author Denis Stepanov
 * @since 3.3
 */
@Internal
public final class StoredQueryParameter implements QueryParameterBinding {

    private final String name;
    private final DataType dataType;
    private final JsonDataType jsonDataType;
    private final int parameterIndex;
    private final String[] parameterBindingPath;
    private final String[] propertyPath;
    private final boolean autoPopulated;
    private final boolean requiresPreviousPopulatedValue;
    private final Class parameterConverterClass;
    private final boolean expandable;
    private final List all;
    private final boolean expression;
    private final Object value;

    private boolean previousInitialized;
    private QueryParameterBinding previousPopulatedValueParameter;

    StoredQueryParameter(String name,
                         DataType dataType,
                         JsonDataType jsonDataType,
                         int parameterIndex,
                         String[] parameterBindingPath,
                         String[] propertyPath,
                         boolean autoPopulated,
                         boolean requiresPreviousPopulatedValue,
                         Class parameterConverterClass,
                         boolean expandable,
                         final boolean expression,
                         Object value,
                         List all) {
        this.name = name;
        this.dataType = dataType;
        this.jsonDataType = jsonDataType;
        this.parameterIndex = parameterIndex;
        this.parameterBindingPath = parameterBindingPath;
        this.propertyPath = propertyPath;
        this.autoPopulated = autoPopulated;
        this.requiresPreviousPopulatedValue = requiresPreviousPopulatedValue;
        this.parameterConverterClass = parameterConverterClass;
        this.expandable = expandable;
        this.expression = expression;
        this.value = value;
        this.all = all;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public DataType getDataType() {
        return dataType;
    }

    @Override
    public JsonDataType getJsonDataType() {
        return jsonDataType;
    }

    @Override
    public Class getParameterConverterClass() {
        return parameterConverterClass;
    }

    @Override
    public int getParameterIndex() {
        return parameterIndex;
    }

    @Override
    public String[] getParameterBindingPath() {
        return parameterBindingPath;
    }

    @Override
    public String[] getPropertyPath() {
        return propertyPath;
    }

    @Override
    public boolean isAutoPopulated() {
        return autoPopulated;
    }

    @Override
    public boolean isRequiresPreviousPopulatedValue() {
        return requiresPreviousPopulatedValue;
    }

    @Override
    public QueryParameterBinding getPreviousPopulatedValueParameter() {
        if (!previousInitialized) {
            for (QueryParameterBinding it : all) {
                if (it != this && it.getParameterIndex() != -1 && Arrays.equals(propertyPath, it.getPropertyPath())) {
                    previousPopulatedValueParameter = it;
                    break;
                }
            }
            previousInitialized = true;
        }
        return previousPopulatedValueParameter;
    }

    @Override
    public boolean isExpandable() {
        return expandable;
    }

    @Override
    public boolean isExpression() {
        return expression;
    }

    @Override
    public Object getValue() {
        return value;
    }

    @Override
    public String toString() {
        return "StoredQueryParameter{" +
                "name='" + name + '\'' +
                ", dataType=" + dataType +
                ", parameterIndex=" + parameterIndex +
                ", parameterBindingPath=" + Arrays.toString(parameterBindingPath) +
                ", propertyPath=" + Arrays.toString(propertyPath) +
                ", autoPopulated=" + autoPopulated +
                ", requiresPreviousPopulatedValue=" + requiresPreviousPopulatedValue +
                ", previousPopulatedValueParameter=" + previousPopulatedValueParameter +
                ", expandable=" + expandable +
                ", expression=" + expression +
                ", value=" + value +
                '}';
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy