use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class NestedResultHandlerAssociationTest method shouldHandleRowBounds.
@Test
public void shouldHandleRowBounds() throws Exception {
SqlSession sqlSession = sqlSessionFactory.openSession();
final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
Date targetMonth = fmt.parse("2014-01-01");
final List<Account> accounts = new ArrayList<Account>();
try {
sqlSession.select("collectPageByBirthMonth", targetMonth, new RowBounds(1, 2), new ResultHandler() {
@Override
public void handleResult(ResultContext context) {
Account account = (Account) context.getResultObject();
accounts.add(account);
}
});
} finally {
sqlSession.close();
}
assertEquals(2, accounts.size());
assertEquals("Bob2", accounts.get(0).getAccountName());
assertEquals("Bob3", accounts.get(1).getAccountName());
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class DuplicateStatementsTest method shouldGetFirstFourUsers_Annotated.
@Test
@Ignore("fails currently - issue 507")
public void shouldGetFirstFourUsers_Annotated() {
sqlSessionFactory.getConfiguration().addMapper(AnnotatedMapper.class);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
List<User> users = mapper.getAllUsers(new RowBounds(0, 4));
Assert.assertEquals(4, users.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class DuplicateStatementsTest method shouldGetFirstFourUsers.
@Test
public void shouldGetFirstFourUsers() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Mapper mapper = sqlSession.getMapper(Mapper.class);
List<User> users = mapper.getAllUsers(new RowBounds(0, 4));
Assert.assertEquals(4, users.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class CursorSimpleTest method testCursorWithBadRowBound.
@Test
public void testCursorWithBadRowBound() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
// Trying to start at offset 10 (which does not exist, since there is only 4 items)
Cursor<User> usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(10, 2));
Iterator<User> iterator = usersCursor.iterator();
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(usersCursor.isOpen());
Assert.assertTrue(usersCursor.isConsumed());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class CursorSimpleTest method testCursorWithRowBound.
@Test
public void testCursorWithRowBound() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
// RowBound starting at offset 1 and limiting to 2 items
Cursor<User> usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(1, 3));
Iterator<User> iterator = usersCursor.iterator();
User user = iterator.next();
Assert.assertEquals("User2", user.getName());
Assert.assertEquals(1, usersCursor.getCurrentIndex());
// Calling hasNext() before next()
Assert.assertTrue(iterator.hasNext());
user = iterator.next();
Assert.assertEquals("User3", user.getName());
Assert.assertEquals(2, usersCursor.getCurrentIndex());
// Calling next() without a previous hasNext() call
user = iterator.next();
Assert.assertEquals("User4", user.getName());
Assert.assertEquals(3, usersCursor.getCurrentIndex());
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(usersCursor.isOpen());
Assert.assertTrue(usersCursor.isConsumed());
} finally {
sqlSession.close();
}
}
Aggregations