private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) { for (Arg arg : args) { List<ResultFlag> flags = new ArrayList<ResultFlag>(); flags.add(ResultFlag.CONSTRUCTOR); if (arg.id()) { flags.add(ResultFlag.ID); } ResultMapping resultMapping = assistant.buildResultMapping( resultType, null, nullOrEmpty(arg.column()), arg.javaType() == void.class ? null : arg.javaType(), arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(), nullOrEmpty(arg.select()), nullOrEmpty(arg.resultMap()), null, null, arg.typeHandler() == UnknownTypeHandler.class ? null : arg.typeHandler(), flags, null, null, false); resultMappings.add(resultMapping); } }
private void applyResultMap(String resultMapId, Class<?> returnType, Arg[] args, Result[] results, TypeDiscriminator discriminator) { List<ResultMapping> resultMappings = new ArrayList<>(); applyConstructorArgs(args, returnType, resultMappings); applyResults(results, returnType, resultMappings); Discriminator disc = applyDiscriminator(resultMapId, returnType, discriminator); // TODO add AutoMappingBehaviour assistant.addResultMap(resultMapId, returnType, null, disc, resultMappings, null); createDiscriminatorResultMaps(resultMapId, returnType, discriminator); }
private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) { for (Arg arg : args) { List<ResultFlag> flags = new ArrayList<>(); flags.add(ResultFlag.CONSTRUCTOR); if (arg.id()) { flags.add(ResultFlag.ID); } @SuppressWarnings("unchecked") Class<? extends TypeHandler<?>> typeHandler = (Class<? extends TypeHandler<?>>) (arg.typeHandler() == UnknownTypeHandler.class ? null : arg.typeHandler()); ResultMapping resultMapping = assistant.buildResultMapping( resultType, nullOrEmpty(arg.name()), nullOrEmpty(arg.column()), arg.javaType() == void.class ? null : arg.javaType(), arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(), nullOrEmpty(arg.select()), nullOrEmpty(arg.resultMap()), null, null, typeHandler, flags, null, null, false); resultMappings.add(resultMapping); } }
private void applyResultMap(String resultMapId, Class<?> returnType, Arg[] args, Result[] results, TypeDiscriminator discriminator) { List<ResultMapping> resultMappings = new ArrayList<ResultMapping>(); applyConstructorArgs(args, returnType, resultMappings); applyResults(results, returnType, resultMappings); Discriminator disc = applyDiscriminator(resultMapId, returnType, discriminator); // TODO add AutoMappingBehaviour assistant.addResultMap(resultMapId, returnType, null, disc, resultMappings, null); createDiscriminatorResultMaps(resultMapId, returnType, discriminator); }
private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) { for (Arg arg : args) { List<ResultFlag> flags = new ArrayList<ResultFlag>(); flags.add(ResultFlag.CONSTRUCTOR); if (arg.id()) { flags.add(ResultFlag.ID); } @SuppressWarnings("unchecked") Class<? extends TypeHandler<?>> typeHandler = (Class<? extends TypeHandler<?>>) (arg.typeHandler() == UnknownTypeHandler.class ? null : arg.typeHandler()); ResultMapping resultMapping = assistant.buildResultMapping( resultType, null, nullOrEmpty(arg.column()), arg.javaType() == void.class ? null : arg.javaType(), arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(), nullOrEmpty(arg.select()), nullOrEmpty(arg.resultMap()), null, null, typeHandler, flags, null, null, false); resultMappings.add(resultMapping); } }
private void applyConstructorArgs(Arg[] args, Class<?> resultType, List<ResultMapping> resultMappings) { for (Arg arg : args) { List<ResultFlag> flags = new ArrayList<ResultFlag>(); flags.add(ResultFlag.CONSTRUCTOR); if (arg.id()) { flags.add(ResultFlag.ID); } @SuppressWarnings("unchecked") Class<? extends TypeHandler<?>> typeHandler = (Class<? extends TypeHandler<?>>) (arg.typeHandler() == UnknownTypeHandler.class ? null : arg.typeHandler()); ResultMapping resultMapping = assistant.buildResultMapping( resultType, nullOrEmpty(arg.name()), nullOrEmpty(arg.column()), arg.javaType() == void.class ? null : arg.javaType(), arg.jdbcType() == JdbcType.UNDEFINED ? null : arg.jdbcType(), nullOrEmpty(arg.select()), nullOrEmpty(arg.resultMap()), null, null, typeHandler, flags, null, null, false); resultMappings.add(resultMapping); } }
private Arg[] argsIf(ConstructorArgs args) { return args == null ? new Arg[0] : args.value(); }
@Select("select id, name from product where name = #{value}") @ConstructorArgs({ @Arg(id = true, column="id", javaType = ProductId.class, jdbcType=JdbcType.INTEGER), @Arg(column="name") }) Product getProductByNameUsingConstructor(String name);
/** * 查询词频统计结果,查询频次开前的N个结果 */ @Select("SELECT `word`,`count` FROM `wordcount` ORDER BY `count` DESC LIMIT #{N}") @ConstructorArgs(value = { @Arg(column = "word", javaType = String.class), @Arg(column = "count", javaType = Integer.class) }) @ResultType(value = WordAndCount.class) public List<WordAndCount> selectWordCountTopN(int N);
@ConstructorArgs({ @Arg(column = "id", name = "noSuchConstructorArg"), }) @Select("select * from users ") User select();
@ConstructorArgs({ @Arg(column = "id", name = "id", javaType = Integer.class), }) @Select("select * from users ") User select();
@ConstructorArgs({ @Arg(column = "id", name = "id"), }) @Select("select * from users ") User select();