Java Code Examples for org.apache.ibatis.session.Configuration#addResultMap()

The following examples show how to use org.apache.ibatis.session.Configuration#addResultMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public 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);
  MappedStatement ms = 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();
  return ms;
}
 
Example 2
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public 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);
  MappedStatement ms = 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();
  return ms;
}
 
Example 3
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostsForBlogMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " INNER JOIN post_tag pt ON pt.post_id = p.id" +
      " INNER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.blog_id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "defaultResultMap", Post.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, "blog", "blog_id", registry.getTypeHandler(int.class)).javaType(Blog.class).nestedQueryId("selectBlogById").build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();
  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}
 
Example 4
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" +
      " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "", Post.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, "blog", "blog_id", registry.getTypeHandler(int.class)).javaType(Blog.class).nestedQueryId("selectBlogById").build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();


  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}
 
Example 5
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostWithBlogByAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.author_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" +
      " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "postResultMap", Post.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, "blog").nestedQueryId("selectBlogByIdAndAuthor").composites(new ArrayList<ResultMapping>() {
        {
          add(new ResultMapping.Builder(config, "authorId", "author_id", registry.getTypeHandler(int.class)).build());
          add(new ResultMapping.Builder(config, "blogId", "blog_id", registry.getTypeHandler(int.class)).build());
        }
      }).build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();


  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}
 
Example 6
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostsForBlogMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " INNER JOIN post_tag pt ON pt.post_id = p.id" +
      " INNER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.blog_id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "defaultResultMap", Post.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, "blog", "blog_id", registry.getTypeHandler(int.class)).javaType(Blog.class).nestedQueryId("selectBlogById").build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();
  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}
 
Example 7
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" +
      " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "", Post.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, "blog", "blog_id", registry.getTypeHandler(int.class)).javaType(Blog.class).nestedQueryId("selectBlogById").build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();


  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}
 
Example 8
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public static MappedStatement prepareSelectPostWithBlogByAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final SqlSource sqlSource = new StaticSqlSource(config,"SELECT p.id, p.created_on, p.blog_id, p.author_id, p.section, p.subject, p.body, pt.tag_id," +
      " t.name as tag_name, c.id as comment_id, c.name as comment_name, c.comment" +
      " FROM post p" +
      " LEFT OUTER JOIN post_tag pt ON pt.post_id = p.id" +
      " LEFT OUTER JOIN tag t ON pt.tag_id = t.id" +
      " LEFT OUTER JOIN comment c ON c.post_id = p.id" +
      " WHERE p.id = ?");
  final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
      new ArrayList<ParameterMapping>() {
        {
          add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
        }
      }).build();
  final ResultMap tagResultMap = new ResultMap.Builder(config, "tagResultMap", Tag.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "tag_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "tag_name", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  final ResultMap commentResultMap = new ResultMap.Builder(config, "commentResultMap", Comment.class, new ArrayList<ResultMapping>() {
    {
      add(new ResultMapping.Builder(config, "id", "comment_id", registry.getTypeHandler(int.class))
          .flags(new ArrayList<ResultFlag>() {
            {
              add(ResultFlag.ID);
            }
          }).build());
      add(new ResultMapping.Builder(config, "name", "comment_name", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "comment", "comment", registry.getTypeHandler(String.class)).build());
    }
  }).build();
  config.addResultMap(tagResultMap);
  config.addResultMap(commentResultMap);
  final ResultMap postResultMap = new ResultMap.Builder(config, "postResultMap", Post.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, "blog").nestedQueryId("selectBlogByIdAndAuthor").composites(new ArrayList<ResultMapping>() {
        {
          add(new ResultMapping.Builder(config, "authorId", "author_id", registry.getTypeHandler(int.class)).build());
          add(new ResultMapping.Builder(config, "blogId", "blog_id", registry.getTypeHandler(int.class)).build());
        }
      }).build());
      add(new ResultMapping.Builder(config, "createdOn", "created_on", registry.getTypeHandler(Date.class)).build());
      add(new ResultMapping.Builder(config, "section", "section", registry.getTypeHandler(Section.class)).build());
      add(new ResultMapping.Builder(config, "subject", "subject", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "body", "body", registry.getTypeHandler(String.class)).build());
      add(new ResultMapping.Builder(config, "tags").nestedResultMapId(tagResultMap.getId()).build());
      add(new ResultMapping.Builder(config, "comments").nestedResultMapId(commentResultMap.getId()).build());
    }
  }).build();


  return new MappedStatement.Builder(config, "selectPostsForBlog", sqlSource, SqlCommandType.SELECT)
      .parameterMap(parameterMap)
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(postResultMap);
        }
      }).build();
}