Search in sources :

Example 6 with StaticSqlSource

use of org.apache.ibatis.builder.StaticSqlSource in project mybatis-3 by mybatis.

the class ExecutorTestHelper method prepareInsertAuthorProc.

public static MappedStatement prepareInsertAuthorProc(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = new MappedStatement.Builder(config, "insertAuthorProc", new StaticSqlSource(config, "{call insertAuthor(?,?,?,?)}"), SqlCommandType.INSERT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {

        {
            add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
            add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
        }
    }).build()).cache(authorCache).build();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) MappedStatement(org.apache.ibatis.mapping.MappedStatement) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 7 with StaticSqlSource

use of org.apache.ibatis.builder.StaticSqlSource in project mybatis-3 by mybatis.

the class ExecutorTestHelper method createSelectAuthorWithIDof99MappedStatement.

public static MappedStatement createSelectAuthorWithIDof99MappedStatement(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = new MappedStatement.Builder(config, "selectAuthor", new StaticSqlSource(config, "SELECT * FROM author WHERE id = 99"), SqlCommandType.SELECT).statementType(StatementType.STATEMENT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>()).build()).resultMaps(new ArrayList<ResultMap>() {

        {
            add(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());
        }
    }).build();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) ResultMapping(org.apache.ibatis.mapping.ResultMapping) ArrayList(java.util.ArrayList) MappedStatement(org.apache.ibatis.mapping.MappedStatement) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 8 with StaticSqlSource

use of org.apache.ibatis.builder.StaticSqlSource in project mybatis-3 by mybatis.

the class ExecutorTestHelper method prepareUpdateAuthorMappedStatement.

public static MappedStatement prepareUpdateAuthorMappedStatement(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = new MappedStatement.Builder(config, "updateAuthor", new StaticSqlSource(config, "UPDATE author SET username = ?, password = ?, email = ?, bio = ? WHERE id = ?"), SqlCommandType.UPDATE).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {

        {
            add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
            add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
    }).build()).cache(authorCache).build();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) MappedStatement(org.apache.ibatis.mapping.MappedStatement) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource)

Example 9 with StaticSqlSource

use of org.apache.ibatis.builder.StaticSqlSource in project mybatis-3 by mybatis.

the class ExecutorTestHelper method prepareInsertAuthorMappedStatementWithAutoKey.

public static MappedStatement prepareInsertAuthorMappedStatementWithAutoKey(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config, "INSERT INTO author (username,password,email,bio,favourite_section) values(?,?,?,?,?)"), SqlCommandType.INSERT).parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {

        {
            add(new ParameterMapping.Builder(config, "username", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).build());
            add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).build());
            add(new ParameterMapping.Builder(config, "favouriteSection", registry.getTypeHandler(Section.class)).jdbcType(JdbcType.VARCHAR).build());
        }
    }).build()).cache(authorCache).keyGenerator(Jdbc3KeyGenerator.INSTANCE).keyProperty("id").build();
    return ms;
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) ParameterMapping(org.apache.ibatis.mapping.ParameterMapping) MappedStatement(org.apache.ibatis.mapping.MappedStatement) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource) Section(org.apache.ibatis.domain.blog.Section)

Example 10 with StaticSqlSource

use of org.apache.ibatis.builder.StaticSqlSource in project mybatis-3 by mybatis.

the class ExecutorTestHelper method prepareComplexSelectBlogMappedStatement.

public static MappedStatement prepareComplexSelectBlogMappedStatement(final Configuration config) {
    final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
    final SqlSource sqlSource = new StaticSqlSource(config, "SELECT b.id, b.author_id, b.title, a.username, a.password, a.email, a.bio" + " FROM blog b" + " INNER JOIN author a ON b.author_id = a.id" + " WHERE b.id = ?");
    final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", int.class, new ArrayList<ParameterMapping>() {

        {
            add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
    }).build();
    final ResultMap resultMap = new ResultMap.Builder(config, "defaultResultMap", Blog.class, new ArrayList<ResultMapping>() {

        {
            add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(int.class)).flags(new ArrayList<ResultFlag>() {

                {
                    add(ResultFlag.ID);
                }
            }).build());
            add(new ResultMapping.Builder(config, "title", "title", registry.getTypeHandler(String.class)).build());
            add(new ResultMapping.Builder(config, "author.id", "author_id", registry.getTypeHandler(int.class)).build());
            add(new ResultMapping.Builder(config, "author.username", "username", registry.getTypeHandler(String.class)).build());
            add(new ResultMapping.Builder(config, "author.password", "password", registry.getTypeHandler(String.class)).build());
            add(new ResultMapping.Builder(config, "author.email", "email", registry.getTypeHandler(String.class)).build());
            add(new ResultMapping.Builder(config, "author.bio", "bio", registry.getTypeHandler(String.class)).build());
            add(new ResultMapping.Builder(config, "posts", "id", registry.getTypeHandler(int.class)).javaType(List.class).nestedQueryId("selectPostsForBlog").build());
        }
    }).build();
    return new MappedStatement.Builder(config, "selectBlogById", sqlSource, SqlCommandType.SELECT).parameterMap(parameterMap).resultMaps(new ArrayList<ResultMap>() {

        {
            add(resultMap);
        }
    }).build();
}
Also used : TypeHandlerRegistry(org.apache.ibatis.type.TypeHandlerRegistry) DynamicSqlSource(org.apache.ibatis.scripting.xmltags.DynamicSqlSource) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource) SqlSource(org.apache.ibatis.mapping.SqlSource) ResultMap(org.apache.ibatis.mapping.ResultMap) ArrayList(java.util.ArrayList) ParameterMap(org.apache.ibatis.mapping.ParameterMap) ResultMapping(org.apache.ibatis.mapping.ResultMapping) ArrayList(java.util.ArrayList) List(java.util.List) MappedStatement(org.apache.ibatis.mapping.MappedStatement) ResultFlag(org.apache.ibatis.mapping.ResultFlag) StaticSqlSource(org.apache.ibatis.builder.StaticSqlSource) Blog(org.apache.ibatis.domain.blog.Blog)

Aggregations

StaticSqlSource (org.apache.ibatis.builder.StaticSqlSource)20 TypeHandlerRegistry (org.apache.ibatis.type.TypeHandlerRegistry)19 MappedStatement (org.apache.ibatis.mapping.MappedStatement)17 ArrayList (java.util.ArrayList)14 ResultMap (org.apache.ibatis.mapping.ResultMap)11 Section (org.apache.ibatis.domain.blog.Section)8 ParameterMap (org.apache.ibatis.mapping.ParameterMap)8 ParameterMapping (org.apache.ibatis.mapping.ParameterMapping)8 Author (org.apache.ibatis.domain.blog.Author)7 ResultMapping (org.apache.ibatis.mapping.ResultMapping)7 ResultFlag (org.apache.ibatis.mapping.ResultFlag)6 DynamicSqlSource (org.apache.ibatis.scripting.xmltags.DynamicSqlSource)6 SqlSource (org.apache.ibatis.mapping.SqlSource)5 Blog (org.apache.ibatis.domain.blog.Blog)4 Date (java.util.Date)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)2 List (java.util.List)2