@Intercepts(value=@Signature(type=org.apache.ibatis.executor.Executor.class,method="update",args={org.apache.ibatis.mapping.MappedStatement.class,java.lang.Object.class}))
public class OptimisticLockerInterceptor
extends Object
implements org.apache.ibatis.plugin.Interceptor
Optimistic Lock Light version
Intercept on Executor.update;
Support version types: int/Integer, long/Long, java.util.Date, java.sql.Timestamp
For extra types, please define a subclass and override getUpdatedVersionVal() method.
How to use?
(1) Define an Entity and add Version annotation on one entity field.
(2) Add OptimisticLockerInterceptor into mybatis plugin.
How to work?
if update entity with version column=1:
(1) no OptimisticLockerInterceptor:
SQL: update tbl_test set name='abc' where id=100001;
(2) add OptimisticLockerInterceptor:
SQL: update tbl_test set name='abc',version=2 where id=100001 and version=1;
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
MP_OPTLOCK_ET_ORIGINAL |
| 构造器和说明 |
|---|
OptimisticLockerInterceptor() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected Object |
getUpdatedVersionVal(Object originalVersionVal)
This method provides the control for version value.
|
Object |
intercept(org.apache.ibatis.plugin.Invocation invocation) |
Object |
plugin(Object target) |
void |
setProperties(Properties properties) |
public Object intercept(org.apache.ibatis.plugin.Invocation invocation) throws Throwable
intercept 在接口中 org.apache.ibatis.plugin.InterceptorThrowableprotected Object getUpdatedVersionVal(Object originalVersionVal)
originalVersionVal - public void setProperties(Properties properties)
setProperties 在接口中 org.apache.ibatis.plugin.InterceptorCopyright © 2017. All rights reserved.