use of org.apache.ibatis.mapping.ResultMap 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;
}
use of org.apache.ibatis.mapping.ResultMap in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectPostWithBlogByAuthorMappedStatement.
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();
}
use of org.apache.ibatis.mapping.ResultMap in project mybatis-3 by mybatis.
the class ExecutorTestHelper method prepareSelectBlogByIdAndAuthor.
public static MappedStatement prepareSelectBlogByIdAndAuthor(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 = ? and a.id = ?");
final ParameterMap parameterMap = new ParameterMap.Builder(config, "defaultParameterMap", Map.class, new ArrayList<ParameterMapping>() {
{
add(new ParameterMapping.Builder(config, "blogId", registry.getTypeHandler(int.class)).build());
add(new ParameterMapping.Builder(config, "authorId", 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, "selectBlogByIdAndAuthor", sqlSource, SqlCommandType.SELECT).parameterMap(parameterMap).resultMaps(new ArrayList<ResultMap>() {
{
add(resultMap);
}
}).build();
}
use of org.apache.ibatis.mapping.ResultMap 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();
}
use of org.apache.ibatis.mapping.ResultMap in project mybatis-3 by mybatis.
the class MapperBuilderAssistant method buildDiscriminator.
public Discriminator buildDiscriminator(Class<?> resultType, String column, Class<?> javaType, JdbcType jdbcType, Class<? extends TypeHandler<?>> typeHandler, Map<String, String> discriminatorMap) {
ResultMapping resultMapping = buildResultMapping(resultType, null, column, javaType, jdbcType, null, null, null, null, typeHandler, new ArrayList<ResultFlag>(), null, null, false);
Map<String, String> namespaceDiscriminatorMap = new HashMap<String, String>();
for (Map.Entry<String, String> e : discriminatorMap.entrySet()) {
String resultMap = e.getValue();
resultMap = applyCurrentNamespace(resultMap, true);
namespaceDiscriminatorMap.put(e.getKey(), resultMap);
}
return new Discriminator.Builder(configuration, resultMapping, namespaceDiscriminatorMap).build();
}
Aggregations