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

cn.org.atool.fluent.mybatis.segment.where.ObjectWhere Maven / Gradle / Ivy

package cn.org.atool.fluent.mybatis.segment.where;

import cn.org.atool.fluent.mybatis.base.crud.IBaseQuery;
import cn.org.atool.fluent.mybatis.base.crud.IQuery;
import cn.org.atool.fluent.mybatis.functions.QFunction;
import cn.org.atool.fluent.mybatis.ifs.Ifs;
import cn.org.atool.fluent.mybatis.segment.WhereBase;

import java.util.Collection;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

import static cn.org.atool.fluent.mybatis.base.model.SqlOp.*;

/**
 * ObjectWhere
 *
 * @param  WHERE
 * @param     子查询
 * @author wudarui
 */
@SuppressWarnings({"unused", "unchecked", "rawtypes"})
public interface ObjectWhere<
    WHERE extends WhereBase,
    NQ extends IBaseQuery
    > extends BaseWhere {

    /**
     * 大于
     *
     * @param value 条件值
     * @return 查询器或更新器
     */
    default WHERE gt(Object value) {
        return this.apply(GT, value);
    }

    /**
     * 大于
     *
     * @param value 条件值
     * @param when  为真时成立
     * @return 查询器或更新器
     */
    default  WHERE gt(T value, Predicate when) {
        return this.apply(args -> when.test(value), GT, value);
    }

    /**
     * 按Ifs条件设置where值
     *
     * @param ifs if condition
     * @param  type
     * @return WHERE
     */
    default  WHERE gt(Ifs ifs) {
        return this.apply(GT, ifs);
    }

    /**
     * 大于等于
     *
     * @param value 条件值
     * @return 查询器或更新器
     */
    default WHERE ge(Object value) {
        return this.apply(GE, value);
    }

    /**
     * 大于等于
     *
     * @param value 条件值
     * @param when  为真时成立
     * @return 查询器或更新器
     */
    default  WHERE ge(T value, Predicate when) {
        return this.apply(args -> when.test(value), GE, value);
    }

    /**
     * 按Ifs条件设置where值
     *
     * @param ifs if conditions
     * @param  type
     * @return WHERE
     */
    default  WHERE ge(Ifs ifs) {
        return this.apply(GE, ifs);
    }

    /**
     * 小于
     *
     * @param value 条件值
     * @return 查询器或更新器
     */
    default WHERE lt(Object value) {
        return this.apply(LT, value);
    }

    /**
     * 小于
     *
     * @param value 条件值
     * @param when  为真时成立
     * @return 查询器或更新器
     */
    default  WHERE lt(T value, Predicate when) {
        return this.apply(args -> when.test(value), LT, value);
    }

    /**
     * 按Ifs条件设置where值
     *
     * @param ifs if conditions
     * @param  type
     * @return WHERE
     */
    default  WHERE lt(Ifs ifs) {
        return this.apply(LT, ifs);
    }

    /**
     * 小于等于
     *
     * @param value 条件值
     * @return 查询器或更新器
     */
    default WHERE le(Object value) {
        return this.apply(LE, value);
    }

    /**
     * 小于等于
     *
     * @param value 条件值
     * @param when  为真时成立
     * @return 查询器或更新器
     */
    default  WHERE le(T value, Predicate when) {
        return this.apply(args -> when.test(value), LE, value);
    }

    /**
     * 按Ifs条件设置where值
     *
     * @param ifs if conditions
     * @param  type
     * @return WHERE
     */
    default  WHERE le(Ifs ifs) {
        return this.apply(LE, ifs);
    }

    /**
     * in (values)
     *
     * @param values 条件值
     * @return 查询器或更新器
     */
    default WHERE in(Object[] values) {
        return this.apply(IN, values);
    }

    /**
     * in (values)
     *
     * @param values 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default  WHERE in(T[] values, Predicate when) {
        return this.apply(args -> when.test(values), IN, values);
    }

    /**
     * in (values)
     *
     * @param values 条件值
     * @return 查询器或更新器
     */
    default WHERE in(Collection values) {
        return this.apply(IN, values == null ? new Object[0] : values.toArray());
    }

    /**
     * in (values)
     *
     * @param values 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default WHERE in(Collection values, Predicate when) {
        return this.apply(args -> when.test(values), IN, values == null ? new Object[0] : values.toArray());
    }

    /**
     * 按Ifs条件设置where值
     *
     * @param ifs if conditions
     * @return WHERE
     */
    default WHERE in(Ifs ifs) {
        return this.apply(IN, ifs);
    }

    /**
     * where column IN (select ... )
     *
     * @param select 子查询语句
     * @param args   子查询语句参数,对应select语句里面的 "?" 占位符
     * @return 查询器或更新器
     */
     WHERE in(String select, O... args);

    /**
     * where column IN (select ... )
     *
     * @param condition true时条件成立
     * @param select    子查询语句
     * @param args      子查询语句参数,对应select语句里面的 "?" 占位符
     * @param        type
     * @return 查询器或更新器
     */
     WHERE in(boolean condition, String select, O... args);

    /**
     * in (select ... )
     *
     * @param query 嵌套查询
     * @return 查询器或更新器
     */
    WHERE in(QFunction query);

    /**
     * in (select ... )
     *
     * @param query 嵌套查询
     * @return 查询器或更新器
     */
    WHERE in(IQuery query);

    /**
     * in (select ... )
     *
     * @param condition true时条件成立
     * @param query     嵌套查询
     * @return 查询器或更新器
     */
    WHERE in(boolean condition, QFunction query);

    /**
     * in (select ... )
     *
     * @param condition true时条件成立
     * @param query     嵌套查询
     * @return 查询器或更新器
     */
    WHERE in(boolean condition, IQuery query);

    /**
     * not in (values)
     *
     * @param values 条件值
     * @return 查询器或更新器
     */
    default WHERE notIn(Object[] values) {
        return this.apply(NOT_IN, values);
    }

    /**
     * not in (values)
     *
     * @param values 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default  WHERE notIn(T[] values, Predicate when) {
        return this.apply(args -> when.test(values), NOT_IN, values);
    }

    /**
     * not in (values)
     *
     * @param values 条件值
     * @return 查询器或更新器
     */
    default WHERE notIn(Collection values) {
        return this.apply(NOT_IN, values == null ? new Object[0] : values.toArray());
    }

    /**
     * not in (values)
     *
     * @param values 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default WHERE notIn(Collection values, Predicate when) {
        return this.apply(args -> when.test(values), NOT_IN, values == null ? new Object[0] : values.toArray());
    }

    /**
     * not in (select ... )
     *
     * @param query 嵌套查询
     * @return 查询器或更新器
     */
    WHERE notIn(QFunction query);

    /**
     * not in (select ... )
     *
     * @param query 嵌套查询
     * @return WHERE
     */
    WHERE notIn(IQuery query);

    /**
     * not in (select ... )
     *
     * @param condition true时条件成立
     * @param query     嵌套查询
     * @return 查询器或更新器
     */
    WHERE notIn(boolean condition, QFunction query);

    /**
     * not in (select ... )
     *
     * @param condition true时条件成立
     * @param query     嵌套查询
     * @return 查询器或更新器
     */
    WHERE notIn(boolean condition, IQuery query);

    /**
     * @param value1 条件值
     * @param value2 条件值
     * @return 查询器或更新器
     */
    default  WHERE between(T value1, T value2) {
        return this.apply(BETWEEN, value1, value2);
    }

    /**
     * @param value1 条件值
     * @param value2 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default  WHERE between(T value1, T value2, BiPredicate when) {
        return this.apply(args -> when.test(value1, value2), BETWEEN, value1, value2);
    }

    /**
     * @param value1 条件值
     * @param value2 条件值
     * @return 查询器或更新器
     */
    default  WHERE notBetween(T value1, T value2) {
        return this.apply(NOT_BETWEEN, value1, value2);
    }

    /**
     * @param value1 条件值
     * @param value2 条件值
     * @param when   为真时成立
     * @return 查询器或更新器
     */
    default  WHERE notBetween(T value1, T value2, BiPredicate when) {
        return this.apply(args -> when.test(value1, value2), NOT_BETWEEN, value1, value2);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy