类 OptimisticLockerInnerInterceptor

  • 所有已实现的接口:
    InnerInterceptor

    public class OptimisticLockerInnerInterceptor
    extends java.lang.Object
    implements InnerInterceptor
    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 OptimisticLockerInnerInterceptor into mybatis plugin.


    How to work?

    if update entity with version column=1:

    (1) no OptimisticLockerInnerInterceptor:

    SQL: update tbl_test set name='abc' where id=100001;

    (2) add OptimisticLockerInnerInterceptor:

    SQL: update tbl_test set name='abc',version=2 where id=100001 and version=1;

    从以下版本开始:
    3.4.0
    作者:
    yuxiaobin
    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型 方法 说明
      void beforeUpdate​(org.apache.ibatis.executor.Executor executor, org.apache.ibatis.mapping.MappedStatement ms, java.lang.Object parameter)
      Executor.update(MappedStatement, Object) 操作前置处理
      protected void doOptimisticLocker​(java.util.Map<java.lang.String,​java.lang.Object> map, java.lang.String msId)  
      protected java.lang.Object getUpdatedVersionVal​(java.lang.Class<?> clazz, java.lang.Object originalVersionVal)
      This method provides the control for version value.
      Returned value type must be the same as original one.
      void setException​(java.lang.RuntimeException exception)  
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • OptimisticLockerInnerInterceptor

        public OptimisticLockerInnerInterceptor()
    • 方法详细资料

      • setException

        public void setException​(java.lang.RuntimeException exception)
      • beforeUpdate

        public void beforeUpdate​(org.apache.ibatis.executor.Executor executor,
                                 org.apache.ibatis.mapping.MappedStatement ms,
                                 java.lang.Object parameter)
                          throws java.sql.SQLException
        从接口复制的说明: InnerInterceptor
        Executor.update(MappedStatement, Object) 操作前置处理

        改改sql啥的

        指定者:
        beforeUpdate 在接口中 InnerInterceptor
        参数:
        executor - Executor(可能是代理对象)
        ms - MappedStatement
        parameter - parameter
        抛出:
        java.sql.SQLException
      • doOptimisticLocker

        protected void doOptimisticLocker​(java.util.Map<java.lang.String,​java.lang.Object> map,
                                          java.lang.String msId)
      • getUpdatedVersionVal

        protected java.lang.Object getUpdatedVersionVal​(java.lang.Class<?> clazz,
                                                        java.lang.Object originalVersionVal)
        This method provides the control for version value.
        Returned value type must be the same as original one.
        参数:
        originalVersionVal - ignore
        返回:
        updated version val