Search in sources :

Example 11 with ParameterMap

use of org.apache.ibatis.mapping.ParameterMap in project mybatis-3 by mybatis.

the class ExecutorTestHelper method prepareSelectOneAuthorMappedStatementWithConstructorResults.

public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = 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();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ResultMap(org.apache.ibatis.mapping.ResultMap) ArrayList(java.util.ArrayList) ParameterMap(org.apache.ibatis.mapping.ParameterMap) Section(org.apache.ibatis.domain.blog.Section) Author(org.apache.ibatis.domain.blog.Author) MappedStatement(org.apache.ibatis.mapping.MappedStatement) ResultFlag(org.apache.ibatis.mapping.ResultFlag) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Aggregations

ParameterMap (org.apache.ibatis.mapping.ParameterMap)11 ArrayList (java.util.ArrayList)9 MappedStatement (org.apache.ibatis.mapping.MappedStatement)9 StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)8 ResultMap (org.apache.ibatis.mapping.ResultMap)8 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)8 Author (org.apache.ibatis.domain.blog.Author)6 ResultFlag (org.apache.ibatis.mapping.ResultFlag)6 Section (org.apache.ibatis.domain.blog.Section)5 ResultMapping (org.apache.ibatis.mapping.ResultMapping)5 SqlSource (org.apache.ibatis.mapping.SqlSource)5 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)5 Blog (org.apache.ibatis.domain.blog.Blog)4 Date (java.util.Date)3 List (java.util.List)3 Comment (org.apache.ibatis.domain.blog.Comment)3 Post (org.apache.ibatis.domain.blog.Post)3 Tag (org.apache.ibatis.domain.blog.Tag)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1