use of com.optimus.common.mybatis.PageList in project luntan by caoawei.
the class MybatisPageInterceptor method intercept.
@Override
public Object intercept(Invocation invocation) throws Throwable {
if (PageUtil.needPage() && sqlParser.isSupport(DBType.MYSQL)) {
Executor executor = (Executor) invocation.getTarget();
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
Object parameterObject = invocation.getArgs()[1];
BoundSql boundSql = ms.getBoundSql(parameterObject);
RowBounds rowBounds = (RowBounds) invocation.getArgs()[2];
ResultHandler resultHandler = (ResultHandler) invocation.getArgs()[3];
Connection connection = executor.getTransaction().getConnection();
String countSql = sqlParser.parseWithCountQuery(boundSql.getSql().trim());
BoundSql countBoundSql = copyBoundSql(ms, boundSql, countSql);
PreparedStatement ps = connection.prepareStatement(countSql);
setParameters(ps, ms, countBoundSql);
ResultSet resultSet = ps.executeQuery();
if (resultSet.next()) {
PageParam pageParam = resolvePageParam(resultSet);
PageList pageList = initPageList(pageParam);
String pageSql = sqlParser.parseWithPageQuery(boundSql.getSql().trim());
Utils.setFieldValue("sql", boundSql, pageSql);
List list = query(executor, ms, parameterObject, boundSql, rowBounds, resultHandler);
pageList.addAll(list);
return pageList;
}
resultSet.close();
connection.close();
}
return invocation.proceed();
}
Aggregations