Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.easy.query.api4j.select.Queryable Maven / Gradle / Ivy
package com.easy.query.api4j.select;
import com.easy.query.api4j.sql.SQLColumnAsSelector;
import com.easy.query.api4j.sql.SQLColumnSelector;
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.core.api.client.EasyQueryClient;
import com.easy.query.core.api.dynamic.sort.ObjectSort;
import com.easy.query.core.basic.api.internal.Interceptable;
import com.easy.query.core.basic.api.internal.LogicDeletable;
import com.easy.query.core.basic.api.internal.QueryStrategy;
import com.easy.query.core.basic.api.internal.TableReNameable;
import com.easy.query.core.basic.api.select.ClientQueryable;
import com.easy.query.core.basic.api.select.Query;
import com.easy.query.core.enums.sharding.ConnectionModeEnum;
import com.easy.query.core.exception.EasyQueryMultiPrimaryKeyException;
import com.easy.query.core.exception.EasyQueryNoPrimaryKeyException;
import com.easy.query.core.exception.EasyQueryOrderByInvalidOperationException;
import com.easy.query.core.exception.EasyQueryWhereInvalidOperationException;
import com.easy.query.core.expression.lambda.Property;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.lambda.SQLExpression2;
import com.easy.query.core.expression.segment.ColumnSegment;
import com.easy.query.core.util.EasyLambdaUtil;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
/**
* @author xuejiaming
* @FileName: Select0.java
* @Description: 文件说明
* @Date: 2023/2/6 21:28
*/
public interface Queryable extends Query,
Interceptable>,
LogicDeletable>,
TableReNameable>,
QueryStrategy> {
ClientQueryable getEntityQueryable();
/**
* 只clone表达式共享上下文
* 如果是两个独立的表达式建议重新创建如果是
*
* @return
*/
@Override
Queryable cloneQueryable();
long countDistinct(SQLExpression1> selectExpression);
/**
* SELECT NOT EXISTS (
* SELECT 1
* FROM `table` AS `t`
* WHERE (`t`.`columns` = ?))
*
* @param whereExpression 表达式最后一个是取反
* @return
*/
boolean all(SQLExpression1> whereExpression);
/**
* 防止溢出
*
* @param column
* @param
* @return
*/
default BigDecimal sumBigDecimalOrNull(Property column) {
return getEntityQueryable().sumBigDecimalOrNull(EasyLambdaUtil.getPropertyName(column));
}
default BigDecimal sumBigDecimalOrDefault(Property column, BigDecimal def) {
return getEntityQueryable().sumBigDecimalOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default TMember sumOrNull(Property column) {
return getEntityQueryable().sumOrNull(EasyLambdaUtil.getPropertyName(column));
}
default TMember sumOrDefault(Property column, TMember def) {
return getEntityQueryable().sumOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default > TMember maxOrNull(Property column) {
return getEntityQueryable().maxOrNull(EasyLambdaUtil.getPropertyName(column));
}
default > TMember maxOrDefault(Property column, TMember def) {
return getEntityQueryable().maxOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default TMember minOrNull(Property column) {
return getEntityQueryable().minOrNull(EasyLambdaUtil.getPropertyName(column));
}
default TMember minOrDefault(Property column, TMember def) {
return getEntityQueryable().minOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default Double avgOrNull(Property column) {
return getEntityQueryable().avgOrNull(EasyLambdaUtil.getPropertyName(column));
}
default BigDecimal avgBigDecimalOrNull(Property column) {
return getEntityQueryable().avgBigDecimalOrNull(EasyLambdaUtil.getPropertyName(column));
}
default Float avgFloatOrNull(Property column) {
return getEntityQueryable().avgFloatOrNull(EasyLambdaUtil.getPropertyName(column));
}
default Double avgOrDefault(Property column, Double def) {
return getEntityQueryable().avgOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default BigDecimal avgOrDefault(Property column, BigDecimal def) {
return getEntityQueryable().avgOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default Float avgOrDefault(Property column, Float def) {
return getEntityQueryable().avgOrDefault(EasyLambdaUtil.getPropertyName(column), def);
}
default TResult avgOrDefault(Property column, TResult def, Class resultClass) {
return getEntityQueryable().avgOrDefault(EasyLambdaUtil.getPropertyName(column), def, resultClass);
}
/**
* 对当前表达式返回自定义select列
*
* @param selectExpression
* @return
*/
Queryable select(SQLExpression1> selectExpression);
/**
* 将当前T1对象转成TR对象,select会将T1属性所对应的列名映射到TR对象的列名上(忽略大小写)
* T1.property1列名叫做column1,T1.property2列名叫做column2,TR.property3的列名也叫column1
* 那么生成的sql为:select column1 from t1
* 如果当前存在join,那么join的子表一律不会映射到resultClass上,如果需要那么请手动调用双参数select
*
* @param resultClass
* @param
* @return
*/
Queryable select(Class resultClass);
/**
* 设置返回对象,返回对象会根据selectExpression映射相同列名
* 多次select会在前一次基础上进行对上次结果进行匿名表处理
*
* @param resultClass
* @param selectExpression
* @param
* @return
*/
Queryable select(Class resultClass, SQLExpression1> selectExpression);
/**
* 设置column所有join表都会生效
*
* @param columns
* @return
*/
@Override
Queryable select(String columns);
default Queryable select(ColumnSegment columnSegment, boolean clearAll){
return select(Collections.singletonList(columnSegment), clearAll);
}
Queryable select(Collection columnSegments, boolean clearAll);
default Queryable where(SQLExpression1> whereExpression) {
return where(true, whereExpression);
}
Queryable where(boolean condition, SQLExpression1> whereExpression);
/**
* 根据id主键查询
*
* @param id 主键
* @return 链式表达式
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException @description 无主键或者多主键报错
*/
default Queryable whereById(Object id) {
return whereById(true, id);
}
/**
* @param condition
* @param id
* @return
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException @description 无主键或者多主键报错
*/
Queryable whereById(boolean condition, Object id);
/**
* @param ids
* @param
* @return
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
*/
default Queryable whereByIds(Collection ids) {
return whereByIds(true, ids);
}
/**
* 根据主键id集合查询
*
* @param condition 是否添加该条件
* @param ids 主键集合
* @param 主键类型
* @return 当前链式表达式
* @throws EasyQueryNoPrimaryKeyException,EasyQueryMultiPrimaryKeyException
*/
Queryable whereByIds(boolean condition, Collection ids);
/**
* @param object
* @return
* @throws EasyQueryWhereInvalidOperationException 当object的where属性和查询对象不匹配或者查询对象属性不匹配
*/
default Queryable whereObject(Object object) {
return whereObject(true, object);
}
/**
* @param condition
* @param object
* @return
* @throws EasyQueryWhereInvalidOperationException 当object的where属性和查询对象不匹配或者查询对象属性不匹配,无法获取 {@link SQLWherePredicate}
*/
Queryable whereObject(boolean condition, Object object);
default Queryable groupBy(SQLExpression1> selectExpression) {
return groupBy(true, selectExpression);
}
Queryable groupBy(boolean condition, SQLExpression1> selectExpression);
default Queryable having(SQLExpression1> predicateExpression) {
return having(true, predicateExpression);
}
Queryable having(boolean condition, SQLExpression1> predicateExpression);
default Queryable orderByAsc(SQLExpression1> selectExpression) {
return orderByAsc(true, selectExpression);
}
default Queryable orderByAsc(boolean condition, SQLExpression1> selectExpression) {
return orderBy(condition, selectExpression, true);
}
default Queryable orderByDesc(SQLExpression1> selectExpression) {
return orderByDesc(true, selectExpression);
}
default Queryable orderByDesc(boolean condition, SQLExpression1> selectExpression) {
return orderBy(condition, selectExpression, false);
}
default Queryable orderBy(SQLExpression1> selectExpression, boolean asc) {
return orderBy(true, selectExpression, asc);
}
Queryable orderBy(boolean condition, SQLExpression1> selectExpression, boolean asc);
/**
* @param configuration
* @return
* @throws EasyQueryOrderByInvalidOperationException 当配置{@link ObjectSort} 为{@code DynamicModeEnum.STRICT}排序设置的属性不存在当前排序对象里面或者当前查询对象无法获取 {@link SQLColumnSelector}
*/
default Queryable orderByObject(ObjectSort configuration) {
return orderByObject(true, configuration);
}
/**
* @param condition
* @param configuration
* @return
* @throws EasyQueryOrderByInvalidOperationException 当配置{@link ObjectSort} 为{@code DynamicModeEnum.STRICT}排序设置的属性不存在当前排序对象里面或者当前查询对象无法获取 {@link SQLColumnSelector}
*/
Queryable orderByObject(boolean condition, ObjectSort configuration);
default Queryable distinct() {
return distinct(true);
}
Queryable distinct(boolean condition);
@Override
default Queryable limit(long rows) {
return limit(true, rows);
}
@Override
default Queryable limit(boolean condition, long rows) {
return limit(condition, 0, rows);
}
@Override
default Queryable limit(long offset, long rows) {
return limit(true, offset, rows);
}
@Override
Queryable limit(boolean condition, long offset, long rows);
Queryable2 leftJoin(Class joinClass, SQLExpression2, SQLWherePredicate> on);
Queryable2 leftJoin(Queryable joinQueryable, SQLExpression2, SQLWherePredicate> on);
Queryable2 rightJoin(Class joinClass, SQLExpression2, SQLWherePredicate> on);
Queryable2 rightJoin(Queryable joinQueryable, SQLExpression2, SQLWherePredicate> on);
Queryable2 innerJoin(Class joinClass, SQLExpression2, SQLWherePredicate> on);
Queryable2 innerJoin(Queryable joinQueryable, SQLExpression2, SQLWherePredicate> on);
default Queryable union(Queryable unionQueryable) {
return union(Collections.singletonList(unionQueryable));
}
default Queryable union(Queryable unionQueryable1, Queryable unionQueryable2) {
return union(Arrays.asList(unionQueryable1, unionQueryable2));
}
default Queryable union(Queryable unionQueryable1, Queryable unionQueryable2, Queryable unionQueryable3) {
return union(Arrays.asList(unionQueryable1, unionQueryable2, unionQueryable3));
}
Queryable union(Collection> unionQueries);
default Queryable unionAll(Queryable unionQueryable) {
return unionAll(Collections.singletonList(unionQueryable));
}
default Queryable unionAll(Queryable unionQueryable1, Queryable unionQueryable2) {
return unionAll(Arrays.asList(unionQueryable1, unionQueryable2));
}
default Queryable unionAll(Queryable unionQueryable1, Queryable unionQueryable2, Queryable unionQueryable3) {
return unionAll(Arrays.asList(unionQueryable1, unionQueryable2, unionQueryable3));
}
Queryable unionAll(Collection> unionQueries);
/**
* 自动将查询结果集合全部添加到当前上下文追踪中,如果当前查询结果十分庞大,并且更新数据只有个别条数,建议不要使用
* 追踪查询,可以通过开启追踪后使用普通的查询,然后添加到当前的追踪上下文中{@link EasyQueryClient#addTracking(Object)},开始先数据追踪的差异更新
* 如果当前启用了追踪查询并且在当前上下文已经追加了当前trackKey的对象那么当前查询结果的对象不会被返回,返回的是被追踪的当前对象,
* 如果对象A:{id:1,name:2}已经被追踪了,新查询的结果是对象A:{id:1,name:3},那么查询到的数据是{id:1,name:3}但是用户获取到的数据是{id:1,name:2}
* 所以尽可能在追踪后调用entity update,而不是重复查询对应对象
*
* @return
*/
Queryable asTracking();
Queryable asNoTracking();
Queryable useShardingConfigure(int maxShardingQueryLimit, ConnectionModeEnum connectionMode);
Queryable useMaxShardingQueryLimit(int maxShardingQueryLimit);
Queryable useConnectionMode(ConnectionModeEnum connectionMode);
// SQLExpressionProvider getSQLExpressionProvider1();
}