Skip to content

Commit 5d486a3

Browse files
committed
refactor: move inclusion of transaction_participants_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 a3d9bca commit 5d486a3

File tree

3 files changed

+25
-39
lines changed

3 files changed

+25
-39
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
*/
1818
package ru.mystamps.web.config;
1919

20-
import org.springframework.context.annotation.Bean;
2120
import org.springframework.context.annotation.Configuration;
2221
import org.springframework.context.annotation.Import;
23-
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
24-
import org.springframework.core.io.ClassPathResource;
2522
import org.springframework.transaction.annotation.EnableTransactionManagement;
2623
import ru.mystamps.web.support.spring.security.SecurityConfig;
2724
import ru.mystamps.web.support.togglz.TogglzConfig;
@@ -37,15 +34,4 @@
3734
@EnableTransactionManagement
3835
@SuppressWarnings({ "checkstyle:hideutilityclassconstructor", "PMD.UseUtilityClass" })
3936
public class ApplicationContext {
40-
41-
@Bean
42-
public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer() {
43-
PropertySourcesPlaceholderConfigurer configurer =
44-
new PropertySourcesPlaceholderConfigurer();
45-
configurer.setLocations(
46-
new ClassPathResource("sql/transaction_participants_dao_queries.properties")
47-
);
48-
return configurer;
49-
}
50-
5137
}

src/main/java/ru/mystamps/web/feature/participant/JdbcParticipantDao.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
*/
1818
package ru.mystamps.web.feature.participant;
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;
@@ -35,31 +34,28 @@
3534

3635
// The String literal "name" appears 4 times in this file
3736
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
38-
@RequiredArgsConstructor
3937
public class JdbcParticipantDao implements ParticipantDao {
4038

4139
private final NamedParameterJdbcTemplate jdbcTemplate;
42-
43-
@Value("${transaction_participant.create}")
44-
private String addParticipantSql;
45-
46-
@Value("${transaction_participant.find_buyers_with_parent_names}")
47-
private String findBuyersWithParentNamesSql;
48-
49-
@Value("${transaction_participant.find_sellers_with_parent_names}")
50-
private String findSellersWithParentNamesSql;
51-
52-
@Value("${transaction_participant.find_seller_id_by_name}")
53-
private String findSellerIdByNameSql;
54-
55-
@Value("${transaction_participant.find_seller_id_by_name_and_url}")
56-
private String findSellerIdByNameAndUrlSql;
57-
58-
@Value("${transaction_participant_group.find_all}")
59-
private String findAllGroupsSql;
60-
61-
@Value("${transaction_participant_group.find_id_by_name}")
62-
private String findGroupIdByNameSql;
40+
private final String addParticipantSql;
41+
private final String findBuyersWithParentNamesSql;
42+
private final String findSellersWithParentNamesSql;
43+
private final String findSellerIdByNameSql;
44+
private final String findSellerIdByNameAndUrlSql;
45+
private final String findAllGroupsSql;
46+
private final String findGroupIdByNameSql;
47+
48+
@SuppressWarnings("checkstyle:linelength")
49+
public JdbcParticipantDao(Environment env, NamedParameterJdbcTemplate jdbcTemplate) {
50+
this.jdbcTemplate = jdbcTemplate;
51+
this.addParticipantSql = env.getRequiredProperty("transaction_participant.create");
52+
this.findBuyersWithParentNamesSql = env.getRequiredProperty("transaction_participant.find_buyers_with_parent_names");
53+
this.findSellersWithParentNamesSql = env.getRequiredProperty("transaction_participant.find_sellers_with_parent_names");
54+
this.findSellerIdByNameSql = env.getRequiredProperty("transaction_participant.find_seller_id_by_name");
55+
this.findSellerIdByNameAndUrlSql = env.getRequiredProperty("transaction_participant.find_seller_id_by_name_and_url");
56+
this.findAllGroupsSql = env.getRequiredProperty("transaction_participant_group.find_all");
57+
this.findGroupIdByNameSql = env.getRequiredProperty("transaction_participant_group.find_id_by_name");
58+
}
6359

6460
@Override
6561
public Integer add(AddParticipantDbDto participant) {

src/main/java/ru/mystamps/web/feature/participant/ParticipantConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.slf4j.LoggerFactory;
2222
import org.springframework.context.annotation.Bean;
2323
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.context.annotation.PropertySource;
25+
import org.springframework.core.env.Environment;
2426
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2527

2628
/**
@@ -45,8 +47,10 @@ public ParticipantController participantController() {
4547
}
4648

4749
@RequiredArgsConstructor
50+
@PropertySource("classpath:sql/transaction_participants_dao_queries.properties")
4851
public static class Services {
4952

53+
private final Environment env;
5054
private final NamedParameterJdbcTemplate jdbcTemplate;
5155

5256
@Bean
@@ -59,7 +63,7 @@ public ParticipantService participantService(ParticipantDao participantDao) {
5963

6064
@Bean
6165
public ParticipantDao participantDao() {
62-
return new JdbcParticipantDao(jdbcTemplate);
66+
return new JdbcParticipantDao(env, jdbcTemplate);
6367
}
6468

6569
}

0 commit comments

Comments
 (0)