org.apache.ibatis.mapping.ParameterMap Java Examples

The following examples show how to use org.apache.ibatis.mapping.ParameterMap. 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 mybatis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 6 votes vote down vote up
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(new Jdbc3KeyGenerator())
      .keyProperty("id")
      .build();
  return ms;
}
 
Example #4
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 6 votes vote down vote up
public static MappedStatement prepareInsertAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,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, "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());
                  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).build();
  return ms;
}
 
Example #5
Source File: MapperBuilderAssistant.java    From mybatis with Apache License 2.0 6 votes vote down vote up
private void setStatementParameterMap(
    String parameterMap,
    Class<?> parameterTypeClass,
    MappedStatement.Builder statementBuilder) {
  parameterMap = applyCurrentNamespace(parameterMap, true);

  if (parameterMap != null) {
    try {
      statementBuilder.parameterMap(configuration.getParameterMap(parameterMap));
    } catch (IllegalArgumentException e) {
      throw new IncompleteElementException("Could not find parameter map " + parameterMap, e);
    }
  } else if (parameterTypeClass != null) {
    List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
    ParameterMap.Builder inlineParameterMapBuilder = new ParameterMap.Builder(
        configuration,
        statementBuilder.id() + "-Inline",
        parameterTypeClass,
        parameterMappings);
    statementBuilder.parameterMap(inlineParameterMapBuilder.build());
  }
}
 
Example #6
Source File: MapperBuilderAssistant.java    From mybaties with Apache License 2.0 6 votes vote down vote up
private void setStatementParameterMap(
    String parameterMap,
    Class<?> parameterTypeClass,
    MappedStatement.Builder statementBuilder) {
  parameterMap = applyCurrentNamespace(parameterMap, true);

  if (parameterMap != null) {
    try {
      statementBuilder.parameterMap(configuration.getParameterMap(parameterMap));
    } catch (IllegalArgumentException e) {
      throw new IncompleteElementException("Could not find parameter map " + parameterMap, e);
    }
  } else if (parameterTypeClass != null) {
    List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
    ParameterMap.Builder inlineParameterMapBuilder = new ParameterMap.Builder(
        configuration,
        statementBuilder.id() + "-Inline",
        parameterTypeClass,
        parameterMappings);
    statementBuilder.parameterMap(inlineParameterMapBuilder.build());
  }
}
 
Example #7
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 6 votes vote down vote up
public static MappedStatement prepareInsertAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,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, "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());
                  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).build();
  return ms;
}
 
Example #8
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 6 votes vote down vote up
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(new Jdbc3KeyGenerator())
      .keyProperty("id")
      .build();
  return ms;
}
 
Example #9
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 6 votes vote down vote up
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT)
      .statementType(StatementType.CALLABLE)
      .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)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
            }
          }).build())
      .resultMaps(new ArrayList<ResultMap>())
      .cache(authorCache).build();
  return ms;
}
 
Example #12
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 6 votes vote down vote up
public static MappedStatement prepareSelectAuthorViaOutParams(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "selectAuthorViaOutParams", new StaticSqlSource(config, "{call selectAuthorViaOutParams(?,?,?,?,?)}"), SqlCommandType.SELECT)
      .statementType(StatementType.CALLABLE)
      .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)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "password", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "email", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
              add(new ParameterMapping.Builder(config, "bio", registry.getTypeHandler(String.class)).jdbcType(JdbcType.VARCHAR).mode(ParameterMode.OUT).build());
            }
          }).build())
      .resultMaps(new ArrayList<ResultMap>())
      .cache(authorCache).build();
  return ms;
}
 
Example #13
Source File: MapperBuilderAssistant.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public ParameterMap addParameterMap(String id, Class<?> parameterClass, List<ParameterMapping> parameterMappings) {
  id = applyCurrentNamespace(id, false);
  ParameterMap.Builder parameterMapBuilder = new ParameterMap.Builder(configuration, id, parameterClass, parameterMappings);
  ParameterMap parameterMap = parameterMapBuilder.build();
  configuration.addParameterMap(parameterMap);
  return parameterMap;
}
 
Example #14
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #15
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public static MappedStatement createInsertAuthorWithIDof99MappedStatement(final Configuration config) {
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio) values(99,'someone','******','[email protected]',null)"), SqlCommandType.INSERT)
      .statementType(StatementType.STATEMENT)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>()).build())
      .cache(authorCache)
      .build();
  return ms;
}
 
Example #16
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public static MappedStatement prepareInsertAuthorMappedStatementWithBeforeAutoKey(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  final ResultMap rm = new ResultMap.Builder(config, "keyResultMap", Integer.class, new ArrayList<ResultMapping>())
      .build();

  MappedStatement kms = new MappedStatement.Builder(config, "insertAuthor!selectKey", new StaticSqlSource(config,"SELECT 123456 as id FROM SYSIBM.SYSDUMMY1"), SqlCommandType.SELECT)
      .keyProperty("id")
      .resultMaps(new ArrayList<ResultMap>() {
        {
          add(rm);
        }
      })
      .build();
  config.addMappedStatement(kms);
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new DynamicSqlSource(config, new TextSqlNode("INSERT INTO author (id,username,password,email,bio,favourite_section) values(#{id},#{username},#{password},#{email},#{bio:VARCHAR},#{favouriteSection})")), SqlCommandType.INSERT)
      .parameterMap(
          new ParameterMap.Builder(config, "defaultParameterMap", Author.class, new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(Integer.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());
              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(new SelectKeyGenerator(kms, true))
      .keyProperty("id")
      .build();
  return ms;
}
 
Example #17
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #18
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public 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();

  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(rm);
        }
      })
      .cache(authorCache).build();
  return ms;
}
 
Example #20
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #21
Source File: ExecutorTestHelper.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public static MappedStatement prepareDeleteAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "deleteAuthor", new StaticSqlSource(config,"DELETE FROM author WHERE id = ?"), SqlCommandType.DELETE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
            }
          }).build())
      .cache(authorCache)
      .build();
  return ms;
}
 
Example #22
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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();

}
 
Example #23
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #24
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public static MappedStatement createInsertAuthorWithIDof99MappedStatement(final Configuration config) {
  MappedStatement ms = new MappedStatement.Builder(config, "insertAuthor", new StaticSqlSource(config,"INSERT INTO author (id,username,password,email,bio) values(99,'someone','******','[email protected]',null)"), SqlCommandType.INSERT)
      .statementType(StatementType.STATEMENT)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>()).build())
      .cache(authorCache)
      .build();
  return ms;
}
 
Example #25
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #26
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public 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();

  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(rm);
        }
      })
      .cache(authorCache).build();
  return ms;
}
 
Example #28
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public static MappedStatement prepareDeleteAuthorMappedStatement(final Configuration config) {
  final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();
  MappedStatement ms = new MappedStatement.Builder(config, "deleteAuthor", new StaticSqlSource(config,"DELETE FROM author WHERE id = ?"), SqlCommandType.DELETE)
      .parameterMap(new ParameterMap.Builder(config, "defaultParameterMap", Author.class,
          new ArrayList<ParameterMapping>() {
            {
              add(new ParameterMapping.Builder(config, "id", registry.getTypeHandler(int.class)).build());
            }
          }).build())
      .cache(authorCache)
      .build();
  return ms;
}
 
Example #29
Source File: ExecutorTestHelper.java    From mybaties with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #30
Source File: MapperBuilderAssistant.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public ParameterMap addParameterMap(String id, Class<?> parameterClass, List<ParameterMapping> parameterMappings) {
  id = applyCurrentNamespace(id, false);
  ParameterMap.Builder parameterMapBuilder = new ParameterMap.Builder(configuration, id, parameterClass, parameterMappings);
  ParameterMap parameterMap = parameterMapBuilder.build();
  configuration.addParameterMap(parameterMap);
  return parameterMap;
}