|
17 | 17 | */
|
18 | 18 | package ru.mystamps.web.feature.country;
|
19 | 19 |
|
20 |
| -import lombok.RequiredArgsConstructor; |
21 | 20 | import org.apache.commons.lang3.Validate;
|
22 |
| -import org.springframework.beans.factory.annotation.Value; |
| 21 | +import org.springframework.core.env.Environment; |
23 | 22 | import org.springframework.dao.EmptyResultDataAccessException;
|
24 | 23 | import org.springframework.jdbc.core.ResultSetExtractor;
|
25 | 24 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
37 | 36 | import java.util.List;
|
38 | 37 | import java.util.Map;
|
39 | 38 |
|
40 |
| -@RequiredArgsConstructor |
41 | 39 | @SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods", "PMD.TooManyFields" })
|
42 | 40 | public class JdbcCountryDao implements CountryDao {
|
43 | 41 |
|
44 | 42 | private static final ResultSetExtractor<Map<String, Integer>> NAME_COUNTER_EXTRACTOR =
|
45 | 43 | new MapStringIntegerResultSetExtractor("name", "counter");
|
46 | 44 |
|
47 | 45 | private final NamedParameterJdbcTemplate jdbcTemplate;
|
48 |
| - |
49 |
| - @Value("${country.create}") |
50 |
| - private String addCountrySql; |
51 |
| - |
52 |
| - @Value("${country.count_all_countries}") |
53 |
| - private String countAllSql; |
54 |
| - |
55 |
| - @Value("${country.count_countries_by_slug}") |
56 |
| - private String countBySlugSql; |
57 |
| - |
58 |
| - @Value("${country.count_countries_by_name}") |
59 |
| - private String countByNameSql; |
60 |
| - |
61 |
| - @Value("${country.count_countries_by_name_ru}") |
62 |
| - private String countByNameRuSql; |
63 |
| - |
64 |
| - @Value("${country.count_countries_of_collection}") |
65 |
| - private String countCountriesOfCollectionSql; |
66 |
| - |
67 |
| - @Value("${country.count_countries_added_since}") |
68 |
| - private String countCountriesAddedSinceSql; |
69 |
| - |
70 |
| - @Value("${country.count_untranslated_names_since}") |
71 |
| - private String countUntranslatedNamesSinceSql; |
72 |
| - |
73 |
| - @Value("${country.count_stamps_by_countries}") |
74 |
| - private String countStampsByCountriesSql; |
75 |
| - |
76 |
| - @Value("${country.find_ids_by_names}") |
77 |
| - private String findIdsByNamesSql; |
78 |
| - |
79 |
| - @Value("${country.find_ids_by_name_pattern}") |
80 |
| - private String findIdsByNamePatternSql; |
81 |
| - |
82 |
| - @Value("${country.find_all_countries_names_with_slug}") |
83 |
| - private String findCountriesNamesWithSlugSql; |
84 |
| - |
85 |
| - @Value("${country.find_country_link_info_by_slug}") |
86 |
| - private String findCountryLinkEntityBySlugSql; |
87 |
| - |
| 46 | + private final String addCountrySql; |
| 47 | + private final String countAllSql; |
| 48 | + private final String countBySlugSql; |
| 49 | + private final String countByNameSql; |
| 50 | + private final String countByNameRuSql; |
| 51 | + private final String countCountriesOfCollectionSql; |
| 52 | + private final String countCountriesAddedSinceSql; |
| 53 | + private final String countUntranslatedNamesSinceSql; |
| 54 | + private final String countStampsByCountriesSql; |
| 55 | + private final String findIdsByNamesSql; |
| 56 | + private final String findIdsByNamePatternSql; |
| 57 | + private final String findCountriesNamesWithSlugSql; |
| 58 | + private final String findCountryLinkEntityBySlugSql; |
88 | 59 | @SuppressWarnings("PMD.LongVariable")
|
89 |
| - @Value("${country.find_from_last_created_series_by_user}") |
90 |
| - private String findFromLastCreatedSeriesByUserSql; |
91 |
| - |
| 60 | + private final String findFromLastCreatedSeriesByUserSql; |
92 | 61 | @SuppressWarnings("PMD.LongVariable")
|
93 |
| - @Value("${country.find_popular_country_from_user_collection}") |
94 |
| - private String findPopularCountryInCollectionSql; |
95 |
| - |
| 62 | + private final String findPopularCountryInCollectionSql; |
96 | 63 | @SuppressWarnings("PMD.LongVariable")
|
97 |
| - @Value("${country.find_last_country_created_by_user}") |
98 |
| - private String findLastCountryCreatedByUserSql; |
| 64 | + private final String findLastCountryCreatedByUserSql; |
| 65 | + |
| 66 | + @SuppressWarnings("checkstyle:linelength") |
| 67 | + public JdbcCountryDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) { |
| 68 | + this.jdbcTemplate = jdbcTemplate; |
| 69 | + this.addCountrySql = env.getRequiredProperty("country.create"); |
| 70 | + this.countAllSql = env.getRequiredProperty("country.count_all_countries"); |
| 71 | + this.countBySlugSql = env.getRequiredProperty("country.count_countries_by_slug"); |
| 72 | + this.countByNameSql = env.getRequiredProperty("country.count_countries_by_name"); |
| 73 | + this.countByNameRuSql = env.getRequiredProperty("country.count_countries_by_name_ru"); |
| 74 | + this.countCountriesOfCollectionSql = env.getRequiredProperty("country.count_countries_of_collection"); |
| 75 | + this.countCountriesAddedSinceSql = env.getRequiredProperty("country.count_countries_added_since"); |
| 76 | + this.countUntranslatedNamesSinceSql = env.getRequiredProperty("country.count_untranslated_names_since"); |
| 77 | + this.countStampsByCountriesSql = env.getRequiredProperty("country.count_stamps_by_countries"); |
| 78 | + this.findIdsByNamesSql = env.getRequiredProperty("country.find_ids_by_names"); |
| 79 | + this.findIdsByNamePatternSql = env.getRequiredProperty("country.find_ids_by_name_pattern"); |
| 80 | + this.findCountriesNamesWithSlugSql = env.getRequiredProperty("country.find_all_countries_names_with_slug"); |
| 81 | + this.findCountryLinkEntityBySlugSql = env.getRequiredProperty("country.find_country_link_info_by_slug"); |
| 82 | + this.findFromLastCreatedSeriesByUserSql = env.getRequiredProperty("country.find_from_last_created_series_by_user"); |
| 83 | + this.findPopularCountryInCollectionSql = env.getRequiredProperty("country.find_popular_country_from_user_collection"); |
| 84 | + this.findLastCountryCreatedByUserSql = env.getRequiredProperty("country.find_last_country_created_by_user"); |
| 85 | + } |
99 | 86 |
|
100 | 87 | @Override
|
101 | 88 | public Integer add(AddCountryDbDto country) {
|
|
0 commit comments