use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class DefaultResultSetHandlerTest method shouldRetainColumnNameCase.
/**
* Contrary to the spec, some drivers require case-sensitive column names when getting result.
*
* @see <a href="http://code.google.com/p/mybatis/issues/detail?id=557">Issue 557</a>
*/
@Test
public void shouldRetainColumnNameCase() throws Exception {
final MappedStatement ms = getMappedStatement();
final Executor executor = null;
final ParameterHandler parameterHandler = null;
final ResultHandler resultHandler = null;
final BoundSql boundSql = null;
final RowBounds rowBounds = new RowBounds(0, 100);
final DefaultResultSetHandler fastResultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);
when(stmt.getResultSet()).thenReturn(rs);
when(rs.getMetaData()).thenReturn(rsmd);
when(rs.getType()).thenReturn(ResultSet.TYPE_FORWARD_ONLY);
when(rs.next()).thenReturn(true).thenReturn(false);
when(rs.getInt("CoLuMn1")).thenReturn(100);
when(rs.wasNull()).thenReturn(false);
when(rsmd.getColumnCount()).thenReturn(1);
when(rsmd.getColumnLabel(1)).thenReturn("CoLuMn1");
when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
when(stmt.getConnection()).thenReturn(conn);
when(conn.getMetaData()).thenReturn(dbmd);
// for simplicity.
when(dbmd.supportsMultipleResultSets()).thenReturn(false);
final List<Object> results = fastResultSetHandler.handleResultSets(stmt);
assertEquals(1, results.size());
assertEquals(Integer.valueOf(100), ((HashMap) results.get(0)).get("cOlUmN1"));
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldSelectAllAuthorsAutoMapped.
@Test
public void shouldSelectAllAuthorsAutoMapped() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
MappedStatement selectStatement = ExecutorTestHelper.prepareSelectAllAuthorsAutoMappedStatement(config);
List<Author> authors = executor.query(selectStatement, null, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
assertEquals(2, authors.size());
Author author = authors.get(0);
// id,username, password, email, bio, favourite_section
// (101,'jim','********','jim@ibatis.apache.org','','NEWS');
assertEquals(101, author.getId());
assertEquals("jim", author.getUsername());
assertEquals("jim@ibatis.apache.org", author.getEmail());
assertEquals("", author.getBio());
assertEquals(Section.NEWS, author.getFavouriteSection());
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldSelect2DiscriminatedPosts.
@Test
public void shouldSelect2DiscriminatedPosts() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
MappedStatement selectStatement = ExecutorTestHelper.prepareSelectDiscriminatedPost(config);
List<Map<String, String>> products = executor.query(selectStatement, null, new RowBounds(2, 2), Executor.NO_RESULT_HANDLER);
assertEquals(2, products.size());
for (Map<String, String> m : products) {
if ("IMAGES".equals(m.get("SECTION"))) {
assertNull(m.get("subject"));
} else {
assertNotNull(m.get("subject"));
}
}
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class BaseExecutorTest method shouldDeleteAuthor.
@Test
public void shouldDeleteAuthor() throws Exception {
Executor executor = createExecutor(new JdbcTransaction(ds, null, false));
try {
Author author = new Author(101, null, null, null, null, null);
MappedStatement deleteStatement = ExecutorTestHelper.prepareDeleteAuthorMappedStatement(config);
MappedStatement selectStatement = ExecutorTestHelper.prepareSelectOneAuthorMappedStatement(config);
int rows = executor.update(deleteStatement, author);
List<Author> authors = executor.query(selectStatement, 101, RowBounds.DEFAULT, Executor.NO_RESULT_HANDLER);
executor.flushStatements();
executor.rollback(true);
assertEquals(0, authors.size());
assertTrue(1 == rows || BatchExecutor.BATCH_UPDATE_RETURN_VALUE == rows);
} finally {
executor.rollback(true);
executor.close(false);
}
}
use of org.apache.ibatis.mapping.MappedStatement in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectTwoSetsOfAuthorsProc.
public static MappedStatement prepareSelectTwoSetsOfAuthorsProc(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
MappedStatement ms = new MappedStatement.Builder(config, "selectTwoSetsOfAuthors", new StaticSqlSource(config, "{call selectTwoSetsOfAuthors(?,?)}"), SqlCommandType.SELECT).statementType(StatementType.CALLABLE).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id1", registry.getTypeHandler(int.class)).build());
add(new ParameterMapping.Builder(config, "id2", registry.getTypeHandler(int.class)).build());
}
}).build()).resultMaps(new ArrayList<ResultMap>() {
{
ResultMap map = new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build());
add(new ResultMapping.Builder(config, "username", "username", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "password", "password", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "email", "email", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "bio", "bio", registry.getTypeHandler(String.class)).build());
}
}).build();
add(map);
add(map);
}
}).build();
return ms;
}
Aggregations