Skip to content

Commit a3d9bca

Browse files
committed
refactor: move inclusion of series_dao_queries.properties to the appropriate package config
We also switched to using Environment.getRequiredProperty() because @value doesn't work without PropertySourcesPlaceholderConfigurer bean (that we are going to remove soon). Relate to #927
1 parent eae504e commit a3d9bca

File tree

4 files changed

+63
-83
lines changed

4 files changed

+63
-83
lines changed

src/main/java/ru/mystamps/web/config/ApplicationContext.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholder
4343
PropertySourcesPlaceholderConfigurer configurer =
4444
new PropertySourcesPlaceholderConfigurer();
4545
configurer.setLocations(
46-
new ClassPathResource("sql/series_dao_queries.properties"),
4746
new ClassPathResource("sql/transaction_participants_dao_queries.properties")
4847
);
4948
return configurer;

src/main/java/ru/mystamps/web/feature/series/JdbcSeriesDao.java

Lines changed: 54 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
*/
1818
package ru.mystamps.web.feature.series;
1919

20-
import lombok.RequiredArgsConstructor;
2120
import org.apache.commons.lang3.Validate;
22-
import org.springframework.beans.factory.annotation.Value;
21+
import org.springframework.core.env.Environment;
2322
import org.springframework.dao.EmptyResultDataAccessException;
2423
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
2524
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@@ -39,82 +38,62 @@
3938
"PMD.TooManyMethods",
4039
"PMD.TooManyFields"
4140
})
42-
@RequiredArgsConstructor
4341
public class JdbcSeriesDao implements SeriesDao {
4442

4543
private final NamedParameterJdbcTemplate jdbcTemplate;
46-
47-
@Value("${series.create}")
48-
private String createSeriesSql;
49-
50-
@Value("${series.add_comment}")
51-
private String addCommentSql;
52-
53-
@Value("${series.add_release_year}")
54-
private String addReleaseYearSql;
55-
56-
@Value("${series.mark_as_modified}")
57-
private String markAsModifiedSql;
58-
59-
@Value("${series.find_all_for_sitemap}")
60-
private String findAllForSitemapSql;
61-
62-
@Value("${series.find_similar_series}")
63-
private String findSimilarSeriesSql;
64-
65-
@Value("${series.find_last_added}")
66-
private String findLastAddedSeriesSql;
67-
68-
@Value("${series.find_full_info_by_id}")
69-
private String findFullInfoByIdSql;
70-
71-
@Value("${series.find_by_ids}")
72-
private String findByIdsSql;
73-
74-
@Value("${series.find_by_category_slug}")
75-
private String findByCategorySlugSql;
76-
77-
@Value("${series.find_by_country_slug}")
78-
private String findByCountrySlugSql;
79-
80-
@Value("${series.count_all_series}")
81-
private String countAllSql;
82-
83-
@Value("${series.count_all_stamps}")
84-
private String countAllStampsSql;
85-
86-
@Value("${series.count_series_by_id}")
87-
private String countSeriesByIdSql;
88-
89-
@Value("${series.count_series_added_since}")
90-
private String countSeriesAddedSinceSql;
91-
92-
@Value("${series.count_series_updated_since}")
93-
private String countSeriesUpdatedSinceSql;
94-
95-
@Value("${series.find_quantity_by_id}")
96-
private String findQuantityByIdSql;
97-
98-
@Value("${series.add_similar_series}")
99-
private String addSimilarSeriesSql;
100-
101-
@Value("${series.add_michel_price}")
102-
private String addMichelPriceSql;
103-
104-
@Value("${series.add_scott_price}")
105-
private String addScottPriceSql;
106-
107-
@Value("${series.add_yvert_price}")
108-
private String addYvertPriceSql;
109-
110-
@Value("${series.add_gibbons_price}")
111-
private String addGibbonsPriceSql;
112-
113-
@Value("${series.add_solovyov_price}")
114-
private String addSolovyovPriceSql;
115-
116-
@Value("${series.add_zagorski_price}")
117-
private String addZagorskiPriceSql;
44+
private final String createSeriesSql;
45+
private final String addCommentSql;
46+
private final String addReleaseYearSql;
47+
private final String markAsModifiedSql;
48+
private final String findAllForSitemapSql;
49+
private final String findSimilarSeriesSql;
50+
private final String findLastAddedSeriesSql;
51+
private final String findFullInfoByIdSql;
52+
private final String findByIdsSql;
53+
private final String findByCategorySlugSql;
54+
private final String findByCountrySlugSql;
55+
private final String countAllSql;
56+
private final String countAllStampsSql;
57+
private final String countSeriesByIdSql;
58+
private final String countSeriesAddedSinceSql;
59+
private final String countSeriesUpdatedSinceSql;
60+
private final String findQuantityByIdSql;
61+
private final String addSimilarSeriesSql;
62+
private final String addMichelPriceSql;
63+
private final String addScottPriceSql;
64+
private final String addYvertPriceSql;
65+
private final String addGibbonsPriceSql;
66+
private final String addSolovyovPriceSql;
67+
private final String addZagorskiPriceSql;
68+
69+
@SuppressWarnings("checkstyle:linelength")
70+
public JdbcSeriesDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
71+
this.jdbcTemplate = jdbcTemplate;
72+
this.createSeriesSql = env.getRequiredProperty("series.create");
73+
this.addCommentSql = env.getRequiredProperty("series.add_comment");
74+
this.addReleaseYearSql = env.getRequiredProperty("series.add_release_year");
75+
this.markAsModifiedSql = env.getRequiredProperty("series.mark_as_modified");
76+
this.findAllForSitemapSql = env.getRequiredProperty("series.find_all_for_sitemap");
77+
this.findSimilarSeriesSql = env.getRequiredProperty("series.find_similar_series");
78+
this.findLastAddedSeriesSql = env.getRequiredProperty("series.find_last_added");
79+
this.findFullInfoByIdSql = env.getRequiredProperty("series.find_full_info_by_id");
80+
this.findByIdsSql = env.getRequiredProperty("series.find_by_ids");
81+
this.findByCategorySlugSql = env.getRequiredProperty("series.find_by_category_slug");
82+
this.findByCountrySlugSql = env.getRequiredProperty("series.find_by_country_slug");
83+
this.countAllSql = env.getRequiredProperty("series.count_all_series");
84+
this.countAllStampsSql = env.getRequiredProperty("series.count_all_stamps");
85+
this.countSeriesByIdSql = env.getRequiredProperty("series.count_series_by_id");
86+
this.countSeriesAddedSinceSql = env.getRequiredProperty("series.count_series_added_since");
87+
this.countSeriesUpdatedSinceSql = env.getRequiredProperty("series.count_series_updated_since");
88+
this.findQuantityByIdSql = env.getRequiredProperty("series.find_quantity_by_id");
89+
this.addSimilarSeriesSql = env.getRequiredProperty("series.add_similar_series");
90+
this.addMichelPriceSql = env.getRequiredProperty("series.add_michel_price");
91+
this.addScottPriceSql = env.getRequiredProperty("series.add_scott_price");
92+
this.addYvertPriceSql = env.getRequiredProperty("series.add_yvert_price");
93+
this.addGibbonsPriceSql = env.getRequiredProperty("series.add_gibbons_price");
94+
this.addSolovyovPriceSql = env.getRequiredProperty("series.add_solovyov_price");
95+
this.addZagorskiPriceSql = env.getRequiredProperty("series.add_zagorski_price");
96+
}
11897

11998
@Override
12099
public Integer add(AddSeriesDbDto series) {

src/main/java/ru/mystamps/web/feature/series/JdbcSeriesImageDao.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@
1717
*/
1818
package ru.mystamps.web.feature.series;
1919

20-
import lombok.RequiredArgsConstructor;
2120
import org.apache.commons.lang3.Validate;
22-
import org.springframework.beans.factory.annotation.Value;
21+
import org.springframework.core.env.Environment;
2322
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2423

2524
import java.util.HashMap;
2625
import java.util.Map;
2726

28-
@RequiredArgsConstructor
2927
public class JdbcSeriesImageDao implements SeriesImageDao {
3028

3129
private final NamedParameterJdbcTemplate jdbcTemplate;
30+
private final String hideImageSql;
3231

33-
@Value("${series_images.mark_as_hidden}")
34-
private String hideImageSql;
32+
public JdbcSeriesImageDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
33+
this.jdbcTemplate = jdbcTemplate;
34+
this.hideImageSql = env.getRequiredProperty("series_images.mark_as_hidden");
35+
}
3536

3637
@Override
3738
public void hideImage(Integer seriesId, Integer imageId) {

src/main/java/ru/mystamps/web/feature/series/SeriesConfig.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public StampsCatalogService zagorskiCatalogService() {
174174

175175
@RequiredArgsConstructor
176176
@PropertySource({
177+
"classpath:sql/series_dao_queries.properties",
177178
"classpath:sql/series_image_dao_queries.properties",
178179
"classpath:/sql/stamps_catalog_dao_queries.properties"
179180
})
@@ -184,12 +185,12 @@ public StampsCatalogService zagorskiCatalogService() {
184185

185186
@Bean
186187
public SeriesDao seriesDao() {
187-
return new JdbcSeriesDao(jdbcTemplate);
188+
return new JdbcSeriesDao(env, jdbcTemplate);
188189
}
189190

190191
@Bean
191192
public SeriesImageDao seriesImageDao() {
192-
return new JdbcSeriesImageDao(jdbcTemplate);
193+
return new JdbcSeriesImageDao(env, jdbcTemplate);
193194
}
194195

195196
@Bean

0 commit comments

Comments
 (0)