All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor Maven / Gradle / Ivy

There is a newer version: 3.5.7
Show newest version
/*
 * Copyright (c) 2011-2020, hubin ([email protected]).
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.baomidou.mybatisplus.extension.plugins; import java.util.Properties; import org.apache.ibatis.executor.Executor; import org.apache.ibatis.executor.statement.StatementHandler; import org.apache.ibatis.logging.Log; import org.apache.ibatis.logging.LogFactory; import org.apache.ibatis.mapping.MappedStatement; import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.plugin.Intercepts; import org.apache.ibatis.plugin.Invocation; import org.apache.ibatis.plugin.Plugin; import org.apache.ibatis.plugin.Signature; import org.apache.ibatis.reflection.SystemMetaObject; import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.RowBounds; import com.baomidou.mybatisplus.extension.handlers.AbstractSqlParserHandler; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; /** *

* //todo 苗神来改个名 * 防止全表更新与删除 *

* * @author hubin * @since 2016-08-16 */ @EqualsAndHashCode(callSuper = true) @Data @Accessors(chain = true) @Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})}) public class SqlExplainInterceptor extends AbstractSqlParserHandler implements Interceptor { private static final Log logger = LogFactory.getLog(SqlExplainInterceptor.class); private Properties properties; @Override public Object intercept(Invocation invocation) throws Throwable { Object[] args = invocation.getArgs(); MappedStatement ms = (MappedStatement) args[0]; Object parameter = args[1]; Configuration configuration = ms.getConfiguration(); Object target = invocation.getTarget(); StatementHandler handler = configuration.newStatementHandler((Executor) target, ms, parameter, RowBounds.DEFAULT, null, null); this.sqlParser(SystemMetaObject.forObject(handler)); return invocation.proceed(); } @Override public Object plugin(Object target) { if (target instanceof Executor) { return Plugin.wrap(target, this); } return target; } @Override public void setProperties(Properties prop) { this.properties = prop; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy