Skip to content

Commit 3d31b67

Browse files
committed
refactor: move inclusion of collection_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 e4fa25a commit 3d31b67

File tree

3 files changed

+38
-46
lines changed

3 files changed

+38
-46
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/collection_dao_queries.properties"),
4746
new ClassPathResource("sql/image_dao_queries.properties"),
4847
new ClassPathResource("sql/user_dao_queries.properties"),
4948
new ClassPathResource("sql/users_activation_dao_queries.properties"),

src/main/java/ru/mystamps/web/feature/collection/CollectionConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.springframework.context.MessageSource;
2323
import org.springframework.context.annotation.Bean;
2424
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.context.annotation.PropertySource;
26+
import org.springframework.core.env.Environment;
2527
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2628
import ru.mystamps.web.feature.category.CategoryService;
2729
import ru.mystamps.web.feature.country.CountryService;
@@ -56,9 +58,11 @@ public CollectionController collectionController() {
5658
}
5759

5860
@RequiredArgsConstructor
61+
@PropertySource("classpath:sql/collection_dao_queries.properties")
5962
public static class Services {
6063

6164
private final NamedParameterJdbcTemplate jdbcTemplate;
65+
private final Environment env;
6266

6367
@Bean
6468
public CollectionService collectionService(CollectionDao collectionDao) {
@@ -70,7 +74,7 @@ public CollectionService collectionService(CollectionDao collectionDao) {
7074

7175
@Bean
7276
public CollectionDao collectionDao() {
73-
return new JdbcCollectionDao(jdbcTemplate);
77+
return new JdbcCollectionDao(env, jdbcTemplate);
7478
}
7579

7680
}

src/main/java/ru/mystamps/web/feature/collection/JdbcCollectionDao.java

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
*/
1818
package ru.mystamps.web.feature.collection;
1919

20-
import lombok.RequiredArgsConstructor;
2120
import org.apache.commons.lang3.Validate;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
24-
import org.springframework.beans.factory.annotation.Value;
23+
import org.springframework.core.env.Environment;
2524
import org.springframework.dao.EmptyResultDataAccessException;
2625
import org.springframework.jdbc.core.ResultSetExtractor;
2726
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
@@ -38,7 +37,6 @@
3837
import java.util.List;
3938
import java.util.Map;
4039

41-
@RequiredArgsConstructor
4240
@SuppressWarnings({ "PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods" })
4341
public class JdbcCollectionDao implements CollectionDao {
4442
private static final Logger LOG = LoggerFactory.getLogger(JdbcCollectionDao.class);
@@ -47,48 +45,39 @@ public class JdbcCollectionDao implements CollectionDao {
4745
new MapIntegerIntegerResultSetExtractor("id", "number_of_stamps");
4846

4947
private final NamedParameterJdbcTemplate jdbcTemplate;
48+
private final String findLastCreatedCollectionsSql;
49+
private final String findSeriesByCollectionIdSql;
50+
private final String findSeriesWithPricesBySlugSql;
51+
private final String countCollectionsOfUsersSql;
52+
private final String countUpdatedSinceSql;
53+
private final String countSeriesOfCollectionSql;
54+
private final String countStampsOfCollectionSql;
55+
private final String addCollectionSql;
56+
private final String markAsModifiedSql;
57+
private final String isSeriesInUserCollectionSql;
58+
private final String findSeriesInstancesSql;
59+
private final String addSeriesToCollectionSql;
60+
private final String removeSeriesInstanceSql;
61+
private final String findCollectionInfoBySlugSql;
5062

51-
@Value("${collection.find_last_created}")
52-
private String findLastCreatedCollectionsSql;
53-
54-
@Value("${collection.find_series_by_collection_id}")
55-
private String findSeriesByCollectionIdSql;
56-
57-
@Value("${collection.find_series_with_prices_by_slug}")
58-
private String findSeriesWithPricesBySlugSql;
59-
60-
@Value("${collection.count_collections_of_users}")
61-
private String countCollectionsOfUsersSql;
62-
63-
@Value("${collection.count_updated_since}")
64-
private String countUpdatedSinceSql;
65-
66-
@Value("${collection.count_series_of_collection}")
67-
private String countSeriesOfCollectionSql;
68-
69-
@Value("${collection.count_stamps_of_collection}")
70-
private String countStampsOfCollectionSql;
71-
72-
@Value("${collection.create}")
73-
private String addCollectionSql;
74-
75-
@Value("${collection.mark_as_modified}")
76-
private String markAsModifiedSql;
77-
78-
@Value("${collection.is_series_in_collection}")
79-
private String isSeriesInUserCollectionSql;
80-
81-
@Value("${collection.find_series_instances}")
82-
private String findSeriesInstancesSql;
83-
84-
@Value("${collection.add_series_to_collection}")
85-
private String addSeriesToCollectionSql;
86-
87-
@Value("${collection.remove_series_instance_from_collection}")
88-
private String removeSeriesInstanceSql;
89-
90-
@Value("${collection.find_info_by_slug}")
91-
private String findCollectionInfoBySlugSql;
63+
@SuppressWarnings("checkstyle:linelength")
64+
public JdbcCollectionDao(Environment env,NamedParameterJdbcTemplate jdbcTemplate) {
65+
this.jdbcTemplate = jdbcTemplate;
66+
this.findLastCreatedCollectionsSql = env.getRequiredProperty("collection.find_last_created");
67+
this.findSeriesByCollectionIdSql = env.getRequiredProperty("collection.find_series_by_collection_id");
68+
this.findSeriesWithPricesBySlugSql = env.getRequiredProperty("collection.find_series_with_prices_by_slug");
69+
this.countCollectionsOfUsersSql = env.getRequiredProperty("collection.count_collections_of_users");
70+
this.countUpdatedSinceSql = env.getRequiredProperty("collection.count_updated_since");
71+
this.countSeriesOfCollectionSql = env.getRequiredProperty("collection.count_series_of_collection");
72+
this.countStampsOfCollectionSql = env.getRequiredProperty("collection.count_stamps_of_collection");
73+
this.addCollectionSql = env.getRequiredProperty("collection.create");
74+
this.markAsModifiedSql = env.getRequiredProperty("collection.mark_as_modified");
75+
this.isSeriesInUserCollectionSql = env.getRequiredProperty("collection.is_series_in_collection");
76+
this.findSeriesInstancesSql = env.getRequiredProperty("collection.find_series_instances");
77+
this.addSeriesToCollectionSql = env.getRequiredProperty("collection.add_series_to_collection");
78+
this.removeSeriesInstanceSql = env.getRequiredProperty("collection.remove_series_instance_from_collection");
79+
this.findCollectionInfoBySlugSql = env.getRequiredProperty("collection.find_info_by_slug");
80+
}
9281

9382
@Override
9483
public List<LinkEntityDto> findLastCreated(int quantity) {

0 commit comments

Comments
 (0)