List of usage examples for org.apache.ibatis.session RowBounds RowBounds
public RowBounds(int offset, int limit)
From source file:com.fitibo.aotearoa.controller.HomeController.java
License:Apache License
@RequestMapping("skus") @Authentication/* ww w . ja v a 2s . com*/ public String querySku(@RequestParam(value = "keyword", defaultValue = "") String keyword, @RequestParam(value = "cityid", defaultValue = "0") int cityId, @RequestParam(value = "categoryid", defaultValue = "0") int categoryId, @RequestParam(value = "pagesize", defaultValue = "10") int pageSize, @RequestParam(value = "pagenumber", defaultValue = "0") int pageNumber, Map<String, Object> model) { Map<Integer, City> cityMap = cityService.findAll(); Map<Integer, Category> categoryMap = categoryService.findAll(); Map<Integer, Vendor> vendorMap = vendorService.findAll(); Map<Integer, Duration> durationMap = durationService.findAll(); RowBounds rowBounds = new RowBounds(pageNumber * pageSize, pageSize); model.put("module", MODULE_QUERY_SKU); model.put("cityId", cityId); model.put("categoryId", categoryId); model.put("keyword", keyword); model.put("cities", Lists.newArrayList(cityMap.values())); model.put("categories", Lists.newArrayList(categoryMap.values())); model.put("durations", Lists.newArrayList(durationMap.values())); model.put("skus", Lists.transform(searchSku(keyword, cityId, categoryId, rowBounds), (input) -> parse(input, cityMap, categoryMap, vendorMap, durationMap))); model.put("pageSize", pageSize); model.put("pageNumber", pageNumber); return "skus"; }
From source file:com.funtl.framework.smoke.core.commons.persistence.interceptor.PaginationInterceptor.java
License:Apache 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(); //??//ww w . j a v a 2 s. 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()); //MyBatis foreach ? start if (Reflections.getFieldValue(boundSql, "metaParameters") != null) { MetaObject mo = (MetaObject) Reflections.getFieldValue(boundSql, "metaParameters"); Reflections.setFieldValue(newBoundSql, "metaParameters", mo); } //MyBatis foreach ? end MappedStatement newMs = copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql)); invocation.getArgs()[0] = newMs; } // } return invocation.proceed(); }
From source file:com.funtl.framework.smoke.core.commons.persistence.proxy.PaginationMapperMethod.java
License:Apache License
/** * ?// w w w. j a v a2 s . c o m * * @param args ?? * @return */ @SuppressWarnings("unchecked") public Object execute(Object[] args) { final Object param = getParam(args); Page<Object> page; RowBounds rowBounds; if (paginationIndex != null) { page = (Page<Object>) args[paginationIndex]; rowBounds = new RowBounds(page.getFirstResult(), page.getMaxResults()); } else if (rowBoundsIndex != null) { rowBounds = (RowBounds) args[rowBoundsIndex]; page = new Page<Object>(); } else { throw new BindingException( "Invalid bound statement (not found rowBounds or pagination in paramenters)"); } page.setCount(executeForCount(param)); page.setList(executeForList(param, rowBounds)); return page; }
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.BaseDao.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) public PageList<T> getList(String key, Object params, Pager page) { PageList pages = new PageList(page); try {/* w ww . j a v a 2s . c o m*/ Integer totalCounts = count(key + COUNT, params); // add int pageM = maxPage(totalCounts, page.getPageSize(), page.getPageNumber()); if (pageM > 0) { pages.getPager().setPageNumber(pageM); } // end if (totalCounts != null && totalCounts.longValue() > 0) { List<T> list = getSqlSession().selectList(key, params, new RowBounds(page.getOffset(), page.getPageSize())); pages.addAll(list); pages.getPager().setTotalCount(totalCounts.longValue()); } return pages; } catch (Exception e) { logger.error(getClass().getName() + " getList exception and key is" + key, e); return null; } }
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) public Object intercept(Invocation invocation) throws Throwable { Object[] queryArgs = invocation.getArgs(); MappedStatement ms = (MappedStatement) queryArgs[MAPPED_STATEMENT_INDEX]; Object parameter = queryArgs[PARAMETER_INDEX]; final RowBounds oldRow = (RowBounds) queryArgs[ROWBOUNDS_INDEX]; // the need for paging intercept. boolean interceptor = ms.getId().matches(sqlRegex); if (!interceptor) { return invocation.proceed(); }//from w w w .j av a 2 s . c om final Executor executor = (Executor) invocation.getTarget(); //obtain paging information. final PagingCriteria pageRequest = interceptor ? PagingParametersFinder.instance.findCriteria(parameter) : PagingCriteria.getDefaultCriteria(); final RowBounds rowBounds = (interceptor) ? offsetPaging(oldRow, pageRequest) : oldRow; 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(); Integer count = getCount(fileterSql(sql, pageRequest), executor, ms, rowBounds, boundSql, parameter, dialect); String newSql = sortSql(fileterSql(sql, pageRequest), pageRequest); if (dialect.supportsLimitOffset()) { newSql = dialect.getLimitString(newSql, offset, limit); offset = RowBounds.NO_ROW_OFFSET; } else { newSql = dialect.getLimitString(newSql, 0, limit); } if (logger.isDebugEnabled()) { logger.debug("Pagination sql is :[" + newSql + "]"); } limit = RowBounds.NO_ROW_LIMIT; queryArgs[ROWBOUNDS_INDEX] = new RowBounds(offset, limit); BoundSql newBoundSql = copyFromBoundSql(ms, boundSql, newSql); MappedStatement newMs = copyFromMappedStatement(ms, new BoundSqlSqlSource(newBoundSql)); queryArgs[MAPPED_STATEMENT_INDEX] = newMs; return new PageList((List) invocation.proceed(), new Pager(pageRequest.getPageNumber(), pageRequest.getPageSize(), count)); } return invocation.proceed(); }
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.PaginationInterceptor.java
License:Apache License
/** * Set the paging information,to RowBuounds. * * @param rowBounds rowBounds./*from w ww.j av a2 s. c om*/ * @return rowBounds. */ private RowBounds offsetPaging(RowBounds rowBounds, PagingCriteria pageRequest) { // rowBuounds has offset. if (rowBounds.getOffset() == RowBounds.NO_ROW_OFFSET) { if (pageRequest != null) { return new RowBounds(dialect.getFirst(pageRequest.getPageNumber(), pageRequest.getPageSize()), pageRequest.getPageSize()); } } return rowBounds; }
From source file:com.github.maoo.indexer.dao.IndexingDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") public List<NodeEntity> getNodesByAclChangesetId(Pair<Long, StoreRef> store, Long lastAclChangesetId, int maxResults) { StoreRef storeRef = store.getSecond(); if (maxResults <= 0 || maxResults == Integer.MAX_VALUE) { throw new IllegalArgumentException("Maximum results must be a reasonable number."); }/*from ww w .j a v a 2s. com*/ logger.debug( "[getNodesByAclChangesetId] On Store " + storeRef.getProtocol() + "://" + storeRef.getIdentifier()); NodeBatchLoadEntity nodeLoadEntity = new NodeBatchLoadEntity(); nodeLoadEntity.setStoreId(store.getFirst()); nodeLoadEntity.setStoreProtocol(storeRef.getProtocol()); nodeLoadEntity.setStoreIdentifier(storeRef.getIdentifier()); nodeLoadEntity.setMinId(lastAclChangesetId); nodeLoadEntity.setMaxId(lastAclChangesetId + maxResults); nodeLoadEntity.setAllowedTypes(this.allowedTypes); nodeLoadEntity.setExcludedNameExtension(this.excludedNameExtension); // nodeLoadEntity.setProperties(this.properties); nodeLoadEntity.setAspects(this.aspects); nodeLoadEntity.setMimeTypes(this.mimeTypes); return filterNodes((List<NodeEntity>) (List<?>) template.selectList(SELECT_NODES_BY_ACLS, nodeLoadEntity, new RowBounds(0, Integer.MAX_VALUE))); }
From source file:com.github.maoo.indexer.dao.IndexingDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") public List<NodeEntity> getNodesByTransactionId(Pair<Long, StoreRef> store, Long lastTransactionId, int maxResults) { StoreRef storeRef = store.getSecond(); if (maxResults <= 0 || maxResults == Integer.MAX_VALUE) { throw new IllegalArgumentException("Maximum results must be a reasonable number."); }/*from www . jav a 2 s. com*/ logger.debug( "[getNodesByTransactionId] On Store " + storeRef.getProtocol() + "://" + storeRef.getIdentifier()); NodeBatchLoadEntity nodeLoadEntity = new NodeBatchLoadEntity(); nodeLoadEntity.setStoreId(store.getFirst()); nodeLoadEntity.setStoreProtocol(storeRef.getProtocol()); nodeLoadEntity.setStoreIdentifier(storeRef.getIdentifier()); nodeLoadEntity.setMinId(lastTransactionId); nodeLoadEntity.setMaxId(lastTransactionId + maxResults); nodeLoadEntity.setAllowedTypes(this.allowedTypes); nodeLoadEntity.setExcludedNameExtension(this.excludedNameExtension); // nodeLoadEntity.setProperties(this.properties); nodeLoadEntity.setAspects(this.aspects); nodeLoadEntity.setMimeTypes(this.mimeTypes); return filterNodes((List<NodeEntity>) (List<?>) template.selectList(SELECT_NODES_BY_TXNS, nodeLoadEntity, new RowBounds(0, Integer.MAX_VALUE))); }
From source file:com.github.pagehelper.rowbounds.test.RowBoundsTest.java
License:Open Source License
/** * Mapper??RowBounds???xml??/* w ww.j a v a 2 s . com*/ * <p/> * RowBounds??count?Page? * <p/> * ??startPagestartPage */ @Test public void testMapperWithRowBounds() { SqlSession sqlSession = RowBoundsHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); try { //?110?count List<Country> list = countryMapper.selectAll(new RowBounds(0, 10)); //PageInfo? assertEquals(10, list.size()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?1010??count list = countryMapper.selectAll(new RowBounds(90, 10)); assertEquals(10, list.size()); //?? assertEquals(91, list.get(0).getId()); assertEquals(100, list.get(list.size() - 1).getId()); //?320?count list = countryMapper.selectAll(new RowBounds(100, 20)); assertEquals(20, list.size()); //?? assertEquals(101, list.get(0).getId()); assertEquals(120, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.github.pagehelper.rowbounds.test.RowBoundsTest.java
License:Open Source License
/** * ???RowBoundsRowBounds?count/* w w w.j a v a 2 s.c o m*/ * ??count?? * ?count?startPage * <p/> * ?startPagestartPage?startPage?? */ @Test public void testNamespaceWithRowBounds() { SqlSession sqlSession = RowBoundsHelper.getSqlSession(); try { //?010? List<Country> list = sqlSession.selectList("selectAll", null, new RowBounds(0, 10)); assertEquals(10, list.size()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?1010? list = sqlSession.selectList("selectAll", null, new RowBounds(90, 10)); assertEquals(10, list.size()); //?? assertEquals(91, list.get(0).getId()); assertEquals(100, list.get(list.size() - 1).getId()); //?2020? list = sqlSession.selectList("selectAll", null, new RowBounds(100, 20)); assertEquals(20, list.size()); //?? assertEquals(101, list.get(0).getId()); assertEquals(120, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }