Class DaoInterceptors

java.lang.Object
org.huiche.dao.support.DaoInterceptors
All Implemented Interfaces:
DaoInterceptor

public class DaoInterceptors extends Object implements DaoInterceptor
多个监听器
Author:
Maning
  • Field Summary

    Fields inherited from interface DaoInterceptor

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    默认实现
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterDelete(Class<?> entityClass, Statement statement, int result)
    删除之后
    void
    afterGet(Class<?> entityClass, Type resultType, Select select, Object result)
    单条查询执行之后
    void
    afterInsert(Class<?> entityClass, Object source, Insert insert, int result)
    插入执行之后
    已执行完毕,一般只用来记录
    void
    afterInsertBatch(Class<?> entityClass, List<?> sources, Insert insert, int result)
    批量插入执行之后
    已执行完毕,一般只用来记录
    如果原entities包含已赋值自增id和未赋值id两组,则会分开两组执行,调用2次
    void
    afterList(Class<?> entityClass, Type elementType, Select select, List<?> result)
    列表查询执行之后
    void
    afterPage(Class<?> entityClass, Type elementType, Pageable pageable, Page<?> result)
    分页查询执行之后
    void
    afterStream(Class<?> entityClass, Type elementType, Select select, Stream<?> result)
    stream查询执行之后
    void
    afterUpdate(Class<?> entityClass, Object source, Update update, int result)
    更新执行之后
    一般只用来记录
    beforeDelete(Class<?> entityClass, Statement statement)
    删除执行之前
    语句已生成, 可直接修改语句,或者返回新语句(如伪删除时Delete改Update)
    void
    beforeGet(Class<?> entityClass, Type resultType, Select select)
    单条查询执行之前,可调整语句,作用于业务参数之后
    void
    beforeInsert(Class<?> entityClass, Object source, Insert insert)
    插入执行之前
    此时已经 生成插入语句, 修改实体对象不会改变插入语句,但可以直接修改插入语句
    void
    beforeInsertBatch(Class<?> entityClass, List<?> sources, Insert insert)
    批量插入执行之前
    此时已经 生成插入语句, 修改实体对象不会改变插入语句,但可以直接修改插入语句
    如果 原entities包含已赋值自增id和未赋值id两组,则会分开两组执行,调用2次
    void
    beforeList(Class<?> entityClass, Type elementType, Select select)
    列表查询执行之前,可调整语句,作用于业务参数之后
    void
    beforeStream(Class<?> entityClass, Type elementType, Select select)
    stream查询执行之前,可调整语句,作用于业务参数之后
    void
    beforeUpdate(Class<?> entityClass, Object source, Update update)
    更新执行之前
    已生成更新语句, 修改实体类不会作用于语句, 但可直接修改语句
    preDelete(Class<?> entityClass)
    删除前置处理,先于before
    preGet(Class<?> entityClass, Type resultType)
    单条查询前置处理
    void
    preInsert(Class<?> entityClass, Object source)
    插入前置处理,先于before
    可在此处进行一些实体类额外修改操作, 如id注入,审计字段等
    void
    preInsertBatch(Class<?> entityClass, List<?> vos)
    批量插入前置处理,先于before
    可在此处进行一些实体类额外修改操作, 如id注入,审计字段等
    preList(Class<?> entityClass, Type elementType)
    列表查询前置处理
    void
    prePage(Class<?> entityClass, Type elementType, Pageable pageable)
    分页查询前置处理
    分页查询内部调用count(属于get)和list(属于collection)实现,所以无单独的before,此处仅用于拦截pageable或记录日志
    preStream(Class<?> entityClass, Type elementType)
    stream查询前置处理
    preUpdate(Class<?> entityClass, Object source)
    更新前置处理, 在before之前
    可在此处进行一些实体类额外修改操作, 如审计字段等

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DaoInterceptors

      public DaoInterceptors(List<DaoInterceptor> interceptors)
      默认实现
      Parameters:
      interceptors - 多个拦截器
  • Method Details

    • afterDelete

      public void afterDelete(Class<?> entityClass, Statement statement, int result)
      Description copied from interface: DaoInterceptor
      删除之后
      Specified by:
      afterDelete in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      statement - 语句
      result - 结果,变动条数(>=0)或错误代码
    • afterGet

      public void afterGet(Class<?> entityClass, Type resultType, Select select, Object result)
      Description copied from interface: DaoInterceptor
      单条查询执行之后
      Specified by:
      afterGet in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      resultType - 结果类型,仅用作记录,如果是optional查询,resultType只是其包裹类型,不带有Optional
      select - 查询语句,仅用作记录
      result - 查询结果
    • afterInsert

      public void afterInsert(Class<?> entityClass, Object source, Insert insert, int result)
      Description copied from interface: DaoInterceptor
      插入执行之后
      已执行完毕,一般只用来记录
      Specified by:
      afterInsert in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 值对象,一般为实体
      insert - 插入语句
      result - 结果,变动条数(>=0)或错误代码
    • afterInsertBatch

      public void afterInsertBatch(Class<?> entityClass, List<?> sources, Insert insert, int result)
      Description copied from interface: DaoInterceptor
      批量插入执行之后
      已执行完毕,一般只用来记录
      如果原entities包含已赋值自增id和未赋值id两组,则会分开两组执行,调用2次
      Specified by:
      afterInsertBatch in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      sources - 值对象,一般为实体
      insert - 插入语句
      result - 结果,变动条数(>=0)或错误代码
    • afterList

      public void afterList(Class<?> entityClass, Type elementType, Select select, List<?> result)
      Description copied from interface: DaoInterceptor
      列表查询执行之后
      Specified by:
      afterList in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      select - 查询语句,仅用作记录
      result - 结果
    • afterPage

      public void afterPage(Class<?> entityClass, Type elementType, Pageable pageable, Page<?> result)
      Description copied from interface: DaoInterceptor
      分页查询执行之后
      Specified by:
      afterPage in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      pageable - 分页
      result - 结果
    • afterStream

      public void afterStream(Class<?> entityClass, Type elementType, Select select, Stream<?> result)
      Description copied from interface: DaoInterceptor
      stream查询执行之后
      Specified by:
      afterStream in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      select - 查询语句,仅用作记录
      result - 结果
    • afterUpdate

      public void afterUpdate(Class<?> entityClass, Object source, Update update, int result)
      Description copied from interface: DaoInterceptor
      更新执行之后
      一般只用来记录
      Specified by:
      afterUpdate in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 要更新的实体,可能为空(如直接setter方式修改某列为null)
      update - 更新语句
      result - 结果,变动条数(>=0)或错误代码
    • beforeDelete

      public Statement beforeDelete(Class<?> entityClass, Statement statement)
      Description copied from interface: DaoInterceptor
      删除执行之前
      语句已生成, 可直接修改语句,或者返回新语句(如伪删除时Delete改Update)
      Specified by:
      beforeDelete in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      statement - 语句(可能已被前置拦截器修改为其他语句,如Update)
      Returns:
      语句,可以修改为其他语句,比如伪删除会将Delete改为update
    • beforeGet

      public void beforeGet(Class<?> entityClass, Type resultType, Select select)
      Description copied from interface: DaoInterceptor
      单条查询执行之前,可调整语句,作用于业务参数之后
      Specified by:
      beforeGet in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      resultType - 结果类型,仅做记录, 调整不再作用语句,如果是optional查询,resultType只是其包裹类型,不带有Optional
      select - 查询语句,可自行调整
    • beforeInsert

      public void beforeInsert(Class<?> entityClass, Object source, Insert insert)
      Description copied from interface: DaoInterceptor
      插入执行之前
      此时已经 生成插入语句, 修改实体对象不会改变插入语句,但可以直接修改插入语句
      Specified by:
      beforeInsert in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 值对象,一般为实体
      insert - 插入语句
    • beforeInsertBatch

      public void beforeInsertBatch(Class<?> entityClass, List<?> sources, Insert insert)
      Description copied from interface: DaoInterceptor
      批量插入执行之前
      此时已经 生成插入语句, 修改实体对象不会改变插入语句,但可以直接修改插入语句
      如果 原entities包含已赋值自增id和未赋值id两组,则会分开两组执行,调用2次
      Specified by:
      beforeInsertBatch in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      sources - 值对象,一般为实体
      insert - 插入语句
    • beforeList

      public void beforeList(Class<?> entityClass, Type elementType, Select select)
      Description copied from interface: DaoInterceptor
      列表查询执行之前,可调整语句,作用于业务参数之后
      Specified by:
      beforeList in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      select - 查询语句,可自行调整
    • beforeStream

      public void beforeStream(Class<?> entityClass, Type elementType, Select select)
      Description copied from interface: DaoInterceptor
      stream查询执行之前,可调整语句,作用于业务参数之后
      Specified by:
      beforeStream in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      select - 查询语句,可自行调整
    • beforeUpdate

      public void beforeUpdate(Class<?> entityClass, Object source, Update update)
      Description copied from interface: DaoInterceptor
      更新执行之前
      已生成更新语句, 修改实体类不会作用于语句, 但可直接修改语句
      Specified by:
      beforeUpdate in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 要更新的实体,可能为空(如直接setter方式修改某列为null)
      update - 更新语句,可自行调整
    • preDelete

      public Consumer<Delete> preDelete(Class<?> entityClass)
      Description copied from interface: DaoInterceptor
      删除前置处理,先于before
      Specified by:
      preDelete in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      Returns:
      删除语句自定义, 无需操作可以返回空操作或null,一般仅用于添加前置条件(早于dao其他参数传入的条件)
    • preGet

      public Consumer<Select> preGet(Class<?> entityClass, Type resultType)
      Description copied from interface: DaoInterceptor
      单条查询前置处理
      Specified by:
      preGet in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      resultType - 结果类型,仅做记录,如果是optional查询,resultType只是其包裹类型,不带有Optional
      Returns:
      无需自定义查询可返回null, 若需则返回, 会先于业务参数作用于语句
    • preInsert

      public void preInsert(Class<?> entityClass, Object source)
      Description copied from interface: DaoInterceptor
      插入前置处理,先于before
      可在此处进行一些实体类额外修改操作, 如id注入,审计字段等
      Specified by:
      preInsert in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 值对象,一般为实体
    • preInsertBatch

      public void preInsertBatch(Class<?> entityClass, List<?> vos)
      Description copied from interface: DaoInterceptor
      批量插入前置处理,先于before
      可在此处进行一些实体类额外修改操作, 如id注入,审计字段等
      Specified by:
      preInsertBatch in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      vos - 值对象,一般为实体
    • preList

      public Consumer<Select> preList(Class<?> entityClass, Type elementType)
      Description copied from interface: DaoInterceptor
      列表查询前置处理
      Specified by:
      preList in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      Returns:
      无需自定义查询可返回null, 若需则返回, 会先于业务参数作用于语句
    • prePage

      public void prePage(Class<?> entityClass, Type elementType, Pageable pageable)
      Description copied from interface: DaoInterceptor
      分页查询前置处理
      分页查询内部调用count(属于get)和list(属于collection)实现,所以无单独的before,此处仅用于拦截pageable或记录日志
      Specified by:
      prePage in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      pageable - 分页
    • preStream

      public Consumer<Select> preStream(Class<?> entityClass, Type elementType)
      Description copied from interface: DaoInterceptor
      stream查询前置处理
      Specified by:
      preStream in interface DaoInterceptor
      Parameters:
      entityClass - 实体类,仅做记录
      elementType - 元素类型,仅做记录
      Returns:
      无需自定义查询可返回null, 若需则返回, 会先于业务参数作用于语句
    • preUpdate

      public Consumer<Update> preUpdate(Class<?> entityClass, Object source)
      Description copied from interface: DaoInterceptor
      更新前置处理, 在before之前
      可在此处进行一些实体类额外修改操作, 如审计字段等
      Specified by:
      preUpdate in interface DaoInterceptor
      Parameters:
      entityClass - 实体类
      source - 要更新的值对象|实体,可能为空(如直接setter方式)
      Returns:
      更新自定义