List of usage examples for org.apache.ibatis.session RowBounds getOffset
public int getOffset()
From source file:com.yimidida.shards.plugin.PaginationInterceptor.java
License:Open Source License
@Override public Object intercept(Invocation invocation) throws Throwable { final MappedStatement mappedStatement = this.getMappedStatement(invocation); final Object parameter = this.getParameter(invocation); final RowBounds rowBounds = this.getRowBounds(invocation); final int offset = rowBounds.getOffset(); final int limit = rowBounds.getLimit(); if (dialect.supportLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) { BoundSql boundSql = mappedStatement.getBoundSql(parameter); String sql = boundSql.getSql().trim(); if (dialect.supportOffsetLimit()) { sql = dialect.getLimitString(sql, offset, limit); } else {// w w w. j av a2 s . c om sql = dialect.getLimitString(sql, RowBounds.NO_ROW_OFFSET, limit); } this.setMappedStatement(invocation, this.buildMappedStatement(mappedStatement, boundSql, sql)); this.setRowBounds(invocation, RowBounds.DEFAULT); } return invocation.proceed(); }
From source file:core.plugin.mybatis.dialect.H2Dialect.java
License:Apache License
/** * H2 SQL://w w w.j a v a 2 s .com * * <pre> * SELECT * FROM table limit MAX offset START * </pre> */ @Override public String getSqlWithPagination(String sql, RowBounds rowBounds) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append(sql).append(" limit " + rowBounds.getLimit() + " offset " + rowBounds.getOffset()); return sqlBuilder.toString(); }
From source file:core.plugin.mybatis.dialect.OracleDialect.java
License:Apache License
/** * ORACLE SQL:/*from w w w. ja v a 2 s . c o m*/ * * <pre> * SELECT * FROM ( * SELECT row_.*, ROWNUM rownum_ FROM ( * orginSQL * ) row_ WHERE ROWNUM <= MAX * ) * WHERE rownum_ > START * </pre> */ @Override public String getSqlWithPagination(String sql, RowBounds rowBounds) { StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.append("SELECT * FROM (SELECT row_.*, ROWNUM rownum_ FROM ( ").append(sql).append( " ) row_ WHERE ROWNUM <= " + rowBounds.getLimit() + ") WHERE rownum_ > " + rowBounds.getOffset()); return sqlBuilder.toString(); }
From source file:jp.co.ctc_g.jfw.core.jdbc.PartialListResultHandler.java
License:Apache License
/** * {@inheritDoc}//w ww .j a v a2 s. c om */ @Override public <E> List<E> createPaginatedResult(String statement, Object parameter, RowBounds rowBounds, Integer total, List<E> result) { int offset = rowBounds.getOffset(); int limit = rowBounds.getLimit(); return create(offset, limit, total, result, rowBoundsOrigin); }
From source file:org.fire.platform.common.page.Page.java
License:Open Source License
public Page(RowBounds rowBounds, int total) { this.pageSize = rowBounds.getLimit(); this.startRow = rowBounds.getOffset(); //RowBounds??countcount,?SQL_COUNT this.total = total; this.endRow = this.startRow + this.pageSize; }
From source file:org.nebula.service.dao.PaginationInterceptor.java
License:Apache License
public String newSql(String oldSql, RowBounds rowBounds) { return getLimitString(oldSql, rowBounds.getOffset(), Integer.toString(rowBounds.getOffset()), Integer.toString(rowBounds.getLimit())); }
From source file:org.smqk.framework.pagehelper.PageHelper.java
License:Open Source License
/** * ??//from w w w . j a va2 s . c o m * * @param rowBounds RowBounds? * @return Page */ private Page getPage(RowBounds rowBounds) { Page page = null; if (offsetAsPageNum) { page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new Page(rowBounds, rowBoundsWithCount); } return page; }
From source file:plum.mybatis.PaginationInterceptor.java
License:Apache License
/** * Set the paging information,to RowBuounds. * * @param rowBounds rowBounds.//from w w w.j a va 2 s. c o m * @return rowBounds. */ private static RowBounds offset_paging(RowBounds rowBounds) { // rowBuounds has offset. if (rowBounds.getOffset() == RowBounds.NO_ROW_OFFSET) { final PageQuery paginationCriteria = PAGINATION_CRITERIA_THREAD_LOCAL.get(); if (paginationCriteria != null) { return new RowBounds(paginationCriteria.getPage(), paginationCriteria.getPageSize()); } } return rowBounds; }
From source file:plum.mybatis.PaginationInterceptor.java
License:Apache License
/** * perform paging intercetion.//w w w .ja v a 2 s . com * * @param queryArgs Executor.query params. */ private void processIntercept(final Object[] queryArgs) { //queryArgs = query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) final MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX]; final Object parameter = queryArgs[PARAMETER_INDEX]; //the need for paging intercept. boolean interceptor = ms.getId().matches(_sql_regex); //obtain paging information. final PageQuery pageQuery = interceptor ? PagingParametersFinder.getInstance().findCriteria(parameter) : new PageQuery(PageQuery.DEFAULT_PAGE_SIZE); if (interceptor) { PAGINATION_CRITERIA_THREAD_LOCAL.set(pageQuery); } final RowBounds rowBounds = (interceptor) ? offset_paging((RowBounds) queryArgs[ROWBOUNDS_INDEX]) : (RowBounds) queryArgs[ROWBOUNDS_INDEX]; int offset = rowBounds.getOffset(); int limit = rowBounds.getLimit(); if (_dialect.supportsLimit() && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) { final BoundSql boundSql = ms.getBoundSql(parameter); String sql = boundSql.getSql().trim(); if (LOG.isDebugEnabled()) { LOG.debug("Pagination sql is <" + sql + ">"); } //implementation of the access to the total number of SQL,to obtain the total number and stored in the thread location Connection connection = null; try { //get connection connection = ms.getConfiguration().getEnvironment().getDataSource().getConnection(); int count = SQLHelp.getCount(sql, connection, ms, parameter, boundSql, _dialect); final Pager pager = new Pager(pageQuery.getPage(), pageQuery.getPageSize(), count); PAGINATION_COUNT.set(pager); } catch (SQLException e) { LOG.error("The total number of access to the database failure.", e); PAGINATION_COUNT.set(null); } finally { try { if (connection != null && !connection.isClosed()) { connection.close(); } } catch (SQLException e) { LOG.error("Close the database connection error.", e); } } if (_dialect.supportsLimit()) { 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; } }