Last active
October 19, 2022 10:16
-
-
Save jeffgbutler/a87f83754061eaa686abefb8016dde0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.ibatis.submitted.automapping; | |
import java.util.Properties; | |
import org.apache.ibatis.executor.Executor; | |
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.session.ResultHandler; | |
import org.apache.ibatis.session.RowBounds; | |
@Intercepts({ | |
@Signature(type=Executor.class, method="query", | |
args={MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class}), | |
@Signature(type=Executor.class, method="update", | |
args={MappedStatement.class, Object.class}) | |
}) | |
public class SqlPrintingInterceptor implements Interceptor { | |
@Override | |
public Object intercept(Invocation invocation) throws Throwable { | |
MappedStatement ms = (MappedStatement) invocation.getArgs()[0]; | |
Object parameter = invocation.getArgs()[1]; | |
System.out.println(ms.getBoundSql(parameter).getSql()); | |
return invocation.proceed(); | |
} | |
@Override | |
public Object plugin(Object target) { | |
return Plugin.wrap(target, this); | |
} | |
@Override | |
public void setProperties(Properties properties) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment