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.github.pagehelper.page.PageParams.java

License:Open Source License

/**
 * ??/* ww w. j a  v  a  2s .co  m*/
 *
 * @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 {
            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.glaf.core.entity.mybatis.MyBatisOffsetLimitInterceptor.java

License:Apache License

void processIntercept(final Object[] queryArgs) {
    // queryArgs = query(MappedStatement ms, Object parameter, RowBounds
    // rowBounds, ResultHandler resultHandler)
    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();

    String currentSystemName = Environment.getCurrentSystemName();
    Dialect dialect = null;//from  w  ww .  j  av a 2  s.c  om
    if (conf.getBoolean("useDatabaseDialect", true)) {
        if (dialects.isEmpty()) {
            Map<String, Dialect> rows = DBConfiguration.getDatabaseDialects();
            Iterator<Entry<String, Dialect>> iterator = rows.entrySet().iterator();
            while (iterator.hasNext()) {
                Entry<String, Dialect> entry = iterator.next();
                String key = (String) entry.getKey();
                Dialect d = entry.getValue();
                dialects.put(key, d);
            }
        }
        logger.debug("currentSystemName:" + currentSystemName);
        dialect = dialects.get(currentSystemName);
    }
    if (dialect != null && dialect.supportsLimit()
            && (offset != RowBounds.NO_ROW_OFFSET || limit != RowBounds.NO_ROW_LIMIT)) {
        logger.debug("dialect:" + dialect.getClass().getName());
        BoundSql boundSql = ms.getBoundSql(parameter);
        String sql = boundSql.getSql().trim();
        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;
        if (logger.isDebugEnabled()) {
            String sql2 = newBoundSql.getSql();
            SQLFormatter f = new SQLFormatter();
            sql2 = f.format(sql2);
            logger.debug("limit sql:\n" + sql2);
        }
    }
}

From source file:com.gochinatv.accelarator.framework.web.base.pagination.SqlUtil.java

License:Open Source License

/**
 * ??//w  ww.j a  v a 2 s.  c om
 *
 * @param args
 * @return Page
 */
public Page getPage(Object[] args) {
    Page page = getLocalPage();
    if (page == null || page.isOrderByOnly()) {
        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 Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
            } else {
                page = new 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.jdonee.framework.util.pagehelper.Page.java

License:Open Source License

public Page(RowBounds rowBounds, int total) {
    super(rowBounds.getLimit() > -1 ? rowBounds.getLimit() : 0);
    this.pageSize = rowBounds.getLimit();
    this.startRow = rowBounds.getOffset();
    // RowBounds??countcount,?SQL_COUNT
    this.total = total;
    this.endRow = this.startRow + this.pageSize;
}

From source file:com.jdonee.framework.util.pagehelper.PageHelper.java

License:Open Source License

/**
 * ??//  w  w w  .  j  a  va2s. c o m
 *
 * @param rowBounds RowBounds?
 * @return Page
 */
private Page getPage(RowBounds rowBounds) {
    Page page = LOCAL_PAGE.get();
    // ??
    LOCAL_PAGE.remove();

    if (page == null) {
        if (offsetAsPageNum) {
            page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
        } else {
            page = new Page(rowBounds, rowBoundsWithCount);
        }
    }
    return page;
}

From source file:com.linju.framework.pager.Page.java

License:Open Source License

public Page(RowBounds rowBounds, int total) {
    super(0);/*  w  ww  . ja  v  a  2  s  . c o m*/
    if (rowBounds.getOffset() == 0 && rowBounds.getLimit() == Integer.MAX_VALUE) {
        pageSizeZero = true;
        this.pageSize = 0;
    } else {
        this.pageSize = rowBounds.getLimit();
    }
    this.startRow = rowBounds.getOffset();
    //RowBounds??countcount,?SQL_COUNT
    this.total = total;
    this.endRow = this.startRow + rowBounds.getLimit();
}

From source file:com.linju.framework.pager.SqlUtil.java

License:Open Source License

/**
 * ??/*from  w w w . j  a  v  a  2  s .  com*/
 *
 * @param params RowBounds?
 * @return Page
 */
public Page getPage(Object params) {
    Page page = getLocalPage();
    if (page == null) {
        if (params instanceof RowBounds) {
            RowBounds rowBounds = (RowBounds) params;
            if (offsetAsPageNum) {
                page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
            } else {
                page = new Page(rowBounds, rowBoundsWithCount);
                //offsetAsPageNum=falsePageNum?reasonablefalse
                page.setReasonable(false);
            }
        } else {
            page = getPageFromObject(params);
        }
        setLocalPage(page);
    }
    //??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    //truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}

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 .j  a v  a  2  s .com*/

    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;

    }
}

From source file:com.pansoft.common.pageHelper.PageHelper.java

License:Open Source License

/**
 * ??//from ww w .  j av  a  2s .  c  o  m
 *
 * @param rowBounds
 *            RowBounds?
 * @return Page
 */
private Page getPage(RowBounds rowBounds) {
    Page page = LOCAL_PAGE.get();
    // ??
    LOCAL_PAGE.remove();
    if (page == null) {
        if (offsetAsPageNum) {
            page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
        } else {
            page = new Page(rowBounds, rowBoundsWithCount);
        }
    }
    // ??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    // truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}

From source file:com.sino.ssi.mybatis.plugin.SqlUtil.java

License:Open Source License

/**
 * ??/*  ww  w .  j a  v  a 2  s. c o  m*/
 *
 * @param params RowBounds?
 * @return Page
 */
public Page getPage(Object params) {
    Page page = getLocalPage();
    if (page == null) {
        if (params instanceof RowBounds) {
            RowBounds rowBounds = (RowBounds) params;
            if (offsetAsPageNum) {
                page = new Page(rowBounds.getOffset(), rowBounds.getLimit(), rowBoundsWithCount);
            } else {
                page = new Page(rowBounds, rowBoundsWithCount);
            }
        } else {
            page = getPageFromObject(params);
        }
        setLocalPage(page);
    }
    //??
    if (page.getReasonable() == null) {
        page.setReasonable(reasonable);
    }
    //truepagesize0RowBoundslimit=0?
    if (page.getPageSizeZero() == null) {
        page.setPageSizeZero(pageSizeZero);
    }
    return page;
}