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

cn.vonce.sql.bean.Condition Maven / Gradle / Ivy

There is a newer version: 1.7.0-beta1
Show newest version
package cn.vonce.sql.bean;

import cn.vonce.sql.enumerate.SqlLogic;
import cn.vonce.sql.enumerate.SqlOperator;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 简单的条件
 *
 * @author Jovi
 * @version 1.0
 * @email [email protected]
 * @date 2022年3月15日上午10:00:10
 */
public class Condition implements Serializable {

    private Action action;
    private SqlLogic sqlLogic;
    private Logic logic = new Logic(this);
    private List dataList = new ArrayList<>();

    protected Condition(Action action){
        this.action = action;
    }

    protected Action getAction() {
        return action;
    }

    protected SqlLogic getSqlLogic() {
        return sqlLogic;
    }

    protected void setSqlLogic(SqlLogic sqlLogic) {
        this.sqlLogic = sqlLogic;
    }

    /**
     * 获得条件模型列表
     *
     * @return
     */
    public List getDataList() {
        return this.dataList;
    }

    /**
     * 等于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic eq(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 等于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic eq(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不等于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic notEq(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不等于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic notEq(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 小于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic lt(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 小于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic lt(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 大于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic gt(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 大于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic gt(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 小于等于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic ltEq(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 小于等于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic ltEq(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 大于等于
     *
     * @param field
     * @param value
     * @return
     */
    public Logic gtEq(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 大于等于
     *
     * @param column
     * @param value
     * @return
     */
    public Logic gtEq(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 全模糊 包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic like(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 全模糊 包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic like(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 左模糊 包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic likeL(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 左模糊 包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic likeL(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 右模糊 包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic likeR(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 右模糊 包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic likeR(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 全模糊 不包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic notLike(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 全模糊 不包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic notLike(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 左模糊 不包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic notLikeL(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 左模糊 不包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic notLikeL(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 右模糊 不包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic notLikeR(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 右模糊 不包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic notLikeR(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 是
     *
     * @param field
     * @param value
     * @return
     */
    public Logic is(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 是
     *
     * @param column
     * @param value
     * @return
     */
    public Logic is(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不是
     *
     * @param field
     * @param value
     * @return
     */
    public Logic isNot(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不是
     *
     * @param column
     * @param value
     * @return
     */
    public Logic isNot(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic in(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic in(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不包含
     *
     * @param field
     * @param value
     * @return
     */
    public Logic notIn(String field, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 不包含
     *
     * @param column
     * @param value
     * @return
     */
    public Logic notIn(Column column, Object value) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, value)));
        return logic;
    }

    /**
     * 介于
     *
     * @param field
     * @param value1
     * @param value2
     * @return
     */
    public Logic between(String field, Object value1, Object value2) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(field, SqlOperator.EQUAL_TO, new Object[]{value1, value2})));
        return logic;
    }

    /**
     * 介于
     *
     * @param column
     * @param value1
     * @param value2
     * @return
     */
    public Logic between(Column column, Object value1, Object value2) {
        dataList.add(new ConditionData(sqlLogic, newConditionInfo(column, SqlOperator.EQUAL_TO, new Object[]{value1, value2})));
        return logic;
    }

    private ConditionInfo newConditionInfo(String name, SqlOperator sqlOperator, Object value) {
        return new ConditionInfo(null, null, name, value, sqlOperator);
    }

    private ConditionInfo newConditionInfo(Column column, SqlOperator sqlOperator, Object value) {
        return new ConditionInfo(null, column.getTableAlias(), column.getName(), value, sqlOperator);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy