fix #123 allow to specify extra annotations on repositories/methods
[yosql.git] / yosql-codegen / src / main / java / wtf / metio / yosql / codegen / files / DefaultSqlConfigurationFactory.java
blob8fcf45547fd98ac40c5bbfc93a0f08a95765311c
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 */
7 package wtf.metio.yosql.codegen.files;
9 import org.slf4j.cal10n.LocLogger;
10 import wtf.metio.yosql.internals.jdk.FileNames;
11 import wtf.metio.yosql.models.immutables.SqlConfiguration;
13 import java.nio.file.Path;
14 import java.util.List;
15 import java.util.Map;
17 /**
18 * Default implementation of the {@link SqlConfigurationFactory}.
20 public final class DefaultSqlConfigurationFactory implements SqlConfigurationFactory {
22 private final LocLogger logger;
23 private final SqlConfigurationParser configParser;
24 private final MethodSettingsConfigurer methodSettings;
25 private final MethodNameConfigurer methodNames;
26 private final MethodNameValidator methodNameValidator;
27 private final MethodApiConfigurer methodApis;
28 private final MethodParameterConfigurer methodParameters;
29 private final MethodResultRowConverterConfigurer methodConverter;
30 private final RepositoryNameConfigurer repositoryName;
32 /**
33 * @param logger The logger to use.
34 * @param configParser The configuration parser to use.
35 * @param methodSettings How method settings are configured.
36 * @param methodNames How method names are configured.
37 * @param methodNameValidator Validator for method names.
38 * @param methodApis How method APIs are configured.
39 * @param methodParameters How method parameters are configured.
40 * @param methodConverter How method converters are configured.
41 * @param repositoryName How repository names are configured.
43 public DefaultSqlConfigurationFactory(
44 final LocLogger logger,
45 final SqlConfigurationParser configParser,
46 final MethodSettingsConfigurer methodSettings,
47 final MethodNameConfigurer methodNames,
48 final MethodNameValidator methodNameValidator,
49 final MethodApiConfigurer methodApis,
50 final MethodParameterConfigurer methodParameters,
51 final MethodResultRowConverterConfigurer methodConverter,
52 final RepositoryNameConfigurer repositoryName) {
53 this.methodParameters = methodParameters;
54 this.logger = logger;
55 this.configParser = configParser;
56 this.methodSettings = methodSettings;
57 this.methodNames = methodNames;
58 this.methodNameValidator = methodNameValidator;
59 this.methodApis = methodApis;
60 this.methodConverter = methodConverter;
61 this.repositoryName = repositoryName;
64 /**
65 * @param source The source file of the statement.
66 * @param yaml The YAML front matter of the statement.
67 * @param parameterIndices The parameter indices (if any) of the statement.
68 * @param statementInFile The counter for statements with the same name in the same source file.
69 * @return The resulting configuration.
71 @Override
72 public SqlConfiguration createConfiguration(
73 final Path source,
74 final String yaml,
75 final Map<String, List<Integer>> parameterIndices,
76 final int statementInFile) {
77 var configuration = configParser.parseConfig(yaml);
78 logger.debug("SQL configuration: {}", configuration);
79 configuration = methodNames.configureNames(configuration, FileNames.withoutExtension(source), statementInFile);
80 configuration = methodSettings.configureSettings(configuration);
81 configuration = methodApis.configureApis(configuration);
82 configuration = repositoryName.configureNames(configuration, source);
83 configuration = methodParameters.configureParameters(configuration, source, parameterIndices);
84 configuration = methodConverter.configureResultRowConverter(configuration);
85 logger.debug("SQL configuration: {}", configuration);
86 methodNameValidator.validateNames(configuration, source);
87 return configuration;