Package com.pugwoo.dbhelper.impl.part
Class P3_UpdateOp
java.lang.Object
com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
com.pugwoo.dbhelper.impl.part.P1_QueryOp
com.pugwoo.dbhelper.impl.part.P2_InsertOp
com.pugwoo.dbhelper.impl.part.P3_UpdateOp
- All Implemented Interfaces:
DBHelper,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
P4_InsertOrUpdateOp
-
Field Summary
Fields inherited from class com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
applicationContext, features, fetchSize, interceptors, jdbcTemplate, LOGGER, maxPageSize, namedParameterJdbcTemplate, timeoutWarningValve -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> intupdate(Collection<T> list) 批量更新数据库记录,返回数据库实际修改条数。【只更新非null字段,需要更新null字段请使用updateWithNull方法】
当符合以下条件时,更新数据将转换成真正的批量更新,性能可提升100倍左右:
1) list中所有的元素都是相同的类
2) list中所有的元素都有且只有一个主键,且主键有值(多主键场景很少,后续有时间再支持多主键)
特别说明:如果有cas版本,会抛出CasVersionNotMatchException异常(可以从该异常中获取实际的修改行数),需要自行注解@Transactional事务进行回滚,否则修改的数据不会回滚。此外,clickhouse不支持有cas的批量更新操作,一般情况下也不会使用clickhouse进行批量cas update操作。<T> intupdate(T t) 更新单条数据库记录,必须带上object的key。【只更新非null字段】<T> int更新单条数据库记录,必须带上object的key,主要用于mysql的update ...<T> int自定义更新多行记录,会自动去掉已软删除的行。 【重要更新 since 1.0.0】该方法修改的记录,不会再调用afterUpdate方法,如果需要获得被修改的行记录,请考虑使用canal方案。<T> intupdateCustom(T t, String setSql, Object... args) 自定义set字句更新,用于单个sql进行值更新,例如set reads = reads + 1这种情况。<T> intupdateWithNull(T t) 更新单个实例数据库记录,必须带上object的key,包含更新null值的字段<T> intupdateWithNull(T t, String postSql, Object... args) 带条件的更新单个对象,必须带上object的key,主要用于mysql的update ...Methods inherited from class com.pugwoo.dbhelper.impl.part.P2_InsertOp
insert, insert, insertBatchWithoutReturnId, insertBatchWithoutReturnId, insertBatchWithoutReturnId, insertWithNullMethods inherited from class com.pugwoo.dbhelper.impl.part.P1_QueryOp
getAll, getAll, getAllForStream, getAllForStream, getAllKey, getByExample, getByKey, getCount, getCount, getOne, getOne, getPage, getPage, getPageWithoutCount, getPageWithoutCount, getRaw, getRaw, getRawForStream, getRawForStream, getRawOne, getRawOne, handleRelatedColumn, handleRelatedColumn, handleRelatedColumn, handleRelatedColumn, isExist, isExistAtLeastMethods inherited from class com.pugwoo.dbhelper.impl.part.P0_JdbcTemplateOp
addComment, executeAfterCommit, getDatabaseType, getFeature, getJdbcTemplate, getNamedParameterJdbcTemplate, jdbcExecuteUpdate, log, logSlow, namedJdbcExecuteUpdate, namedJdbcExecuteUpdateWithLog, rollback, setApplicationContext, setFetchSize, setInterceptors, setJdbcTemplate, setMaxPageSize, setNamedParameterJdbcTemplate, setTimeoutWarningCallback, setTimeoutWarningValve, turnOffFeature, turnOnFeatureMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.pugwoo.dbhelper.DBHelper
delete, delete, delete, deleteHard, deleteHard, deleteHard, executeRaw, executeRaw, insertOrUpdate, insertOrUpdate, insertOrUpdateWithNull
-
Constructor Details
-
P3_UpdateOp
public P3_UpdateOp()
-
-
Method Details
-
update
Description copied from interface:DBHelper更新单条数据库记录,必须带上object的key。【只更新非null字段】- Parameters:
t- 更新的对象实例- Returns:
- 返回数据库实际修改条数
- Throws:
NullKeyValueException- 当对象t的主键值为null时抛出
-
update
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
Description copied from interface:DBHelper更新单个实例数据库记录,必须带上object的key,包含更新null值的字段- Parameters:
t- 更新的对象实例- Returns:
- 返回数据库实际修改条数
- Throws:
NullKeyValueException- 当对象t的主键值为null时抛出
-
updateWithNull
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
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
Description copied from interface:DBHelper自定义set字句更新,用于单个sql进行值更新,例如set reads = reads + 1这种情况。- Parameters:
t- 必须提供keysetSql- 可包含set关键字也可不包含,多个则用逗号隔开,【不能】包含where子句,例如a=a+1,c=b 或 set a=a+1,c=bargs- set子句的参数- Returns:
- 实际修改的条数
- Throws:
NullKeyValueException- 当t没有带上key时,抛出该异常
-
updateAll
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:
- 实际修改条数
-