Class OptLogMybatisInterceptor
java.lang.Object
cn.sinozg.applet.common.interceptor.OptLogMybatisInterceptor
- All Implemented Interfaces:
org.apache.ibatis.plugin.Interceptor
@Signature(type=org.apache.ibatis.executor.statement.StatementHandler.class,method="batch",args=java.sql.Statement.class) @Signature(type=org.apache.ibatis.executor.statement.StatementHandler.class,method="update",args=java.sql.Statement.class)
public class OptLogMybatisInterceptor
extends Object
implements org.apache.ibatis.plugin.Interceptor
原生mybatis拦截器实现类 batch
- Since:
- 2024-02-27 18:24:18
- Author:
- xieyubin
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.commons.lang3.tuple.Pair<com.baomidou.mybatisplus.core.metadata.TableInfo,OptMapperTable> entityTable(String sql) 获取实体对象类型private ObjectgetProperty(Object bean, String propertyName) 获取字段private <T> Tprivate voidhandleDataLog(String methodId, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, org.apache.ibatis.mapping.SqlCommandType type, com.baomidou.mybatisplus.core.metadata.TableInfo tableInfo, org.apache.ibatis.session.Configuration configuration) 设置单次sql 的基本信息private intindexOfSqlStart(String sql) 获取sql语句开头部分intercept(org.apache.ibatis.plugin.Invocation invocation) private voidinterceptionChain(org.apache.ibatis.plugin.Invocation invocation) 记录日志private booleanisIgnoreMethod(String methodId) 是否忽略private ModeEnummodeEnum(org.apache.ibatis.mapping.SqlCommandType type, List<Map<String, Object>> newValues, Map<String, Map<String, Object>> oldValues) 判定执行类型newValueMap(Object object, OptMapperTable mapperTable, List<org.apache.ibatis.mapping.ParameterMapping> mappings) 获取到参数组成的原始数据 可能没有主键 update 可以是一个 eg:where for_key = ?oldValuesByDb(org.apache.ibatis.session.Configuration configuration, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, com.baomidou.mybatisplus.core.metadata.TableInfo tableInfo, String foreignIdName) 从数据库根据sql 条件查询原始数据转为 id:需要记录字段maponeSql(String originalSql, org.apache.ibatis.session.SqlSession sqlSession, String statementSql, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, String foreignIdName) 可能存在批量sql 执行单次sqlprivate ObjectsqlParams(org.apache.ibatis.mapping.BoundSql bound) 获取参数,参数必须为实体对象private Stringsql 值拼接valueMap(Object bean, OptMapperTable mapperTable, List<org.apache.ibatis.mapping.ParameterMapping> mappings, String foreignIdName) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.ibatis.plugin.Interceptor
setProperties
-
Field Details
-
properties
-
PLACEHOLDER
- See Also:
-
-
Constructor Details
-
OptLogMybatisInterceptor
-
-
Method Details
-
plugin
- Specified by:
pluginin interfaceorg.apache.ibatis.plugin.Interceptor
-
intercept
- Specified by:
interceptin interfaceorg.apache.ibatis.plugin.Interceptor- Throws:
Throwable
-
interceptionChain
private void interceptionChain(org.apache.ibatis.plugin.Invocation invocation) 记录日志- Parameters:
invocation- Invocation
-
handleDataLog
private void handleDataLog(String methodId, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, org.apache.ibatis.mapping.SqlCommandType type, com.baomidou.mybatisplus.core.metadata.TableInfo tableInfo, org.apache.ibatis.session.Configuration configuration) 设置单次sql 的基本信息- Parameters:
methodId- 请求idboundSql- boundSqlmapperTable- mapperTabletype- 类型tableInfo- 表配置configuration- configuration
-
modeEnum
private ModeEnum modeEnum(org.apache.ibatis.mapping.SqlCommandType type, List<Map<String, Object>> newValues, Map<String, Map<String, Object>> oldValues) 判定执行类型- Parameters:
type- 类型newValues- 新值oldValues- 旧值- Returns:
- 类型
-
oldValuesByDb
private Map<String,Map<String, oldValuesByDbObject>> (org.apache.ibatis.session.Configuration configuration, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, com.baomidou.mybatisplus.core.metadata.TableInfo tableInfo, String foreignIdName) 从数据库根据sql 条件查询原始数据转为 id:需要记录字段map- Parameters:
configuration- configurationboundSql- boundSqlmapperTable- mapperTabletableInfo- tableInfoforeignIdName- foreignIdName- Returns:
- 集合map
-
oneSql
private Map<String,Map<String, oneSqlObject>> (String originalSql, org.apache.ibatis.session.SqlSession sqlSession, String statementSql, org.apache.ibatis.mapping.BoundSql boundSql, OptMapperTable mapperTable, String foreignIdName) 可能存在批量sql 执行单次sql- Parameters:
originalSql- sql语句sqlSession- SessionstatementSql- statementSqlboundSql- boundSqlmapperTable- 映射foreignIdName- 外键- Returns:
- 数据集
-
sqlValue
sql 值拼接- Parameters:
obj- 对象- Returns:
- 值
-
indexOfSqlStart
获取sql语句开头部分- Parameters:
sql- ignore- Returns:
- ignore
-
isIgnoreMethod
是否忽略- Parameters:
methodId- 方法- Returns:
- 是否忽略
- Throws:
Exception- 异常
-
entityTable
private org.apache.commons.lang3.tuple.Pair<com.baomidou.mybatisplus.core.metadata.TableInfo,OptMapperTable> entityTable(String sql) 获取实体对象类型- Parameters:
sql- sql- Returns:
- 对象类型
-
sqlParams
获取参数,参数必须为实体对象- Parameters:
bound- bound- Returns:
- 实体
-
newValueMap
private List<Map<String,Object>> newValueMap(Object object, OptMapperTable mapperTable, List<org.apache.ibatis.mapping.ParameterMapping> mappings) 获取到参数组成的原始数据 可能没有主键 update 可以是一个 eg:where for_key = ? and stat = ? 可以是批量更新 insert 单个插入或者批量插入- Parameters:
object- 参数mapperTable- 实体对象配置- Returns:
- 集合
-
valueMap
-
getProperty
获取字段- Parameters:
bean- 实体propertyName- 属性名称- Returns:
- 值
- Throws:
IllegalAccessException- 异常
-
getTarget
-