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

com.easy.query.api4j.select.Queryable3 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.ClientQueryable3;
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.lambda.SQLExpression3;
import com.easy.query.core.expression.lambda.SQLExpression4;

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


/**
 * @FileName: Select3.java
 * @Description: 文件说明
 * @Date: 2023/2/6 22:44
 * @author xuejiaming
 */
public interface Queryable3 extends Queryable {

    ClientQueryable3 getClientQueryable3();

     Queryable4 leftJoin(Class joinClass, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);
     Queryable4 leftJoin(Queryable joinQueryable, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);
     Queryable4 rightJoin(Class joinClass, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);
     Queryable4 rightJoin(Queryable joinQueryable, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);

     Queryable4 innerJoin(Class joinClass, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);
     Queryable4 innerJoin(Queryable joinQueryable, SQLExpression4, SQLWherePredicate, SQLWherePredicate, SQLWherePredicate> on);

    //region where
    default Queryable3 whereById(Object id){
        return whereById(true,id);
    }
    Queryable3 whereById(boolean condition, Object id);
    default Queryable3 whereObject(Object object){
        return whereObject(true,object);
    }
    Queryable3 whereObject(boolean condition, Object object);
    @Override
    default Queryable3 where(SQLExpression1> whereExpression) {
        return where(true, whereExpression);
    }

    @Override
    Queryable3 where(boolean condition, SQLExpression1> whereExpression);
    default Queryable3 where(SQLExpression3, SQLWherePredicate, SQLWherePredicate> whereExpression) {
        return where(true, whereExpression);
    }

    Queryable3 where(boolean condition, SQLExpression3, SQLWherePredicate, SQLWherePredicate> whereExpression);

    //endregion

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

    //region aggregate

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    default Queryable3 groupBy(SQLExpression3, SQLGroupBySelector, SQLGroupBySelector> selectExpression) {
        return groupBy(true, selectExpression);
    }

    Queryable3 groupBy(boolean condition, SQLExpression3, SQLGroupBySelector, SQLGroupBySelector> selectExpression);


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

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

    default Queryable3 having(SQLExpression3, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate> predicateExpression) {
        getClientQueryable3().having((predicate1, predicate2, predicate3) -> {
            predicateExpression.apply(new SQLWhereAggregatePredicateImpl<>(predicate1), new SQLWhereAggregatePredicateImpl<>(predicate2), new SQLWhereAggregatePredicateImpl<>(predicate3));
        });
        return this;
    }

    default Queryable3 having(boolean condition, SQLExpression3, SQLWhereAggregatePredicate, SQLWhereAggregatePredicate> predicateExpression) {
        getClientQueryable3().having(condition, (predicate1, predicate2, predicate3) -> {
            predicateExpression.apply(new SQLWhereAggregatePredicateImpl<>(predicate1), new SQLWhereAggregatePredicateImpl<>(predicate2), new SQLWhereAggregatePredicateImpl<>(predicate3));
        });
        return this;
    }

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

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

    default Queryable3 orderByAsc(SQLExpression3, SQLOrderBySelector, SQLOrderBySelector> selectExpression) {
        return orderByAsc(true, selectExpression);
    }

    Queryable3 orderByAsc(boolean condition, SQLExpression3, SQLOrderBySelector, SQLOrderBySelector> selectExpression);

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

    @Override
    Queryable3 orderByDesc(boolean condition, SQLExpression1> selectExpression);
    default Queryable3 orderByDesc(SQLExpression3, SQLOrderBySelector, SQLOrderBySelector> selectExpression) {
        return orderByDesc(true, selectExpression);
    }

    Queryable3 orderByDesc(boolean condition, SQLExpression3, SQLOrderBySelector, SQLOrderBySelector> selectExpression);
    //endregion
    //region limit

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

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

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

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

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

    Queryable3 distinct(boolean condition);
    //endregion

    @Override
    Queryable3 disableLogicDelete();

    @Override
    Queryable3 enableLogicDelete();
    @Override
    Queryable3 useLogicDelete(boolean enable);

    @Override
    Queryable3 noInterceptor();
    @Override
    Queryable3 useInterceptor(String name);
    @Override
    Queryable3 noInterceptor(String name);
    @Override
    Queryable3 useInterceptor();

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

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

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

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

    @Override
    Queryable3 asSchema(Function schemaAs);

    @Override
    Queryable3 asAlias(String alias);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy