List of usage examples for org.apache.ibatis.session RowBounds RowBounds
public RowBounds(int offset, int limit)
From source file:com.sinotopia.mybatis.pagehelper.test.pagesize.PageSizeLessThenOrEqualZeroTest.java
License:Open Source License
/** * Mapper?PageHelper.startPage??Mapper?? *//* w ww. j a v a2s .c o m*/ @Test public void testWithRowbounds() { //?MybatisRowBoundsHelpercount SqlSession sqlSession = MybatisHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); try { //limit=0,?count,????rounbounds?count?-1 List<Country> list = countryMapper.selectAll(new RowBounds(1, -1)); PageInfo<Country> page = new PageInfo<Country>(list); assertEquals(0, list.size()); assertEquals(183, page.getTotal()); //limit<0? list = countryMapper.selectAll(new RowBounds(1, -100)); page = new PageInfo<Country>(list); assertEquals(0, list.size()); assertEquals(183, page.getTotal()); } finally { sqlSession.close(); } }
From source file:com.sinotopia.mybatis.pagehelper.test.rowbounds.RowBoundsTest.java
License:Open Source License
/** * Mapper?PageHelper.startPage??Mapper?? *//*from w ww . j a va 2s . com*/ @Test public void testWithRowboundsAndCountTrue() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); try { //limit=0,?count,????rounbounds?count?-1 //?-1 List<Country> list = countryMapper.selectAll(new RowBounds(1, -1)); PageInfo<Country> page = new PageInfo<Country>(list); assertEquals(0, list.size()); assertEquals(183, page.getTotal()); //pageSize<0? list = countryMapper.selectAll(new RowBounds(1, -100)); page = new PageInfo<Country>(list); assertEquals(0, list.size()); assertEquals(183, page.getTotal()); } finally { sqlSession.close(); } }
From source file:com.springD.framework.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 ww . ja v a 2s. com*/ Page<Object> page = null; if (parameterObject != null) { page = convertParameter(parameterObject, page); } // if (page != null && page.getPageSize() != -1) { if (org.apache.commons.lang3.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.tiamaes.mybatis.test.basic.PageHelperTest.java
License:Open Source License
/** * Mapper??RowBounds???xml??//from w w w .ja v a 2s.c o m * <p/> * RowBounds??count?Page? * <p/> * ??startPagestartPage */ @Test public void testMapperWithRowBounds() { SqlSession sqlSession = MybatisHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); try { //?110?count List<Country> list = countryMapper.selectAll(new RowBounds(0, 10)); assertEquals(10, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?210??count list = countryMapper.selectAll(new RowBounds(10, 10)); assertEquals(10, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(11, list.get(0).getId()); assertEquals(20, list.get(list.size() - 1).getId()); //?320?count list = countryMapper.selectAll(new RowBounds(60, 20)); assertEquals(20, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(61, list.get(0).getId()); assertEquals(80, list.get(list.size() - 1).getId()); //?startPageRowBoundsstartPage PageHelper.startPage(1, 20); list = countryMapper.selectAll(new RowBounds(60, 20)); assertEquals(20, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(20, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.tiamaes.mybatis.test.basic.PageHelperTest.java
License:Open Source License
/** * ???RowBoundsRowBounds?count//from ww w. j av a2s . c o m * ??count?? * ?count?startPage * <p/> * ?startPagestartPage?startPage?? */ @Test public void testNamespaceWithRowBounds() { SqlSession sqlSession = MybatisHelper.getSqlSession(); try { //?010? List<Country> list = sqlSession.selectList("selectAll", null, new RowBounds(0, 10)); assertEquals(10, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?1010? list = sqlSession.selectList("selectAll", null, new RowBounds(10, 10)); assertEquals(10, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(11, list.get(0).getId()); assertEquals(20, list.get(list.size() - 1).getId()); //?2020? list = sqlSession.selectList("selectAll", null, new RowBounds(20, 20)); assertEquals(20, list.size()); assertEquals(-1, ((Pagination<?>) list).getTotal()); //?? assertEquals(21, list.get(0).getId()); assertEquals(40, list.get(list.size() - 1).getId()); //?startPageRowBoundsstartPage PageHelper.startPage(1, 20); list = sqlSession.selectList("selectAll", null, new RowBounds(0, 10)); assertEquals(20, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(20, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.tiamaes.mybatis.test.rowbounds.RowBoundsTest.java
License:Open Source License
/** * Mapper??RowBounds???xml??/*from w ww . jav a 2 s . c o m*/ * <p/> * RowBounds??count?Page? * <p/> * ??startPagestartPage */ @Test public void testMapperWithRowBounds() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class); try { //?110?count List<Country> list = countryMapper.selectAll(new RowBounds(1, 10)); //PageInfo? PageInfo<Country> page = new PageInfo<Country>(list); assertEquals(10, list.size()); assertEquals(183, page.getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?1010??count list = countryMapper.selectAll(new RowBounds(10, 10)); assertEquals(10, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(91, list.get(0).getId()); assertEquals(100, list.get(list.size() - 1).getId()); //?320?count list = countryMapper.selectAll(new RowBounds(6, 20)); assertEquals(20, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(101, list.get(0).getId()); assertEquals(120, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.tiamaes.mybatis.test.rowbounds.RowBoundsTest.java
License:Open Source License
/** * ???RowBoundsRowBounds?count//ww w.j a va 2s . c o m * ??count?? * ?count?startPage * <p/> * ?startPagestartPage?startPage?? */ @Test public void testNamespaceWithRowBounds() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); try { //?010? List<Country> list = sqlSession.selectList("selectAll", null, new RowBounds(1, 10)); assertEquals(10, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); //?1010? list = sqlSession.selectList("selectAll", null, new RowBounds(10, 10)); assertEquals(10, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(91, list.get(0).getId()); assertEquals(100, list.get(list.size() - 1).getId()); //?2020? list = sqlSession.selectList("selectAll", null, new RowBounds(6, 20)); assertEquals(20, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(101, list.get(0).getId()); assertEquals(120, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.tiamaes.mybatis.test.rowbounds.RowBoundsTest.java
License:Open Source License
@Test public void testNamespaceWithRowBounds2() { SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession(); try {/*from w w w . j a va 2 s . c om*/ //?010? List<Country> list = sqlSession.selectList("selectIf", null, new RowBounds(1, 10)); assertEquals(10, list.size()); assertEquals(183, ((Pagination<?>) list).getTotal()); //?? assertEquals(1, list.get(0).getId()); assertEquals(10, list.get(list.size() - 1).getId()); Map<String, Object> map = new HashMap<String, Object>(); map.put("id", 10); //?1010? list = sqlSession.selectList("selectIf", map, new RowBounds(10, 10)); assertEquals(10, list.size()); assertEquals(173, ((Pagination<?>) list).getTotal()); //?? assertEquals(101, list.get(0).getId()); assertEquals(110, list.get(list.size() - 1).getId()); } finally { sqlSession.close(); } }
From source file:com.tianjunwei.dynamic.SimpleTableAnnotatedMapperTest.java
License:Apache License
@Test public void testSelectByExampleWithRowbounds() { try (SqlSession session = sqlSessionFactory.openSession()) { SimpleTableAnnotatedMapper mapper = session.getMapper(SimpleTableAnnotatedMapper.class); RowBounds rowBounds = new RowBounds(2, 2); List<SimpleTableRecord> rows = mapper.selectByExample(rowBounds).where(id, isEqualTo(1)) .or(occupation, isNull()).build().execute(); assertThat(rows.size()).isEqualTo(1); }/*from w w w.ja v a 2 s . com*/ }
From source file:com.tianjunwei.dynamic.SimpleTableAnnotatedMapperTest.java
License:Apache License
@Test public void testSelectDistinctByExampleWithRowbounds() { try (SqlSession session = sqlSessionFactory.openSession()) { SimpleTableAnnotatedMapper mapper = session.getMapper(SimpleTableAnnotatedMapper.class); RowBounds rowBounds = new RowBounds(2, 2); List<SimpleTableRecord> rows = mapper.selectDistinctByExample(rowBounds).where(id, isGreaterThan(1)) .or(occupation, isNull()).build().execute(); assertThat(rows.size()).isEqualTo(2); }/*from w ww . j a v a2 s . c o m*/ }