List of usage examples for org.apache.ibatis.executor CachingExecutor getTransaction
@Override
public Transaction getTransaction()
From source file:com.monee1988.core.mybatis.pageinterceptor.PageInterceptor.java
License:Open Source License
void processMybatisIntercept(final Object[] queryArgs, Invocation invocation) { MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX]; Object parameter = queryArgs[PARAMETER_INDEX]; Page<?> page = null;/* w w w . ja v a 2 s .c om*/ if (parameter != null) { page = convertParameter(page, parameter); } if (dialect.supportsLimit() && page != null) { BoundSql boundSql = ms.getBoundSql(parameter); String sql = boundSql.getSql().trim(); final RowBounds rowBounds = (RowBounds) queryArgs[ROWBOUNDS_INDEX]; int offset = rowBounds.getOffset(); int limit = rowBounds.getLimit(); offset = page.getOffset(); limit = page.getPageSize(); CachingExecutor executor = (CachingExecutor) invocation.getTarget(); Transaction transaction = executor.getTransaction(); try { Connection connection = transaction.getConnection(); /** * */ this.setTotalRecord(page, ms, connection, parameter); } catch (SQLException e) { e.printStackTrace(); } if (dialect.supportsLimitOffset()) { sql = dialect.getLimitString(sql, offset, limit); offset = RowBounds.NO_ROW_OFFSET; } else { sql = dialect.getLimitString(sql, 0, limit); } limit = RowBounds.NO_ROW_LIMIT; queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit); BoundSql newBoundSql = copyFromBoundSql(ms, boundSql, sql); MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql)); queryArgs[MAPPED_STATEMENT_INDEX] = newMs; } }