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

com.github.wz2cool.dynamic.builder.SelectClauseBuilder Maven / Gradle / Ivy

There is a newer version: 3.2.32
Show newest version
package com.github.wz2cool.dynamic.builder;

import com.github.wz2cool.dynamic.DynamicQuery;
import com.github.wz2cool.dynamic.builder.direction.ISortDirection;
import com.github.wz2cool.dynamic.builder.opeartor.IFilterOperator;
import com.github.wz2cool.dynamic.helper.CommonsHelper;
import com.github.wz2cool.dynamic.lambda.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Frank
 */
public class SelectClauseBuilder implements IDynamicQueryBuilder {

    private final List selectedProperties = new ArrayList<>();
    private final DynamicQueryBuilder dynamicQueryBuilder;

    public SelectClauseBuilder(DynamicQueryBuilder dynamicQueryBuilder) {
        this.dynamicQueryBuilder = dynamicQueryBuilder;
        dynamicQueryBuilder.setSelectClauseBuilder(this);
    }

    public SelectClauseBuilder(DynamicQueryBuilder dynamicQueryBuilder,
                               GetCommonPropertyFunction[] getPropertyFunctions) {
        this.dynamicQueryBuilder = dynamicQueryBuilder;
        this.selectedProperties.addAll(getSelectedProperties(getPropertyFunctions));
        dynamicQueryBuilder.setSelectClauseBuilder(this);
    }

    String[] getSelectedProperties() {
        return selectedProperties.toArray(new String[0]);
    }

    @Override
    public DynamicQuery build() {
        return dynamicQueryBuilder.build();
    }

    @SafeVarargs
    public final SelectClauseBuilder select(GetCommonPropertyFunction... getPropertyFunctions) {
        this.selectedProperties.addAll(getSelectedProperties(getPropertyFunctions));
        return this;
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetBigDecimalPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetBytePropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetDatePropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetDoublePropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetFloatPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetIntegerPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetLongPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetShortPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    @SafeVarargs
    public final WhereClauseBuilder where(
            GetStringPropertyFunction getPropertyFunction, IFilterOperator filterOperator,
            ConditionClauseBuilder... conditionClauseBuilders) {
        return new WhereClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, filterOperator, conditionClauseBuilders);
    }

    public OrderByClauseBuilder orderBy(GetCommonPropertyFunction getPropertyFunction) {
        return new OrderByClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction);
    }

    public OrderByClauseBuilder orderBy(GetCommonPropertyFunction getPropertyFunction, ISortDirection direction) {
        return new OrderByClauseBuilder<>(dynamicQueryBuilder, getPropertyFunction, direction);
    }

    private List getSelectedProperties(GetCommonPropertyFunction[] getPropertyFunctions) {
        List result = new ArrayList<>();
        for (GetCommonPropertyFunction getPropertyFunction : getPropertyFunctions) {
            String propertyName = CommonsHelper.getPropertyName(getPropertyFunction);
            result.add(propertyName);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy