use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatement.
static MappedStatement prepareSelectOneAuthorMappedStatement(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final ResultMap rm = 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());
add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build());
}
}).build();
return new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config, "SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
}
}).build()).resultMaps(new ArrayList<ResultMap>() {
{
add(rm);
}
}).cache(authorCache).build();
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectDiscriminatedPost.
static MappedStatement prepareSelectDiscriminatedPost(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final ResultMap discriminatorResultMap = new ResultMap.Builder(config, "postResultMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
}
}).build();
config.addResultMap(discriminatorResultMap);
return new MappedStatement.Builder(config, "selectPosts", new StaticSqlSource(config, "SELECT * FROM post"), SqlCommandType.SELECT).resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "defaultResultMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).build());
add(new ResultMapping.Builder(config, "blog_id", "blog_id", registry.getTypeHandler(int.class)).build());
}
}).discriminator(new Discriminator.Builder(config, new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(String.class)).build(), new HashMap<String, String>() {
{
put("NEWS", discriminatorResultMap.getId());
put("VIDEOS", discriminatorResultMap.getId());
put("PODCASTS", discriminatorResultMap.getId());
// NEWS left out on purpose.
}
}).build()).build());
}
}).build();
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatementWithConstructorResults.
static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
return new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config, "SELECT * FROM author WHERE id = ?"), SqlCommandType.SELECT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
}
}).build()).resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "defaultResultMap", Author.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, null, "id", registry.getTypeHandler(Integer.class)).javaType(int.class).flags(new ArrayList<ResultFlag>() {
{
add(ResultFlag.CONSTRUCTOR);
}
}).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());
add(new ResultMapping.Builder(config, "favouriteSection", "favourite_section", registry.getTypeHandler(Section.class)).build());
}
}).build());
}
}).cache(authorCache).build();
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class DefaultResultSetHandlerTest2 method shouldNotCallNextOnClosedResultSet_NestedResult.
@SuppressWarnings("serial")
@Test
void shouldNotCallNextOnClosedResultSet_NestedResult() throws Exception {
final Configuration config = new Configuration();
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final ResultMap nestedResultMap = new ResultMap.Builder(config, "roleMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "role", "role", registry.getTypeHandler(String.class)).build());
}
}).build();
config.addResultMap(nestedResultMap);
final MappedStatement ms = new MappedStatement.Builder(config, "selectPerson", new StaticSqlSource(config, "select person..."), SqlCommandType.SELECT).resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "personMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(Integer.class)).build());
add(new ResultMapping.Builder(config, "roles").nestedResultMapId("roleMap").build());
}
}).build());
}
}).resultOrdered(true).build();
final Executor executor = null;
final ParameterHandler parameterHandler = null;
final ResultHandler<?> resultHandler = null;
final BoundSql boundSql = null;
final RowBounds rowBounds = new RowBounds(5, 1);
final DefaultResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);
when(stmt.getResultSet()).thenReturn(rs);
when(rsmd.getColumnCount()).thenReturn(2);
when(rsmd.getColumnLabel(1)).thenReturn("id");
when(rsmd.getColumnType(1)).thenReturn(Types.INTEGER);
when(rsmd.getColumnClassName(1)).thenReturn(Integer.class.getCanonicalName());
final List<Object> results = resultSetHandler.handleResultSets(stmt);
assertEquals(0, results.size());
}
use of org.apache.ibatis.type.TypeHandlerRegistry in project mybatis-3 by mybatis.
the class DefaultResultSetHandlerTest2 method shouldNotCallNextOnClosedResultSet_SimpleResult.
@SuppressWarnings("serial")
@Test
void shouldNotCallNextOnClosedResultSet_SimpleResult() throws Exception {
final Configuration config = new Configuration();
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
final MappedStatement ms = new MappedStatement.Builder(config, "testSelect", new StaticSqlSource(config, "some select statement"), SqlCommandType.SELECT).resultMaps(new ArrayList<ResultMap>() {
{
add(new ResultMap.Builder(config, "testMap", HashMap.class, new ArrayList<ResultMapping>() {
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(Integer.class)).build());
}
}).build());
}
}).build();
final Executor executor = null;
final ParameterHandler parameterHandler = null;
final ResultHandler<?> resultHandler = null;
final BoundSql boundSql = null;
final RowBounds rowBounds = new RowBounds(5, 1);
final DefaultResultSetHandler resultSetHandler = new DefaultResultSetHandler(executor, ms, parameterHandler, resultHandler, boundSql, rowBounds);
when(stmt.getResultSet()).thenReturn(rs);
when(rsmd.getColumnCount()).thenReturn(1);
when(rsmd.getColumnLabel(1)).thenReturn("id");
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 = resultSetHandler.handleResultSets(stmt);
assertEquals(0, results.size());
}
Aggregations