Example usage for org.apache.ibatis.session RowBounds getLimit

List of usage examples for org.apache.ibatis.session RowBounds getLimit

Introduction

In this page you can find the example usage for org.apache.ibatis.session RowBounds getLimit.

Prototype

public int getLimit() 

Source Link

Usage

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.Db2RowBoundsDialect.java

License:Open Source License

@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);/*from w  ww . ja  v  a2  s  .  co  m*/
    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();
}

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.HsqldbRowBoundsDialect.java

License:Open Source License

@Override
public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) {

    StringBuilder sqlBuilder = new StringBuilder(sql.length() + 20);
    sqlBuilder.append(sql);//from w ww .j a  va  2s .  co  m
    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();
}

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.InformixRowBoundsDialect.java

License:Open Source License

@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());
    }//from   ww  w.j a va2s.  co  m
    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();
}

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.MySqlRowBoundsDialect.java

License:Open Source License

@Override
public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) {

    StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
    sqlBuilder.append(sql);//from  w  w  w .ja va2 s. c  o m
    if (rowBounds.getOffset() == 0) {
        sqlBuilder.append(" LIMIT ");
        sqlBuilder.append(rowBounds.getLimit());
    } else {
        sqlBuilder.append(" LIMIT ");
        sqlBuilder.append(rowBounds.getOffset());
        sqlBuilder.append(",");
        sqlBuilder.append(rowBounds.getLimit());
        pageKey.update(rowBounds.getOffset());
    }
    pageKey.update(rowBounds.getLimit());
    return sqlBuilder.toString();
}

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.OracleRowBoundsDialect.java

License:Open Source License

@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 ( ");
    }/*from   w  ww  . j  a  v a2s  .com*/
    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();
}

From source file:com.sinotopia.mybatis.pagehelper.dialect.rowbounds.SqlServer2012RowBoundsDialect.java

License:Open Source License

@Override
public String getPageSql(String sql, RowBounds rowBounds, CacheKey pageKey) {

    StringBuilder sqlBuilder = new StringBuilder(sql.length() + 14);
    sqlBuilder.append(sql);//  w ww .ja v  a  2s.co m
    sqlBuilder.append(" OFFSET ");
    sqlBuilder.append(rowBounds.getOffset());
    sqlBuilder.append(" ROWS ");
    pageKey.update(rowBounds.getOffset());
    sqlBuilder.append(" FETCH NEXT ");
    sqlBuilder.append(rowBounds.getLimit());
    sqlBuilder.append(" ROWS ONLY");
    pageKey.update(rowBounds.getLimit());
    return sqlBuilder.toString();
}

From source file:com.sinotopia.mybatis.pagehelper.page.PageParams.java

License:Open Source License

/**
 * ??//w  w  w.  j  a v  a  2s .c  om
 *
 * @param parameterObject
 * @param rowBounds
 * @return
 */
public Page getPage(Object parameterObject, RowBounds rowBounds) {
    Page page = PageHelper.getLocalPage();
    if (page == null) {
        if (rowBounds != RowBounds.DEFAULT) {
            if (offsetAsPageNum) {
                page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
            } else {
                page = new Page(new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount);
                //offsetAsPageNum=falsePageNum?reasonablefalse
                page.setReasonable(false);
            }
        } else if (supportMethodsArguments) {
            try {
                page = PageObjectUtil.getPageFromObject(parameterObject, false);
            } catch (Exception e) {
                return null;
            }
        }
        if (page == null) {
            return null;
        }
        PageHelper.setLocalPage(page);
    }
    //??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    //truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}

From source file:com.swifts.frame.common.pagehelper.SqlUtil.java

License:Open Source License

/**
 * ??//  ww  w.  java 2s .  co m
 *
 * @param args
 * @return Page
 */
public com.swifts.frame.common.pagehelper.Page getPage(Object[] args) {
    com.swifts.frame.common.pagehelper.Page page = getLocalPage();
    if (page == null || page.isOrderByOnly()) {
        com.swifts.frame.common.pagehelper.Page oldPage = page;
        //?,page.isOrderByOnly()true??
        if ((args[2] == null || args[2] == RowBounds.DEFAULT) && page != null) {
            return oldPage;
        }
        if (args[2] instanceof RowBounds && args[2] != RowBounds.DEFAULT) {
            RowBounds rowBounds = (RowBounds) args[2];
            if (offsetAsPageNum) {
                page = new com.swifts.frame.common.pagehelper.Page(rowBounds.getOffset(), rowBounds.getLimit(),
                        rowBoundsWithCount);
            } else {
                page = new com.swifts.frame.common.pagehelper.Page(
                        new int[] { rowBounds.getOffset(), rowBounds.getLimit() }, rowBoundsWithCount);
                //offsetAsPageNum=falsePageNum?reasonablefalse
                page.setReasonable(false);
            }
        } else {
            try {
                page = getPageFromObject(args[1]);
            } catch (Exception e) {
                return null;
            }
        }
        if (oldPage != null) {
            page.setOrderBy(oldPage.getOrderBy());
        }
        setLocalPage(page);
    }
    //??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    //truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}

From source file:com.tiamaes.mybatis.SqlUtil.java

License:Open Source License

/**
 * ??//from   w  w  w .j  ava2s .com
 *
 * @param args
 * @return Page
 */
public Pagination getPage(Object[] args) {
    Pagination page = getLocalPage();
    if (page == null || page.isOrderByOnly()) {
        Pagination oldPage = page;
        //?,page.isOrderByOnly()true??
        if ((args[2] == null || args[2] == RowBounds.DEFAULT) && page != null) {
            return oldPage;
        }
        if (args[2] instanceof RowBounds && args[2] != RowBounds.DEFAULT) {
            RowBounds rowBounds = (RowBounds) args[2];
            if (offsetAsPageNum) {
                page = new Pagination(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
            } else {
                page = new Pagination(new int[] { rowBounds.getOffset(), rowBounds.getLimit() },
                        rowBoundsWithCount);
                //offsetAsPageNum=falsePageNum?reasonablefalse
                page.setReasonable(false);
            }
        } else {
            try {
                page = getPageFromObject(args[1]);
            } catch (Exception e) {
                return null;
            }
        }
        if (oldPage != null) {
            page.setOrderBy(oldPage.getOrderBy());
        }
        setLocalPage(page);
    }
    //??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    //truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}

From source file:com.wsun.seap.dao.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {
    // ??//from   w  ww . jav a 2 s. c om
    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[MAPPED_STATEMENT_INDEX];
    // ?SQL
    // ??
    Object parameterObj = invocation.getArgs()[PARAMETER_INDEX];
    // ??QueryParam
    Object parameter;
    if (parameterObj instanceof QueryParam) {
        // ?QueryParam,??Map
        parameter = ((QueryParam) parameterObj).getAllParam();
        invocation.getArgs()[PARAMETER_INDEX] = parameter;
    } else {
        parameter = parameterObj;
    }

    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    if (StringUtils.isBlank(boundSql.getSql())) {
        return null;
    }
    // ??RowBounds
    RowBounds rowBounds = (RowBounds) invocation.getArgs()[ROWBOUNDS_INDEX];
    // 
    if (rowBounds != null && rowBounds != RowBounds.DEFAULT) {
        String originalSql = boundSql.getSql().trim();
        // ??sql
        String pageSql = dialect.getLimitString(originalSql, rowBounds.getOffset(), rowBounds.getLimit());
        invocation.getArgs()[ROWBOUNDS_INDEX] = new RowBounds(RowBounds.NO_ROW_OFFSET, RowBounds.NO_ROW_LIMIT);
        BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), pageSql,
                boundSql.getParameterMappings(), boundSql.getParameterObject());
        MappedStatement newMs = copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql));
        invocation.getArgs()[MAPPED_STATEMENT_INDEX] = newMs;
    }
    return invocation.proceed();
}