|
17 | 17 | */
|
18 | 18 | package ru.mystamps.web.feature.category;
|
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;
|
|
38 | 37 | import java.util.List;
|
39 | 38 | import java.util.Map;
|
40 | 39 |
|
41 |
| -@RequiredArgsConstructor |
42 | 40 | @SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods", "PMD.TooManyFields" })
|
43 | 41 | public class JdbcCategoryDao implements CategoryDao {
|
44 | 42 |
|
45 | 43 | private static final ResultSetExtractor<Map<String, Integer>> NAME_COUNTER_EXTRACTOR =
|
46 | 44 | new MapStringIntegerResultSetExtractor("name", "counter");
|
47 | 45 |
|
48 | 46 | private final NamedParameterJdbcTemplate jdbcTemplate;
|
49 |
| - |
50 |
| - @Value("${category.create}") |
51 |
| - private String addCategorySql; |
52 |
| - |
53 |
| - @Value("${category.count_all_categories}") |
54 |
| - private String countAllSql; |
55 |
| - |
56 |
| - @Value("${category.count_categories_by_slug}") |
57 |
| - private String countBySlugSql; |
58 |
| - |
59 |
| - @Value("${category.count_categories_by_name}") |
60 |
| - private String countByNameSql; |
61 |
| - |
62 |
| - @Value("${category.count_categories_by_name_ru}") |
63 |
| - private String countByNameRuSql; |
64 |
| - |
65 |
| - @Value("${category.count_categories_of_collection}") |
66 |
| - private String countCategoriesOfCollectionSql; |
67 |
| - |
68 |
| - @Value("${category.count_categories_added_since}") |
69 |
| - private String countCategoriesAddedSinceSql; |
70 |
| - |
71 |
| - @Value("${category.count_untranslated_names_since}") |
72 |
| - private String countUntranslatedNamesSinceSql; |
73 |
| - |
74 |
| - @Value("${category.count_stamps_by_categories}") |
75 |
| - private String countStampsByCategoriesSql; |
76 |
| - |
77 |
| - @Value("${category.find_ids_by_names}") |
78 |
| - private String findIdsByNamesSql; |
79 |
| - |
80 |
| - @Value("${category.find_ids_by_name_pattern}") |
81 |
| - private String findIdsByNamePatternSql; |
82 |
| - |
83 |
| - @Value("${category.find_all_categories_names_with_slug}") |
84 |
| - private String findCategoriesNamesWithSlugSql; |
85 |
| - |
86 |
| - @Value("${category.find_category_link_info_by_slug}") |
87 |
| - private String findLinkEntityBySlugSql; |
88 |
| - |
| 47 | + private final String addCategorySql; |
| 48 | + private final String countAllSql; |
| 49 | + private final String countBySlugSql; |
| 50 | + private final String countByNameSql; |
| 51 | + private final String countByNameRuSql; |
| 52 | + private final String countCategoriesOfCollectionSql; |
| 53 | + private final String countCategoriesAddedSinceSql; |
| 54 | + private final String countUntranslatedNamesSinceSql; |
| 55 | + private final String countStampsByCategoriesSql; |
| 56 | + private final String findIdsByNamesSql; |
| 57 | + private final String findIdsByNamePatternSql; |
| 58 | + private final String findCategoriesNamesWithSlugSql; |
| 59 | + private final String findLinkEntityBySlugSql; |
89 | 60 | @SuppressWarnings("PMD.LongVariable")
|
90 |
| - @Value("${category.find_categories_with_parent_names}") |
91 |
| - private String findCategoriesWithParentNamesSql; |
92 |
| - |
| 61 | + private final String findCategoriesWithParentNamesSql; |
93 | 62 | @SuppressWarnings("PMD.LongVariable")
|
94 |
| - @Value("${category.find_from_last_created_series_by_user}") |
95 |
| - private String findFromLastCreatedSeriesByUserSql; |
| 63 | + private final String findFromLastCreatedSeriesByUserSql; |
| 64 | + |
| 65 | + @SuppressWarnings("checkstyle:linelength") |
| 66 | + public JdbcCategoryDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) { |
| 67 | + this.jdbcTemplate = jdbcTemplate; |
| 68 | + this.addCategorySql = env.getRequiredProperty("category.create"); |
| 69 | + this.countAllSql = env.getRequiredProperty("category.count_all_categories"); |
| 70 | + this.countBySlugSql = env.getRequiredProperty("category.count_categories_by_slug"); |
| 71 | + this.countByNameSql = env.getRequiredProperty("category.count_categories_by_name"); |
| 72 | + this.countByNameRuSql = env.getRequiredProperty("category.count_categories_by_name_ru"); |
| 73 | + this.countCategoriesOfCollectionSql = env.getRequiredProperty("category.count_categories_of_collection"); |
| 74 | + this.countCategoriesAddedSinceSql = env.getRequiredProperty("category.count_categories_added_since"); |
| 75 | + this.countUntranslatedNamesSinceSql = env.getRequiredProperty("category.count_untranslated_names_since"); |
| 76 | + this.countStampsByCategoriesSql = env.getRequiredProperty("category.count_stamps_by_categories"); |
| 77 | + this.findIdsByNamesSql = env.getRequiredProperty("category.find_ids_by_names"); |
| 78 | + this.findIdsByNamePatternSql = env.getRequiredProperty("category.find_ids_by_name_pattern"); |
| 79 | + this.findCategoriesNamesWithSlugSql = env.getRequiredProperty("category.find_all_categories_names_with_slug"); |
| 80 | + this.findLinkEntityBySlugSql = env.getRequiredProperty("category.find_category_link_info_by_slug"); |
| 81 | + this.findCategoriesWithParentNamesSql = env.getRequiredProperty("category.find_categories_with_parent_names"); |
| 82 | + this.findFromLastCreatedSeriesByUserSql = env.getRequiredProperty("category.find_from_last_created_series_by_user"); |
| 83 | + } |
96 | 84 |
|
97 | 85 | @Override
|
98 | 86 | public Integer add(AddCategoryDbDto category) {
|
|
0 commit comments