
com.gitee.qdbp.jdbc.stream.CrudOnUpdateWhereByStream Maven / Gradle / Ivy
package com.gitee.qdbp.jdbc.stream;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.able.jdbc.condition.DbUpdate;
import com.gitee.qdbp.able.jdbc.condition.DbWhere;
import com.gitee.qdbp.jdbc.api.CrudDao;
/**
* UpdateSet+Where后续操作, 只有update!
*
* @author zhaohuihua
* @version 20210529
*/
public class CrudOnUpdateWhereByStream {
protected final CrudDao dao;
protected final DbUpdate ud;
protected final DbWhere where;
CrudOnUpdateWhereByStream(CrudDao dao, DbUpdate ud, DbWhere where) {
this.dao = dao;
this.ud = ud;
this.where = where;
}
/**
* 根据条件批量更新实体对象
*
int rows = qdbcBoot.crudStream(SysUser.class)
.setBy((ud) -> {
ud.set("userName").to("zhaohuihua"); // 用户名修改为指定值
// ud.set("memberScore").add(+100); // 会员积分增加100
// ud.set("memberScore").add(-100); // 会员积分减少100
// ud.set("userState").toNull(); // 用户状态修改为空
})
// .whereEquals("userId", "U0000001");
.whereBy((where) -> {
where.on("userId").equals("U0000001")
.and("userState").in(UserState.NORMAL, UserState.LOCKED)
.end();
})
.update();
*
*
* @return 受影响行数
* @throws ServiceException 操作失败
*/
public int update() throws ServiceException {
return dao.update(ud, where);
}
/**
* 根据条件批量更新实体对象
*
int rows = qdbcBoot.crudStream(SysUser.class)
.setBy((ud) -> {
ud.set("userName").to("zhaohuihua"); // 用户名修改为指定值
// ud.set("memberScore").add(+100); // 会员积分增加100
// ud.set("memberScore").add(-100); // 会员积分减少100
// ud.set("userState").toNull(); // 用户状态修改为空
})
// .whereEquals("userId", "U0000001");
.whereBy((where) -> {
where.on("userId").equals("U0000001")
.and("userState").in(UserState.NORMAL, UserState.LOCKED)
.end();
})
.update(true, true); // 自动填充更新参数, 受影响行数为0时抛异常
*
*
* @param fillUpdateParams 是否自动填充更新参数(修改人/修改时间等)
* @param errorOnUnaffected 受影响行数为0时是否抛异常
* @return 受影响行数
* @throws ServiceException 操作失败
*/
public int update(boolean fillUpdateParams, boolean errorOnUnaffected) throws ServiceException {
return dao.update(ud, where, fillUpdateParams, errorOnUnaffected);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy