@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 java.lang.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 java.lang.String |
MP_OPTLOCK_ET_ORIGINAL |
static java.lang.String |
MP_OPTLOCK_VERSION_COLUMN |
static java.lang.String |
MP_OPTLOCK_VERSION_ORIGINAL |
| 构造器和说明 |
|---|
OptimisticLockerInterceptor() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected java.lang.Object |
getUpdatedVersionVal(java.lang.Object originalVersionVal)
This method provides the control for version value.
|
java.lang.Object |
intercept(org.apache.ibatis.plugin.Invocation invocation) |
java.lang.Object |
plugin(java.lang.Object target) |
void |
setProperties(java.util.Properties properties) |
public static final java.lang.String MP_OPTLOCK_VERSION_ORIGINAL
public static final java.lang.String MP_OPTLOCK_VERSION_COLUMN
public static final java.lang.String MP_OPTLOCK_ET_ORIGINAL
public java.lang.Object intercept(org.apache.ibatis.plugin.Invocation invocation)
throws java.lang.Throwable
intercept 在接口中 org.apache.ibatis.plugin.Interceptorjava.lang.Throwableprotected java.lang.Object getUpdatedVersionVal(java.lang.Object originalVersionVal)
originalVersionVal - public java.lang.Object plugin(java.lang.Object target)
plugin 在接口中 org.apache.ibatis.plugin.Interceptorpublic void setProperties(java.util.Properties properties)
setProperties 在接口中 org.apache.ibatis.plugin.Interceptor