use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class DefaultResultSetHandler method handleRefCursorOutputParameter.
private void handleRefCursorOutputParameter(ResultSet rs, ParameterMapping parameterMapping, MetaObject metaParam) throws SQLException {
if (rs == null) {
return;
}
try {
final String resultMapId = parameterMapping.getResultMapId();
final ResultMap resultMap = configuration.getResultMap(resultMapId);
final DefaultResultHandler resultHandler = new DefaultResultHandler(objectFactory);
final ResultSetWrapper rsw = new ResultSetWrapper(rs, configuration);
handleRowValues(rsw, resultMap, resultHandler, new RowBounds(), null);
metaParam.setValue(parameterMapping.getProperty(), resultHandler.getResultList());
} finally {
// issue #228 (close resultsets)
closeResultSet(rs);
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class DefaultResultSetHandlerTest method shouldThrowExceptionWithColumnName.
@Test
public void shouldThrowExceptionWithColumnName() throws Exception {
final MappedStatement ms = getMappedStatement();
final RowBounds rowBounds = new RowBounds(0, 100);
final DefaultResultSetHandler defaultResultSetHandler = new DefaultResultSetHandler(null, /*executor*/
ms, null, /*parameterHandler*/
null, /*resultHandler*/
null, /*boundSql*/
rowBounds);
final ResultSetWrapper rsw = mock(ResultSetWrapper.class);
when(rsw.getResultSet()).thenReturn(mock(ResultSet.class));
final ResultMapping resultMapping = mock(ResultMapping.class);
final TypeHandler typeHandler = mock(TypeHandler.class);
when(resultMapping.getColumn()).thenReturn("column");
when(resultMapping.getTypeHandler()).thenReturn(typeHandler);
when(typeHandler.getResult(any(ResultSet.class), any(String.class))).thenThrow(new SQLException("exception"));
List<ResultMapping> constructorMappings = Collections.singletonList(resultMapping);
try {
defaultResultSetHandler.createParameterizedResultObject(rsw, null, /*resultType*/
constructorMappings, null, /*constructorArgTypes*/
null, /*constructorArgs*/
null);
Assert.fail("Should have thrown ExecutorException");
} catch (Exception e) {
Assert.assertTrue("Expected ExecutorException", e instanceof ExecutorException);
Assert.assertTrue("", e.getMessage().contains("mapping: " + resultMapping.toString()));
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class BindingTest method shouldSelectListOfPostsLike.
@Test
public void shouldSelectListOfPostsLike() {
SqlSession session = sqlSessionFactory.openSession();
try {
BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
List<Post> posts = mapper.selectPostsLike(new RowBounds(1, 1), "%a%");
assertEquals(1, posts.size());
} finally {
session.close();
}
}
use of org.apache.ibatis.session.RowBounds in project mybatis-3 by mybatis.
the class CursorNestedTest method testCursorWithRowBound.
@Test
public void testCursorWithRowBound() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Cursor<User> usersCursor = sqlSession.selectCursor("getAllUsers", null, new RowBounds(2, 1));
Iterator<User> iterator = usersCursor.iterator();
Assert.assertTrue(iterator.hasNext());
User user = iterator.next();
Assert.assertEquals("User3", user.getName());
Assert.assertEquals(2, usersCursor.getCurrentIndex());
Assert.assertFalse(iterator.hasNext());
Assert.assertFalse(usersCursor.isOpen());
Assert.assertTrue(usersCursor.isConsumed());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.RowBounds in project generator by mybatis.
the class FlatJava5Test method testPKFieldsSelectByExampleBetweenWithRowbounds.
@Test
public void testPKFieldsSelectByExampleBetweenWithRowbounds() {
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
Pkfields record = new Pkfields();
record.setFirstname("Fred");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(1);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Wilma");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(2);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Pebbles");
record.setLastname("Flintstone");
record.setId1(1);
record.setId2(3);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Barney");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(1);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Betty");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(2);
mapper.insert(record);
record = new Pkfields();
record.setFirstname("Bamm Bamm");
record.setLastname("Rubble");
record.setId1(2);
record.setId2(3);
mapper.insert(record);
PkfieldsExample example = new PkfieldsExample();
example.createCriteria().andId2Between(1, 3);
example.setOrderByClause("ID1, ID2");
RowBounds rb = new RowBounds(2, 3);
List<Pkfields> answer = mapper.selectByExampleWithRowbounds(example, rb);
assertEquals(3, answer.size());
assertEquals("Pebbles", answer.get(0).getFirstname());
assertEquals("Barney", answer.get(1).getFirstname());
assertEquals("Betty", answer.get(2).getFirstname());
} finally {
sqlSession.close();
}
}
Aggregations