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

com.easy.query.api4j.select.Queryable4 Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.easy.query.api4j.select;

import com.easy.query.api4j.sql.SQLColumnAsSelector;
import com.easy.query.api4j.sql.SQLColumnResultSelector;
import com.easy.query.api4j.sql.SQLGroupBySelector;
import com.easy.query.api4j.sql.SQLOrderBySelector;
import com.easy.query.api4j.sql.SQLWhereAggregatePredicate;
import com.easy.query.api4j.sql.SQLWherePredicate;
import com.easy.query.api4j.sql.impl.SQLColumnResultSelectorImpl;
import com.easy.query.api4j.sql.impl.SQLWhereAggregatePredicateImpl;
import com.easy.query.core.api.client.EasyQueryClient;
import com.easy.query.core.basic.api.select.ClientQueryable4;
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.lambda.SQLExpression4;

import java.math.BigDecimal;
import java.util.function.Function;

/**
 * @author xuejiaming
 * @FileName: Queryable4.java
 * @Description: 文件说明
 * @Date: 2023/3/9 12:10
 */
public interface Queryable4 extends Queryable {
    ClientQueryable4 getClientQueryable4();

    //region where
    default Queryable4 whereById(Object id){
        return whereById(true,id);
    }
    Queryable4 whereById(boolean condition, Object id);
    default Queryable4 whereObject(Object object) {
        return whereObject(true, object);
    }

    Queryable4 whereObject(boolean condition, Object object);

    @Override
    default Queryable4 where(SQLExpression1> whereExpression) {
        return where(true, whereExpression);
    }

    @Override
    Queryable4 where(boolean condition, SQLExpression1> whereExpression);

    default Queryable4 where(SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> whereExpression) {
        return where(true, whereExpression);
    }

    Queryable4 where(boolean condition, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> whereExpression);

    //endregion
    //region select
     Queryable select(Class resultClass, SQLExpression4, SQLColumnAsSelector, SQLColumnAsSelector, SQLColumnAsSelector> selectExpression);
    //endregion

    //region aggregate

    /**
     * 防止溢出
     *
     * @param columnSelectorExpression
     * @param 
     * @return
     */
    default  BigDecimal sumBigDecimalOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().sumBigDecimalOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }


    default  BigDecimal sumBigDecimalOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, BigDecimal def) {
        return getClientQueryable4().sumBigDecimalOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  TMember sumOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().sumOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  TMember sumOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, TMember def) {
        return getClientQueryable4().sumOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  TMember maxOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().maxOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  TMember maxOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, TMember def) {
        return getClientQueryable4().maxOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  TMember minOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().minOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  TMember minOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, TMember def) {
        return getClientQueryable4().minOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  Double avgOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().avgOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  BigDecimal avgBigDecimalOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().avgBigDecimalOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  Float avgFloatOrNull(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression) {
        return getClientQueryable4().avgFloatOrNull((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        });
    }

    default  Double avgOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, Double def) {
        return getClientQueryable4().avgOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  BigDecimal avgBigDecimalOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, BigDecimal def) {
        return getClientQueryable4().avgBigDecimalOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  Float avgFloatOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, Float def) {
        return getClientQueryable4().avgFloatOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def);
    }

    default  TResult avgOrDefault(SQLExpression4, SQLColumnResultSelector, SQLColumnResultSelector, SQLColumnResultSelector> columnSelectorExpression, TResult def, Class resultClass) {
        return getClientQueryable4().avgOrDefault((selector1, selector2, selector3, selector4) -> {
            columnSelectorExpression.apply(new SQLColumnResultSelectorImpl<>(selector1), new SQLColumnResultSelectorImpl<>(selector2), new SQLColumnResultSelectorImpl<>(selector3), new SQLColumnResultSelectorImpl<>(selector4));
        }, def, resultClass);
    }
    //endregion


    //region group
    @Override
    default Queryable4 groupBy(SQLExpression1> selectExpression) {
        return groupBy(true, selectExpression);
    }

    @Override
    Queryable4 groupBy(boolean condition, SQLExpression1> selectExpression);

    default Queryable4 groupBy(SQLExpression4, SQLGroupBySelector, SQLGroupBySelector, SQLGroupBySelector> selectExpression) {
        return groupBy(true, selectExpression);
    }

    Queryable4 groupBy(boolean condition, SQLExpression4, SQLGroupBySelector, SQLGroupBySelector, SQLGroupBySelector> selectExpression);


    @Override
    default Queryable4 having(SQLExpression1> predicateExpression) {
        return having(true, predicateExpression);
    }

    @Override
    Queryable4 having(boolean condition, SQLExpression1> predicateExpression);

    default Queryable4 having(SQLExpression4, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate> predicateExpression) {
        getClientQueryable4().having((predicate1, predicate2, predicate3, predicate4) -> {
            predicateExpression.apply(new SQLWhereAggregatePredicateImpl<>(predicate1), new SQLWhereAggregatePredicateImpl<>(predicate2), new SQLWhereAggregatePredicateImpl<>(predicate3), new SQLWhereAggregatePredicateImpl<>(predicate4));
        });
        return this;
    }

    default Queryable4 having(boolean condition, SQLExpression4, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate> predicateExpression) {
        getClientQueryable4().having(condition, (predicate1, predicate2, predicate3, predicate4) -> {
            predicateExpression.apply(new SQLWhereAggregatePredicateImpl<>(predicate1), new SQLWhereAggregatePredicateImpl<>(predicate2), new SQLWhereAggregatePredicateImpl<>(predicate3), new SQLWhereAggregatePredicateImpl<>(predicate4));
        });
        return this;
    }

    //endregion
    //region order
    @Override
    default Queryable4 orderByAsc(SQLExpression1> selectExpression) {
        return orderByAsc(true, selectExpression);
    }

    @Override
    Queryable4 orderByAsc(boolean condition, SQLExpression1> selectExpression);

    default Queryable4 orderByAsc(SQLExpression4, SQLOrderBySelector, SQLOrderBySelector, SQLOrderBySelector> selectExpression) {
        return orderByAsc(true, selectExpression);
    }

    Queryable4 orderByAsc(boolean condition, SQLExpression4, SQLOrderBySelector, SQLOrderBySelector, SQLOrderBySelector> selectExpression);

    @Override
    default Queryable4 orderByDesc(SQLExpression1> selectExpression) {
        return orderByDesc(true, selectExpression);
    }

    @Override
    Queryable4 orderByDesc(boolean condition, SQLExpression1> selectExpression);

    default Queryable4 orderByDesc(SQLExpression4, SQLOrderBySelector, SQLOrderBySelector, SQLOrderBySelector> selectExpression) {
        return orderByDesc(true, selectExpression);
    }

    Queryable4 orderByDesc(boolean condition, SQLExpression4, SQLOrderBySelector, SQLOrderBySelector, SQLOrderBySelector> selectExpression);
    //endregion
    //region limit

    @Override
    default Queryable4 limit(long rows) {
        return limit(true, rows);
    }

    @Override
    default Queryable4 limit(boolean condition, long rows) {
        return limit(condition, 0, rows);
    }

    @Override
    default Queryable4 limit(long offset, long rows) {
        return limit(true, offset, rows);
    }

    @Override
    Queryable4 limit(boolean condition, long offset, long rows);

    default Queryable4 distinct() {
        return distinct(true);
    }

    Queryable4 distinct(boolean condition);
    //endregion

    @Override
    Queryable4 disableLogicDelete();

    @Override
    Queryable4 enableLogicDelete();

    @Override
    Queryable4 useLogicDelete(boolean enable);

    @Override
    Queryable4 noInterceptor();

    @Override
    Queryable4 useInterceptor();

    /**
     * 自动将查询结果集合全部添加到当前上下文追踪中,如果当前查询结果十分庞大,并且更新数据只有个别条数,建议不要使用
     * 追踪查询,可以通过开启追踪后使用普通的查询,然后添加到当前的追踪上下文中{@link EasyQueryClient#addTracking(Object)},开始先数据追踪的差异更新
     *
     * @return
     */
    @Override
    Queryable4 asTracking();

    @Override
    Queryable4 asNoTracking();

    @Override
    Queryable4 queryLargeColumn(boolean queryLarge);

    @Override
    Queryable4 useShardingConfigure(int maxShardingQueryLimit, ConnectionModeEnum connectionMode);

    @Override
    Queryable4 useMaxShardingQueryLimit(int maxShardingQueryLimit);

    @Override
    Queryable4 useConnectionMode(ConnectionModeEnum connectionMode);

    /**
     * 将当前表达式最近的一张表的表名修改成 {@param tableName}
     * 如果当前最近的表是正常的数据库表名,那么直接将表名改写
     * 如果当前最近的表是匿名表比如嵌套queryable的表那么将alias改成对应的表名
     *
     * @param tableName
     * @return
     */
    @Override
    default Queryable4 asTable(String tableName) {
        return asTable(old -> tableName);
    }

    /**
     * 将当前表达式最近的一张表的表名修改成 {@param tableNameAs}返回的表名
     * 如果当前最近的表是正常的数据库表名,那么直接将表名改写
     * 如果当前最近的表是匿名表比如嵌套queryable的表那么将alias改成对应的表名
     *
     * @param tableNameAs
     * @return
     */
    @Override
    Queryable4 asTable(Function tableNameAs);

    @Override
    default Queryable4 asSchema(String tableName) {
        return asSchema(old -> tableName);
    }

    @Override
    Queryable4 asSchema(Function schemaAs);

    @Override
    Queryable4 asAlias(String alias);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy