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

com.easy.query.api.proxy.client.EasyEntityQuery Maven / Gradle / Ivy

There is a newer version: 2.0.106
Show newest version
package com.easy.query.api.proxy.client;

import com.easy.query.api.proxy.entity.EntityQueryProxyManager;
import com.easy.query.api.proxy.entity.delete.EntityDeletable;
import com.easy.query.api.proxy.entity.delete.ExpressionDeletable;
import com.easy.query.api.proxy.entity.insert.EntityInsertable;
import com.easy.query.api.proxy.entity.select.EntityQueryable;
import com.easy.query.api.proxy.entity.update.EntityUpdatable;
import com.easy.query.api.proxy.entity.update.ExpressionUpdatable;
import com.easy.query.core.configuration.LoadIncludeConfiguration;
import com.easy.query.core.expression.lambda.SQLExpression1;
import com.easy.query.core.expression.lambda.SQLFuncExpression1;
import com.easy.query.core.proxy.PropColumn;
import com.easy.query.core.proxy.ProxyEntity;
import com.easy.query.core.proxy.ProxyEntityAvailable;
import com.easy.query.core.util.EasyCollectionUtil;
import com.easy.query.core.util.EasyObjectUtil;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * create time 2023/9/19 08:07
 * 文件说明
 *
 * @author xuejiaming
 */
public interface EasyEntityQuery extends EasyBaseQuery{
    , T extends ProxyEntityAvailable> EntityQueryable queryable(Class entityClass);
    , T extends ProxyEntityAvailable> EntityQueryable queryable(String sql, Class entityClass);
    , T extends ProxyEntityAvailable> EntityQueryable queryable(String sql, Class entityClass, Collection params);


    , T extends ProxyEntityAvailable> EntityInsertable insertable(T entity);

    , T extends ProxyEntityAvailable> EntityInsertable insertable(Collection entities);

    /**
     * 表达式更新 更新条件和set值需要自定义
     * @param entityClass
     * @return
     * @param 
     * @param 
     */
    , T extends ProxyEntityAvailable> ExpressionUpdatable updatable(Class entityClass);

    /**
     * 对象更新 更新条件默认是对象的主键
     * @param entity
     * @return
     * @param 
     * @param 
     */
    , T extends ProxyEntityAvailable> EntityUpdatable updatable(T entity);

    /**
     * 对象更新 更新条件默认是对象的主键
     * @param entities
     * @return
     * @param 
     * @param 
     */
    , T extends ProxyEntityAvailable> EntityUpdatable updatable(Collection entities);

    /**
     * 对象删除 删除条件为对象的主键
     * @param entity
     * @return
     * @param 
     * @param 
     */
    , T extends ProxyEntityAvailable> EntityDeletable deletable(T entity);

    /**
     * 对象删除 删除条件为对象的主键
     * @param entities
     * @return
     * @param 
     * @param 
     */

    , T extends ProxyEntityAvailable> EntityDeletable deletable(Collection entities);

    /**
     * 表达式删除,删除条件自定义
     * @param entityClass
     * @return
     * @param 
     * @param 
     */
    , T extends ProxyEntityAvailable> ExpressionDeletable deletable(Class entityClass);

    default  , T extends ProxyEntityAvailable>  void loadInclude(T entity, SQLFuncExpression1 navigateProperty){
        loadInclude(Collections.singletonList(entity),navigateProperty);
    }
    default , T extends ProxyEntityAvailable> void loadInclude(T entity,SQLFuncExpression1 navigateProperty, SQLExpression1 configure){
        loadInclude(Collections.singletonList(entity),navigateProperty,configure);
    }
    default , T extends ProxyEntityAvailable> void loadInclude(List entities,SQLFuncExpression1 navigateProperty){
        loadInclude(entities,navigateProperty,null);
    }
    default , T extends ProxyEntityAvailable> void loadInclude(List entities, SQLFuncExpression1 navigateProperty, SQLExpression1 configure){
        if(EasyCollectionUtil.isEmpty(entities)){
            return;
        }
        Class entityClass = EasyObjectUtil.typeCast(entities.get(0).getClass());
        TProxy tProxy = EntityQueryProxyManager.create(entityClass);
        PropColumn propColumn = navigateProperty.apply(tProxy);
        getEasyQueryClient().loadInclude(entities,propColumn.getValue(),configure);
    }
}