|
26 | 26 | import java.util.ArrayList;
|
27 | 27 | import java.util.Collections;
|
28 | 28 | import java.util.HashMap;
|
| 29 | +import java.util.Iterator; |
29 | 30 | import java.util.List;
|
30 | 31 | import java.util.Map;
|
31 | 32 |
|
|
36 | 37 | import net.sf.cglib.proxy.Factory;
|
37 | 38 |
|
38 | 39 | import org.apache.ibatis.BaseDataTest;
|
| 40 | +import org.apache.ibatis.cursor.Cursor; |
39 | 41 | import org.apache.ibatis.domain.blog.Author;
|
40 | 42 | import org.apache.ibatis.domain.blog.Blog;
|
41 | 43 | import org.apache.ibatis.domain.blog.DraftPost;
|
@@ -734,5 +736,55 @@ public void shouldGetBlogsWithAuthorsAndPostsEagerly() {
|
734 | 736 | session.close();
|
735 | 737 | }
|
736 | 738 | }
|
737 |
| - |
| 739 | + |
| 740 | + @Test |
| 741 | + public void executeWithResultHandlerAndRowBounds() { |
| 742 | + SqlSession session = sqlSessionFactory.openSession(); |
| 743 | + try { |
| 744 | + BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class); |
| 745 | + final DefaultResultHandler handler = new DefaultResultHandler(); |
| 746 | + mapper.collectRangeBlogs(handler, new RowBounds(1, 1)); |
| 747 | + |
| 748 | + assertEquals(1, handler.getResultList().size()); |
| 749 | + Blog blog = (Blog) handler.getResultList().get(0); |
| 750 | + assertEquals(2, blog.getId()); |
| 751 | + |
| 752 | + } finally { |
| 753 | + session.close(); |
| 754 | + } |
| 755 | + } |
| 756 | + |
| 757 | + @Test |
| 758 | + public void executeWithMapKeyAndRowBounds() { |
| 759 | + SqlSession session = sqlSessionFactory.openSession(); |
| 760 | + try { |
| 761 | + BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class); |
| 762 | + Map<Integer, Blog> blogs = mapper.selectRangeBlogsAsMapById(new RowBounds(1, 1)); |
| 763 | + |
| 764 | + assertEquals(1, blogs.size()); |
| 765 | + Blog blog = blogs.get(2); |
| 766 | + assertEquals(2, blog.getId()); |
| 767 | + |
| 768 | + } finally { |
| 769 | + session.close(); |
| 770 | + } |
| 771 | + } |
| 772 | + |
| 773 | + @Test |
| 774 | + public void executeWithCursorAndRowBounds() { |
| 775 | + SqlSession session = sqlSessionFactory.openSession(); |
| 776 | + try { |
| 777 | + BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class); |
| 778 | + Cursor<Blog> blogs = mapper.openRangeBlogs(new RowBounds(1, 1)); |
| 779 | + |
| 780 | + Iterator<Blog> blogIterator = blogs.iterator(); |
| 781 | + Blog blog = blogIterator.next(); |
| 782 | + assertEquals(2, blog.getId()); |
| 783 | + assertFalse(blogIterator.hasNext()); |
| 784 | + |
| 785 | + } finally { |
| 786 | + session.close(); |
| 787 | + } |
| 788 | + } |
| 789 | + |
738 | 790 | }
|
0 commit comments