diff options
author | Vitaly Takmazov | 2018-02-18 00:17:26 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-02-18 00:17:26 +0300 |
commit | 3e0d8bc42c4972d3ab66c5b4292e022c5e62034e (patch) | |
tree | 206fffb654d9cdd8e409ae4513c40ab0e8011cb9 /juick-server-jdbc/src/main | |
parent | f2ae5252e70355a5481e99a41ab79969e1c65502 (diff) |
server-jdbc: no need to reinvent JdbcDaoSupport
Diffstat (limited to 'juick-server-jdbc/src/main')
13 files changed, 11 insertions, 98 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java b/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java index 7a02e8ce..67ddf713 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/BaseJdbcService.java @@ -17,56 +17,20 @@ package com.juick.service; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.support.TransactionTemplate; -import org.springframework.util.Assert; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcDaoSupport; +import javax.annotation.PostConstruct; +import javax.inject.Inject; import javax.sql.DataSource; /** * Created by aalexeev on 11/13/16. */ -public abstract class BaseJdbcService { - protected final Logger logger = LoggerFactory.getLogger(getClass()); - - private final JdbcTemplate jdbcTemplate; - private final TransactionTemplate transactionTemplate; - private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; - - - protected BaseJdbcService(JdbcTemplate jdbcTemplate, PlatformTransactionManager transactionManager) { - Assert.notNull(jdbcTemplate, "JdbcTemplate must be initialized"); - - this.jdbcTemplate = jdbcTemplate; - this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); - this.transactionTemplate = (transactionManager == null) ? - null : new TransactionTemplate(transactionManager); - - } - - protected BaseJdbcService(DataSource dataSource, PlatformTransactionManager transactionManager) { - Assert.notNull(dataSource, "DataSource must be initialized"); - - this.jdbcTemplate = new JdbcTemplate(dataSource); - this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(jdbcTemplate); - this.transactionTemplate = (transactionManager == null) ? - null : new TransactionTemplate(transactionManager); - - } - - protected JdbcTemplate getJdbcTemplate() { - return jdbcTemplate; - } - - protected NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { - return namedParameterJdbcTemplate; - } - - protected TransactionTemplate getTransactionTemplate() { - return transactionTemplate; +public class BaseJdbcService extends NamedParameterJdbcDaoSupport { + @Inject + DataSource dataSource; + @PostConstruct + public void init() { + setDataSource(dataSource); } } diff --git a/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java index fb9ef167..3d0c9ba8 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/CrosspostServiceImpl.java @@ -36,11 +36,6 @@ import java.util.Optional; @Repository public class CrosspostServiceImpl extends BaseJdbcService implements CrosspostService { - @Inject - public CrosspostServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Transactional(readOnly = true) @Override public Optional<ExternalToken> getTwitterToken(final int uid) { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java index 0cbaec00..1921354a 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java @@ -33,10 +33,6 @@ import java.util.List; @Repository @Transactional public class EmailServiceImpl extends BaseJdbcService implements EmailService { - @Inject - public EmailServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } @Override public boolean verifyAddressByCode(Integer userId, String code) { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java index b81ef578..0ebd2838 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -67,11 +67,6 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Value("${img_url:https://i.juick.com/}") private String baseImagesUrl; - @Inject - public MessagesServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - private class MessageMapper implements RowMapper<Message> { @Override public Message mapRow(ResultSet rs, int rowNum) throws SQLException { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java index fe7165b3..6118ac3d 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessengerServiceImpl.java @@ -13,10 +13,6 @@ import java.util.UUID; @Repository public class MessengerServiceImpl extends BaseJdbcService implements MessengerService { - @Inject - protected MessengerServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } @Transactional(readOnly = true) @Override diff --git a/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java index 8b7ba42e..fcb8a6f3 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/PMQueriesServiceImpl.java @@ -33,11 +33,6 @@ import java.util.List; @Repository public class PMQueriesServiceImpl extends BaseJdbcService implements PMQueriesService { - @Inject - public PMQueriesServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Transactional @Override public boolean createPM(final int uidFrom, final int uid_to, final String body) { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java index b6ee1327..53d1eb42 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/PrivacyQueriesServiceImpl.java @@ -32,11 +32,6 @@ import javax.inject.Inject; @Transactional public class PrivacyQueriesServiceImpl extends BaseJdbcService implements PrivacyQueriesService { - @Inject - public PrivacyQueriesServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Override public PrivacyResult blacklistUser(final User user, final User target) { int result = getJdbcTemplate().update( diff --git a/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java index 85343a7c..878d10d5 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/PushQueriesServiceImpl.java @@ -34,11 +34,6 @@ import java.util.List; @Repository public class PushQueriesServiceImpl extends BaseJdbcService implements PushQueriesService { - @Inject - public PushQueriesServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Transactional(readOnly = true) @Override public List<String> getGCMRegID(final int uid) { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/ShowQueriesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/ShowQueriesServiceImpl.java index 0b603693..19ab08aa 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/ShowQueriesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/ShowQueriesServiceImpl.java @@ -34,11 +34,6 @@ import java.util.List; @Transactional(readOnly = true) public class ShowQueriesServiceImpl extends BaseJdbcService implements ShowQueriesService { - @Inject - public ShowQueriesServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Override public List<String> getRecommendedUsers(final User forUser) { if (forUser == null) diff --git a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java index d7ac6c84..9dd41721 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java @@ -44,10 +44,8 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip private final TagService tagService; @Inject - public SubscriptionServiceImpl(JdbcTemplate jdbcTemplate, UserService userService, + public SubscriptionServiceImpl(UserService userService, MessagesService messagesService, TagService tagService) { - super(jdbcTemplate, null); - Assert.notNull(userService, "UserService must be initialized"); this.userService = userService; diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java index 2540037a..0f155b39 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/TagServiceImpl.java @@ -59,8 +59,7 @@ public class TagServiceImpl extends BaseJdbcService implements TagService { private final MessagesService messagesService; @Inject - public TagServiceImpl(JdbcTemplate jdbcTemplate, MessagesService messagesService) { - super(jdbcTemplate, null); + public TagServiceImpl(MessagesService messagesService) { Assert.notNull(messagesService, "MessagesService must be initialized"); this.messagesService = messagesService; } diff --git a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java index 8e941531..9af85f0c 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/TelegramServiceImpl.java @@ -35,11 +35,6 @@ import java.util.stream.Collectors; @Repository public class TelegramServiceImpl extends BaseJdbcService implements TelegramService { - @Inject - public TelegramServiceImpl(JdbcTemplate jdbc) { - super(jdbc, null); - } - @Transactional @Override public boolean addChat(final Long id) { diff --git a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java index 8adab346..770819ec 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java @@ -61,11 +61,6 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { } } - @Inject - public UserServiceImpl(JdbcTemplate jdbcTemplate) { - super(jdbcTemplate, null); - } - @Transactional @Override public String getSignUpHashByJID(final String jid) { |