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

cn.org.atool.fluent.mybatis.segment.UpdateApply Maven / Gradle / Ivy

There is a newer version: 1.9.9
Show newest version
package cn.org.atool.fluent.mybatis.segment;

import cn.org.atool.fluent.mybatis.base.crud.IBaseUpdate;
import cn.org.atool.fluent.mybatis.ifs.Ifs;
import cn.org.atool.fluent.mybatis.ifs.IfsPredicate;
import cn.org.atool.fluent.mybatis.segment.fragment.Column;

import java.util.function.Predicate;

import static cn.org.atool.fluent.mybatis.utility.MybatisUtil.assertNotBlank;

/**
 * SetObject 更新字段值
 *
 * @param  更新器
 * @author darui.wu
 */
@SuppressWarnings({"unchecked"})
public class UpdateApply<
    S extends UpdateBase,
    U extends IBaseUpdate
    > extends BaseApply {

    public UpdateApply(S setter) {
        super(setter);
    }

    /**
     * 

* 更新字段值: #{column}=value * value可以为null *

* * @param value 更新值 * @return 更新器 */ public S is(Object value) { Column column = Column.set(this.segment.wrapper, this.current()); this.segment.data().updateSet(column, value); return segment; } /** * 值更新为null: #{column} = null * * @return 更新器 */ public S isNull() { return this.is(null); } /** * 条件when成立时, 更新为value值 * * @param value 更新值 * @param when 当条件为真时设置更新 * @return 更新器 */ public S is(O value, Predicate when) { return when.test(value) ? this.is(value) : this.segment; } /** * 条件when成立时, 更新为value值 * * @param value 更新值 * @param condition 当条件为真时设置更新 * @return 更新器 */ public S is(O value, boolean condition) { return condition ? this.is(value) : this.segment; } /** * 按分支条件更新 * * @param ifs if conditions * @param type * @return ignore */ public S is(Ifs ifs) { /* 重载(实际入参为null)时兼容处理 **/ if (ifs == null) { return this.is((Object) null); } for (IfsPredicate predicate : ifs.predicates) { Object value = predicate.value(null); if (predicate.predicate.test(value)) { this.is(value); return this.segment; } } return this.segment; } /** * 按函数function更新, 示例 * apply( "concat('abc', ?)", "xyz"): 将字段赋值为 abc连接value("xyz") * * @param function 函数 * @param args 函数参数列表 * @return 更新器 */ public S applyFunc(String function, Object... args) { assertNotBlank("function", function); Column column = Column.set(this.segment.wrapper, this.current()); this.segment.data().updateSql(column, function, args); return this.segment; } /** * 按函数function更新, 示例 * apply( "concat('abc', ?)", "xyz"): 将字段赋值为 abc连接value("xyz") * * @param condition 条件为真时, 更新才被执行 * @param function 函数 * @param args 函数参数列表 * @return 更新器 */ public S applyFunc(boolean condition, String function, Object... args) { if (condition) { this.applyFunc(function, args); } return this.segment; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy