Class P3_UpdateOp

All Implemented Interfaces:
DBHelper, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware
Direct Known Subclasses:
P4_InsertOrUpdateOp

public abstract class P3_UpdateOp extends P2_InsertOp
  • Constructor Details

    • P3_UpdateOp

      public P3_UpdateOp()
  • Method Details

    • update

      public <T> int update(T t) throws NullKeyValueException
      Description copied from interface: DBHelper
      更新单条数据库记录,必须带上object的key。【只更新非null字段】
      Parameters:
      t - 更新的对象实例
      Returns:
      返回数据库实际修改条数
      Throws:
      NullKeyValueException - 当对象t的主键值为null时抛出
    • update

      public <T> int update(T t, String postSql, Object... args) throws NullKeyValueException
      Description copied from interface: DBHelper
      更新单条数据库记录,必须带上object的key,主要用于mysql的update ... where ...这样的CAS修改。 【只更新非null字段】
      Parameters:
      t - 更新的对象实例
      postSql - where及后续的sql,包含where关键字
      args - postSql中的参数
      Returns:
      返回数据库实际修改条数
      Throws:
      NullKeyValueException - 当对象t的主键值为null时抛出
    • updateWithNull

      public <T> int updateWithNull(T t) throws NullKeyValueException
      Description copied from interface: DBHelper
      更新单个实例数据库记录,必须带上object的key,包含更新null值的字段
      Parameters:
      t - 更新的对象实例
      Returns:
      返回数据库实际修改条数
      Throws:
      NullKeyValueException - 当对象t的主键值为null时抛出
    • updateWithNull

      public <T> int updateWithNull(T t, String postSql, Object... args) throws NullKeyValueException
      Description copied from interface: DBHelper
      带条件的更新单个对象,必须带上object的key,主要用于mysql的update ... where ...这样的CAS修改
      Parameters:
      t - 更新的对象实例
      postSql - where及后续的sql,包含where关键字
      args - postSql中的参数
      Returns:
      返回数据库实际修改条数
      Throws:
      NullKeyValueException - 当对象t的主键值为null时抛出
    • update

      public <T> int update(Collection<T> list) throws NullKeyValueException
      Description copied from interface: DBHelper
      批量更新数据库记录,返回数据库实际修改条数。【只更新非null字段,需要更新null字段请使用updateWithNull方法】

      当符合以下条件时,更新数据将转换成真正的批量更新,性能可提升100倍左右:
      1) list中所有的元素都是相同的类
      2) list中所有的元素都有且只有一个主键,且主键有值(多主键场景很少,后续有时间再支持多主键)
      特别说明:如果有cas版本,会抛出CasVersionNotMatchException异常(可以从该异常中获取实际的修改行数),需要自行注解@Transactional事务进行回滚,否则修改的数据不会回滚。此外,clickhouse不支持有cas的批量更新操作,一般情况下也不会使用clickhouse进行批量cas update操作。
      Parameters:
      list - 要更新的对象列表
      Returns:
      实际修改条数
      Throws:
      NullKeyValueException - 当对象列表中的对象的主键值为null时抛出
    • updateCustom

      public <T> int updateCustom(T t, String setSql, Object... args) throws NullKeyValueException
      Description copied from interface: DBHelper
      自定义set字句更新,用于单个sql进行值更新,例如set reads = reads + 1这种情况。
      Parameters:
      t - 必须提供key
      setSql - 可包含set关键字也可不包含,多个则用逗号隔开,【不能】包含where子句,例如a=a+1,c=b 或 set a=a+1,c=b
      args - set子句的参数
      Returns:
      实际修改的条数
      Throws:
      NullKeyValueException - 当t没有带上key时,抛出该异常
    • updateAll

      public <T> int updateAll(Class<T> clazz, String setSql, String whereSql, Object... args)
      Description copied from interface: DBHelper
      自定义更新多行记录,会自动去掉已软删除的行。 【重要更新 since 1.0.0】该方法修改的记录,不会再调用afterUpdate方法,如果需要获得被修改的行记录,请考虑使用canal方案。
      Parameters:
      clazz - 要更新的DO类
      setSql - update sql中的set sql子句,可以包括set关键字也可以不包括
      whereSql - update sql中的where sql子句,可以包括where关键字也可以不包括
      args - whereSql中的参数
      Returns:
      实际修改条数