key, algorithm 디폴트값 수정
parent
5e331b873f
commit
d8f9cd21c4
@ -0,0 +1,113 @@
|
||||
package cokr.xit.foundation.data.paging;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.executor.parameter.ParameterHandler;
|
||||
import org.apache.ibatis.executor.resultset.ResultSetHandler;
|
||||
import org.apache.ibatis.executor.statement.StatementHandler;
|
||||
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.Signature;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.apache.ibatis.session.RowBounds;
|
||||
|
||||
import cokr.xit.foundation.AbstractComponent;
|
||||
|
||||
/**조회 결과의 페이징 처리를 지원하는 MyBatis Interceptor
|
||||
* @author mjkhan
|
||||
*/
|
||||
@Intercepts({
|
||||
@Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class, Integer.class}),
|
||||
@Signature(type = StatementHandler.class, method = "parameterize", args = {Statement.class}),
|
||||
@Signature(type = StatementHandler.class, method = "query", args = {Statement.class, ResultHandler.class}),
|
||||
@Signature(type = StatementHandler.class, method = "update", args = {Statement.class}),
|
||||
|
||||
@Signature(type = ParameterHandler.class, method = "getParameterObject", args = {}),
|
||||
@Signature(type = ParameterHandler.class, method = "setParameters", args = {PreparedStatement.class}),
|
||||
|
||||
@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}),
|
||||
|
||||
@Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})
|
||||
})
|
||||
public class MybatisPlugin extends AbstractComponent implements Interceptor {
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
Object target = invocation.getTarget();
|
||||
Method method = invocation.getMethod();
|
||||
Object[] args = invocation.getArgs();
|
||||
|
||||
String methodName = method.toString();
|
||||
System.out.println(methodName);
|
||||
|
||||
if (methodName.contains("Executor.query"))
|
||||
return query((Executor)target, (MappedStatement)args[0], args[1], (RowBounds)args[2], (ResultHandler<?>)args[3]);
|
||||
else if (methodName.contains("Executor.update"))
|
||||
return update((Executor)target, (MappedStatement)args[0], args[1]);
|
||||
|
||||
else if (methodName.contains("StatementHandler.prepare"))
|
||||
return prepare((StatementHandler)target, (Connection)args[0], (Integer)args[1]);
|
||||
else if (methodName.contains("StatementHandler.parameterize"))
|
||||
return parameterize((StatementHandler)target, (Statement)args[0]);
|
||||
else if (methodName.contains("StatementHandler.query"))
|
||||
return query((StatementHandler)target, (Statement)args[0], (ResultHandler<?>)args[1]);
|
||||
else if (methodName.contains("StatementHandler.update"))
|
||||
return update((StatementHandler)target, (Statement)args[0]);
|
||||
|
||||
else if (methodName.contains("ParameterHandler.getParameterObject"))
|
||||
return getParameterObject((ParameterHandler)target);
|
||||
else if (methodName.contains("ParameterHandler.setParameters"))
|
||||
return setParameters((ParameterHandler)target, (PreparedStatement)args[0]);
|
||||
|
||||
else if (methodName.contains("ResultSetHandler.handleResultSets"))
|
||||
return handle((ResultSetHandler)target, (Statement)args[0]);
|
||||
|
||||
else
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
protected Object query(Executor executor, MappedStatement mappedStatement, Object obj, RowBounds rowBounds, ResultHandler<?> resultHandler) throws SQLException {
|
||||
return executor.query(mappedStatement, obj, rowBounds, resultHandler);
|
||||
}
|
||||
|
||||
protected Object update(Executor executor, MappedStatement mappedStatement, Object obj) throws SQLException {
|
||||
return executor.update(mappedStatement, obj);
|
||||
}
|
||||
|
||||
protected Object prepare(StatementHandler statementHandler, Connection connection, Integer timeout) throws SQLException {
|
||||
return statementHandler.prepare(connection, timeout);
|
||||
}
|
||||
|
||||
protected Object parameterize(StatementHandler statementHandler, Statement statement) throws SQLException {
|
||||
statementHandler.parameterize(statement);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Object getParameterObject(ParameterHandler parameterHandler) {
|
||||
return parameterHandler.getParameterObject();
|
||||
}
|
||||
|
||||
protected Object setParameters(ParameterHandler parameterHandler, PreparedStatement statement) throws SQLException {
|
||||
parameterHandler.setParameters(statement);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Object query(StatementHandler statementHandler, Statement statement, ResultHandler<?> resultHandler) throws SQLException {
|
||||
return statementHandler.query(statement, resultHandler);
|
||||
}
|
||||
|
||||
protected int update(StatementHandler statementHandler, Statement statement) throws SQLException {
|
||||
return statementHandler.update(statement);
|
||||
}
|
||||
|
||||
protected Object handle(ResultSetHandler resultSetHandler, Statement statement) throws SQLException {
|
||||
return resultSetHandler.handleResultSets(statement);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue