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));
}
}
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;
}
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();
}
}
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();
}
}
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();
}
}
Aggregations