fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / main / java / wtf / metio / yosql / codegen / dao / DefaultParameterGenerator.java
blobe007591b60630bc8354da6f3e77a47630418fffc
1 /*
2 * This file is part of yosql. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at https://creativecommons.org/publicdomain/zero/1.0/. No part of yosql,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
5 * in the LICENSE file.
6 */
8 package wtf.metio.yosql.codegen.dao;
10 import com.squareup.javapoet.ArrayTypeName;
11 import com.squareup.javapoet.ParameterSpec;
12 import wtf.metio.yosql.codegen.blocks.Parameters;
13 import wtf.metio.yosql.models.configuration.SqlParameter;
15 import java.util.List;
16 import java.util.function.Function;
17 import java.util.stream.Collectors;
19 public class DefaultParameterGenerator implements ParameterGenerator {
21 private final Parameters parameters;
23 public DefaultParameterGenerator(final Parameters parameters) {
24 this.parameters = parameters;
27 @Override
28 public Iterable<ParameterSpec> asParameterSpecs(final List<SqlParameter> parameters) {
29 return asParameterSpecs(parameters, this::ofSqlParameter);
32 private ParameterSpec ofSqlParameter(final SqlParameter parameter) {
33 return parameters.parameter(parameter.typeName().orElseThrow(), parameter.name().orElseThrow());
36 @Override
37 public Iterable<ParameterSpec> asParameterSpecsForInterfaces(final List<SqlParameter> parameters) {
38 return asParameterSpecs(parameters, this::ofSqlParameterForInterfaces);
41 private ParameterSpec ofSqlParameterForInterfaces(final SqlParameter parameter) {
42 return parameters.parameterForInterfaces(parameter.typeName().orElseThrow(), parameter.name().orElseThrow());
45 @Override
46 public Iterable<ParameterSpec> asBatchParameterSpecs(List<SqlParameter> parameters) {
47 return asParameterSpecs(parameters, this::batchOfSqlParameter);
50 private ParameterSpec batchOfSqlParameter(final SqlParameter parameter) {
51 return parameters.parameter(ArrayTypeName.of(parameter.typeName().orElseThrow()), parameter.name().orElseThrow());
54 @Override
55 public Iterable<ParameterSpec> asBatchParameterSpecsForInterfaces(final List<SqlParameter> parameters) {
56 return asParameterSpecs(parameters, this::batchOfSqlParameterForInterfaces);
59 private ParameterSpec batchOfSqlParameterForInterfaces(final SqlParameter parameter) {
60 return parameters.parameterForInterfaces(ArrayTypeName.of(parameter.typeName().orElseThrow()), parameter.name().orElseThrow());
63 private static Iterable<ParameterSpec> asParameterSpecs(
64 final List<SqlParameter> parameters,
65 final Function<SqlParameter, ParameterSpec> asParameter) {
66 return parameters.stream()
67 .map(asParameter)
68 .collect(Collectors.toList());