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

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

Introduction

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

Prototype

public RowBounds(int offset, int limit) 

Source Link

Usage

From source file:com.joey.Fujikom.common.persistence.interceptor.PaginationInterceptor.java

License:Open Source License

@Override
public Object intercept(Invocation invocation) throws Throwable {

    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];

    //        //?SQL
    ////        if (mappedStatement.getId().matches(_SQL_PATTERN)) {
    //        if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) {
    Object parameter = invocation.getArgs()[1];
    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    Object parameterObject = boundSql.getParameterObject();

    //??//from w w  w  . j a va 2s .  co m
    Page<Object> page = null;
    if (parameterObject != null) {
        page = convertParameter(parameterObject, page);
    }

    //
    if (page != null && page.getPageSize() != -1) {

        if (StringUtils.isBlank(boundSql.getSql())) {
            return null;
        }
        String originalSql = boundSql.getSql().trim();

        //
        page.setCount(SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log));

        //  ??
        String pageSql = SQLHelper.generatePageSql(originalSql, page, DIALECT);
        //                if (log.isDebugEnabled()) {
        //                    log.debug("PAGE SQL:" + StringUtils.replace(pageSql, "\n", ""));
        //                }
        invocation.getArgs()[2] = 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()[0] = newMs;
    }
    //        }
    return invocation.proceed();
}

From source file:com.kazuki43zoo.apistub.domain.service.ApiResponseService.java

License:Apache License

public Page<ApiResponse> findPage(String path, String method, String description, Pageable pageable) {
    String searchingPath = Optional.ofNullable(path).map(e -> PATH_VARIABLE_PATTERN.matcher(e).replaceAll(".+"))
            .orElse(null);/*from ww w.  ja v a2  s  . co m*/
    long count = repository.count(searchingPath, method, description);
    List<ApiResponse> content;
    if (count != 0) {
        content = repository.findPage(searchingPath, method, description,
                new RowBounds(Long.valueOf(pageable.getOffset()).intValue(),
                        Long.valueOf(pageable.getPageSize()).intValue()));
    } else {
        content = Collections.emptyList();
    }
    return new PageImpl<>(content, pageable, count);
}

From source file:com.kazuki43zoo.apistub.domain.service.ApiResponseService.java

License:Apache License

public Page<ApiResponse> findAllHistoryById(int id, Pageable pageable) {
    long count = repository.countHistoryById(id);
    List<ApiResponse> content;
    if (count != 0) {
        content = repository.findPageHistoryById(id,
                new RowBounds(Long.valueOf(pageable.getOffset()).intValue(),
                        Long.valueOf(pageable.getPageSize()).intValue()));
    } else {//from   w ww . j av a  2 s  .  co m
        content = Collections.emptyList();
    }
    return new PageImpl<>(content, pageable, count);
}

From source file:com.kazuki43zoo.apistub.domain.service.ApiService.java

License:Apache License

public Page<Api> findAll(String path, String method, String description, Pageable pageable) {
    long count = repository.count(path, method, description);
    List<Api> content;//w  w  w.j a  v  a 2  s.c o  m
    if (count != 0) {
        content = repository.findPage(path, method, description,
                new RowBounds(Long.valueOf(pageable.getOffset()).intValue(),
                        Long.valueOf(pageable.getPageSize()).intValue()));
    } else {
        content = Collections.emptyList();
    }
    return new PageImpl<>(content, pageable, count);
}

From source file:com.lushapp.common.orm.mybatis.interceptor.PaginationInterceptor.java

License:Open Source License

public Object intercept(Invocation invocation) throws Throwable {

    final MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];

    //        //?SQL
    ////        if (mappedStatement.getId().matches(_SQL_PATTERN)) {
    //        if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) {
    Object parameter = invocation.getArgs()[1];
    BoundSql boundSql = mappedStatement.getBoundSql(parameter);
    Object parameterObject = boundSql.getParameterObject();

    //??// w  w  w  .  j ava 2s.c  om
    Page<Object> page = null;
    if (parameterObject != null) {
        page = convertParameter(parameterObject, page);
    }

    //
    if (page != null && page.getPageSize() != -1) {

        if (StringUtils.isBlank(boundSql.getSql())) {
            return null;
        }
        String originalSql = boundSql.getSql().trim();

        //
        page.setTotalCount(
                SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log));

        //  ??
        String pageSql = SQLHelper.generatePageSql(originalSql, page, DIALECT);
        //                if (log.isDebugEnabled()) {
        //                    log.debug("PAGE SQL:" + StringUtils.replace(pageSql, "\n", ""));
        //                }
        invocation.getArgs()[2] = 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()[0] = newMs;
    }
    //        }
    return invocation.proceed();
}

From source file:com.lvzu.common.dao.mybatis.MyBatisDaoSupport.java

License:Open Source License

public List<M> selectLimitedList(String selectId, int limit, Object parameter) {
    RowBounds rowBounds = new RowBounds(0, limit);
    return getSqlSession().selectList(NAMESPACE.concat(selectId), parameter);
}

From source file:com.lvzu.common.dao.mybatis.MyBatisDaoSupport.java

License:Open Source License

public Page<M> fetchPage(String selectId, Page<M> page, Map<String, Object> model) {
    ///* w ww.  j a v  a 2 s.  co  m*/
    if (page.isAutoCount()) {
        String countId = selectId.concat("Count");
        long totalCount = selectPageCount(countId, model);
        page.setTotalCount(totalCount);
    }
    //
    RowBounds rowBounds = new RowBounds(page.getFirst() - 1, page.getPageSize());
    List<M> results = getSqlSession().selectList(NAMESPACE.concat(selectId), model, rowBounds);
    //
    return page.setResults(results);
}

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;//from   w  w w  .j  av a 2  s. c  o  m

    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.mycollab.db.persistence.service.DefaultSearchService.java

License:Open Source License

@Override
public List findPageableListByCriteria(BasicSearchRequest<S> searchRequest) {
    return getSearchMapper().findPageableListByCriteria(searchRequest.getSearchCriteria(),
            new RowBounds((searchRequest.getCurrentPage() - 1) * searchRequest.getNumberOfItems(),
                    searchRequest.getNumberOfItems()));
}

From source file:com.mycollab.db.persistence.service.DefaultSearchService.java

License:Open Source License

@Override
public List findAbsoluteListByCriteria(S searchCriteria, Integer firstIndex, Integer numberOftems) {
    return getSearchMapper().findPageableListByCriteria(searchCriteria,
            new RowBounds(firstIndex, numberOftems));
}