Java Code Examples for org.apache.ibatis.session.RowBounds#getLimit()
The following examples show how to use
org.apache.ibatis.session.RowBounds#getLimit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OracleRowBoundsDialect.java From Mybatis-PageHelper with MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { int startRow = rowBounds.getOffset(); int endRow = rowBounds.getOffset() + rowBounds.getLimit(); StringBuilder sqlBuilder = new StringBuilder(sql.length() + 120); if (startRow > 0) { sqlBuilder.append("SELECT * FROM ( "); } if (endRow > 0) { sqlBuilder.append(" SELECT TMP_PAGE.*, ROWNUM ROW_ID FROM ( "); } sqlBuilder.append(sql); if (endRow > 0) { sqlBuilder.append(" ) TMP_PAGE WHERE ROWNUM <= "); sqlBuilder.append(endRow); pageKey.update(endRow); } if (startRow > 0) { sqlBuilder.append(" ) WHERE ROW_ID > "); sqlBuilder.append(startRow); pageKey.update(startRow); } return sqlBuilder.toString(); }
Example 2
Source File: HsqldbRowBoundsDialect.java From Mybatis-PageHelper with MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 20); sqlBuilder.append(sql); if (rowBounds.getLimit() > 0) { sqlBuilder.append(" LIMIT "); sqlBuilder.append(rowBounds.getLimit()); pageKey.update(rowBounds.getLimit()); } if (rowBounds.getOffset() > 0) { sqlBuilder.append(" OFFSET "); sqlBuilder.append(rowBounds.getOffset()); pageKey.update(rowBounds.getOffset()); } return sqlBuilder.toString(); }
Example 3
Source File: InformixRowBoundsDialect.java From Mybatis-PageHelper with MIT License | 6 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { StringBuilder sqlBuilder = new StringBuilder(sql.length() + 40); sqlBuilder.append("SELECT "); if (rowBounds.getOffset() > 0) { sqlBuilder.append(" SKIP "); sqlBuilder.append(rowBounds.getOffset()); pageKey.update(rowBounds.getOffset()); } if (rowBounds.getLimit() > 0) { sqlBuilder.append(" FIRST "); sqlBuilder.append(rowBounds.getLimit()); pageKey.update(rowBounds.getLimit()); } sqlBuilder.append(" * FROM ( "); sqlBuilder.append(sql); sqlBuilder.append(" ) TEMP_T"); return sqlBuilder.toString(); }
Example 4
Source File: SqlUtil.java From genericdao with Artistic License 2.0 | 6 votes |
/** * 获取分页参数 * * @param params RowBounds参数 * @return 返回Page对象 */ public PageHelper getPage(Object params) { PageHelper page = getLocalPage(); if (page == null) { if (params instanceof RowBounds) { RowBounds rowBounds = (RowBounds) params; if (offsetAsPageNum) { page = new PageHelper(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount); } else { page = new PageHelper(rowBounds, rowBoundsWithCount); } } else { page = getPageFromObject(params); } setLocalPage(page); } //分页合理化 if (page.getReasonable() == null) { page.setReasonable(reasonable); } //当设置为true的时候,如果pagesize设置为0(或RowBounds的limit=0),就不执行分页,返回全部结果 if (page.getPageSizeZero() == null) { page.setPageSizeZero(pageSizeZero); } return page; }
Example 5
Source File: PageHelper.java From genericdao with Artistic License 2.0 | 5 votes |
public PageHelper(RowBounds rowBounds, int total) { super(rowBounds.getLimit() > -1 ? rowBounds.getLimit() : 0); this.pageSize = rowBounds.getLimit(); this.startRow = rowBounds.getOffset(); //RowBounds方式默认不求count总数,如果想求count,可以修改这里为SQL_COUNT this.total = total; this.endRow = this.startRow + this.pageSize; }
Example 6
Source File: Db2RowBoundsDialect.java From Mybatis-PageHelper with MIT License | 5 votes |
@Override public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) { int startRow = rowBounds.getOffset() + 1; int endRow = rowBounds.getOffset() + rowBounds.getLimit(); StringBuilder sqlBuilder = new StringBuilder(sql.length() + 120); sqlBuilder.append("SELECT * FROM (SELECT TMP_PAGE.*,ROWNUMBER() OVER() AS ROW_ID FROM ( "); sqlBuilder.append(sql); sqlBuilder.append(" ) AS TMP_PAGE) TMP_PAGE WHERE ROW_ID BETWEEN "); sqlBuilder.append(startRow); sqlBuilder.append(" AND "); sqlBuilder.append(endRow); pageKey.update(startRow); pageKey.update(endRow); return sqlBuilder.toString(); }
Example 7
Source File: PartialListResultHandler.java From sinavi-jfw with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @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); }
Example 8
Source File: PageInterceptor.java From Zebra with Apache License 2.0 | 5 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { Object[] args = invocation.getArgs(); Object rowBound = args[2]; MappedStatement ms = (MappedStatement) args[0]; if (rowBound != null) { RowBounds rb = (RowBounds) rowBound; // without pagination if (rb.getOffset() == RowBounds.NO_ROW_OFFSET && rb.getLimit() == RowBounds.NO_ROW_LIMIT) { return invocation.proceed(); } else { BoundSql boundSql = ms.getBoundSql(args[1]); if (rowBound instanceof PageModel) { // physical pagination with PageModel PageModel pageModel = (PageModel) rowBound; Object count = queryCount(invocation, args, ms, boundSql); Object records = queryLimit(invocation, args, ms, boundSql, pageModel); pageModel.setRecordCount((Integer) ((List<?>) count).get(0)); pageModel.setRecords((List<?>) records); return null; } else { // physical pagination with RowBounds return queryLimit(invocation, args, ms, boundSql, rb); } } } else { // without pagination return invocation.proceed(); } }
Example 9
Source File: PageBounds.java From AsuraFramework with Apache License 2.0 | 5 votes |
public PageBounds(RowBounds rowBounds) { if(rowBounds instanceof PageBounds){ PageBounds pageBounds = (PageBounds)rowBounds; this.page = pageBounds.page; this.limit = pageBounds.limit; this.orders = pageBounds.orders; this.containsTotalCount = pageBounds.containsTotalCount; this.asyncTotalCount = pageBounds.asyncTotalCount; }else{ this.page = (rowBounds.getOffset()/rowBounds.getLimit())+1; this.limit = rowBounds.getLimit(); } }
Example 10
Source File: PagePluging.java From aaden-pay with Apache License 2.0 | 5 votes |
void processIntercept(final Object[] queryArgs) { MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX]; Object parameter = queryArgs[PARAMETER_INDEX]; final RowBounds rowBounds = (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)) { BoundSql boundSql = ms.getBoundSql(parameter); String sql = boundSql.getSql().trim(); 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 = new BoundSql(ms.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject()); for (ParameterMapping mapping : boundSql.getParameterMappings()) { String prop = mapping.getProperty(); if (boundSql.hasAdditionalParameter(prop)) { newBoundSql.setAdditionalParameter(prop, boundSql.getAdditionalParameter(prop)); } } MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql)); queryArgs[MAPPED_STATEMENT_INDEX] = newMs; } }
Example 11
Source File: MapperInstrument.java From mybatis-boost with MIT License | 5 votes |
private static void addRowBoundsParameter(CtMethod ctMethod, RowBounds rowBounds) { if (rowBounds == RowBounds.DEFAULT) return; try { String newMethodName = ctMethod.getName() + "$" + UUID.randomUUID().toString().replace("-", ""); CtMethod ctNewMethod = CtNewMethod.copy(ctMethod, newMethodName, ctMethod.getDeclaringClass(), null); ctNewMethod.addParameter(ClassPool.getDefault().get("org.apache.ibatis.session.RowBounds")); ctNewMethod.getMethodInfo().addAttribute (ctMethod.getMethodInfo().removeAttribute(AnnotationsAttribute.visibleTag)); String body; if (rowBounds.getLimit() == 1) { MethodInfo methodInfo = ctNewMethod.getMethodInfo(); String descriptor = methodInfo.getDescriptor(); String returnType = descriptor.substring(descriptor.lastIndexOf(')') + 1); methodInfo.setDescriptor(descriptor = descriptor.substring(0, descriptor.length() - returnType.length()) + "Ljava/util/List;"); ctNewMethod.setGenericSignature (descriptor.substring(0, descriptor.length() - 1) + "<" + returnType + ">;"); body = "{ java.util.List list = %s($$, new org.apache.ibatis.session.RowBounds(%s, %s));" + "return !list.isEmpty() ? (%s) list.get(0) : null; }"; body = String.format(body, newMethodName, rowBounds.getOffset(), rowBounds.getLimit(), returnType.substring(1, returnType.length() - 1).replace('/', '.')); } else { String signature = ctMethod.getGenericSignature(); int index = signature.lastIndexOf(')'); ctNewMethod.setGenericSignature(signature.substring(0, index) + "Lorg/apache/ibatis/session/RowBounds;" + signature.substring(index)); body = String.format("{ return %s($$, new org.apache.ibatis.session.RowBounds(%s, %s)); }", newMethodName, rowBounds.getOffset(), rowBounds.getLimit()); } ctMethod.getDeclaringClass().addMethod(ctNewMethod); ctMethod.setBody(body); } catch (CannotCompileException | NotFoundException e) { throw new RuntimeException(e); } }
Example 12
Source File: MybatisUtils.java From sqlhelper with GNU Lesser General Public License v3.0 | 4 votes |
public static boolean isPagingRowBounds(RowBounds rowBounds) { if (rowBounds == null || rowBounds == RowBounds.DEFAULT) { return false; } return rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT; }
Example 13
Source File: DefaultResultSetHandler.java From mybaties with Apache License 2.0 | 4 votes |
private boolean shouldProcessMoreRows(ResultContext context, RowBounds rowBounds) throws SQLException { return !context.isStopped() && context.getResultCount() < rowBounds.getLimit(); }
Example 14
Source File: DefaultResultSetHandler.java From mybatis with Apache License 2.0 | 4 votes |
private boolean shouldProcessMoreRows(ResultContext context, RowBounds rowBounds) throws SQLException { return !context.isStopped() && context.getResultCount() < rowBounds.getLimit(); }
Example 15
Source File: SqlUtils.java From mybatis-boost with MIT License | 4 votes |
public static String appendLimitOffset(String sql, RowBounds rowBounds) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT) { sql += " LIMIT " + rowBounds.getLimit() + " OFFSET " + rowBounds.getOffset(); } return sql; }
Example 16
Source File: SqlUtils.java From mybatis-boost with MIT License | 4 votes |
public static String appendLimit(String sql, RowBounds rowBounds) { if (rowBounds.getOffset() != RowBounds.NO_ROW_OFFSET || rowBounds.getLimit() != RowBounds.NO_ROW_LIMIT) { sql += " LIMIT " + rowBounds.getOffset() + ", " + rowBounds.getLimit(); } return sql; }
Example 17
Source File: MysqlDialect.java From Aooms with Apache License 2.0 | 4 votes |
@Override public String pagingQuery(String originalSql, RowBounds rowBounds) { int start = (rowBounds.getOffset() - 1) * rowBounds.getLimit(); String countsql = "select * from (" + originalSql + ") _table limit " + start + "," + rowBounds.getLimit(); return countsql; }