Search in sources :

Example 6 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class MapperMethod method executeWithResultHandler.

private void executeWithResultHandler(SqlSession sqlSession, Object[] args) {
    MappedStatement ms = sqlSession.getConfiguration().getMappedStatement(command.getName());
    if (void.class.equals(ms.getResultMaps().get(0).getType())) {
        throw new BindingException("method " + command.getName() + " needs either a @ResultMap annotation, a @ResultType annotation," + " or a resultType attribute in XML so a ResultHandler can be used as a parameter.");
    }
    Object param = method.convertArgsToSqlCommandParam(args);
    if (method.hasRowBounds()) {
        RowBounds rowBounds = method.extractRowBounds(args);
        sqlSession.select(command.getName(), param, rowBounds, method.extractResultHandler(args));
    } else {
        sqlSession.select(command.getName(), param, method.extractResultHandler(args));
    }
}
Also used : RowBounds(org.apache.ibatis.session.RowBounds) MetaObject(org.apache.ibatis.reflection.MetaObject) MappedStatement(org.apache.ibatis.mapping.MappedStatement)

Example 7 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class MapperMethod method executeForMap.

private <K, V> Map<K, V> executeForMap(SqlSession sqlSession, Object[] args) {
    Map<K, V> result;
    Object param = method.convertArgsToSqlCommandParam(args);
    if (method.hasRowBounds()) {
        RowBounds rowBounds = method.extractRowBounds(args);
        result = sqlSession.<K, V>selectMap(command.getName(), param, method.getMapKey(), rowBounds);
    } else {
        result = sqlSession.<K, V>selectMap(command.getName(), param, method.getMapKey());
    }
    return result;
}
Also used : RowBounds(org.apache.ibatis.session.RowBounds) MetaObject(org.apache.ibatis.reflection.MetaObject)

Example 8 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class BindingTest method executeWithMapKeyAndRowBounds.

@Test
public void executeWithMapKeyAndRowBounds() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
        Map<Integer, Blog> blogs = mapper.selectRangeBlogsAsMapById(new RowBounds(1, 1));
        assertEquals(1, blogs.size());
        Blog blog = blogs.get(2);
        assertEquals(2, blog.getId());
    } finally {
        session.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) RowBounds(org.apache.ibatis.session.RowBounds) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 9 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class BindingTest method shouldfindThreeSpecificPosts.

@Test
public void shouldfindThreeSpecificPosts() throws Exception {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
        List<Post> posts = mapper.findThreeSpecificPosts(1, new RowBounds(1, 1), 3, 5);
        assertEquals(1, posts.size());
        assertEquals(3, posts.get(0).getId());
        session.rollback();
    } finally {
        session.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) DraftPost(org.apache.ibatis.domain.blog.DraftPost) Post(org.apache.ibatis.domain.blog.Post) RowBounds(org.apache.ibatis.session.RowBounds) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 10 with RowBounds

use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.

the class BindingTest method executeWithCursorAndRowBounds.

@Test
public void executeWithCursorAndRowBounds() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
        BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
        Cursor<Blog> blogs = mapper.openRangeBlogs(new RowBounds(1, 1));
        Iterator<Blog> blogIterator = blogs.iterator();
        Blog blog = blogIterator.next();
        assertEquals(2, blog.getId());
        assertFalse(blogIterator.hasNext());
    } finally {
        session.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) RowBounds(org.apache.ibatis.session.RowBounds) Blog(org.apache.ibatis.domain.blog.Blog) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Aggregations

RowBounds (org.apache.ibatis.session.RowBounds)45 Test (org.junit.Test)35 SqlSession (org.apache.ibatis.session.SqlSession)31 Country (com.github.pagehelper.model.Country)14 CountryMapper (com.github.pagehelper.mapper.CountryMapper)7 BaseDataTest (org.apache.ibatis.BaseDataTest)7 MappedStatement (org.apache.ibatis.mapping.MappedStatement)7 HashMap (java.util.HashMap)6 PageInfo (com.github.pagehelper.PageInfo)4 Executor (org.apache.ibatis.executor.Executor)4 BoundSql (org.apache.ibatis.mapping.BoundSql)4 MetaObject (org.apache.ibatis.reflection.MetaObject)4 ResultHandler (org.apache.ibatis.session.ResultHandler)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 CacheKey (org.apache.ibatis.cache.CacheKey)3 Blog (org.apache.ibatis.domain.blog.Blog)3 DraftPost (org.apache.ibatis.domain.blog.DraftPost)3 Post (org.apache.ibatis.domain.blog.Post)3