diff options
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick')
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 7a02e8ced..67ddf7138 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 fb9ef1679..3d0c9ba82 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 0cbaec00e..1921354a5 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 b81ef5789..0ebd28388 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 fe7165b38..6118ac3d8 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 8b7ba42e7..fcb8a6f35 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 b6ee13271..53d1eb424 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 85343a7c8..878d10d56 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 0b6036936..19ab08aa2 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 d7ac6c84f..9dd417212 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 2540037a4..0f155b399 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 8e941531a..9af85f0c1 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 8adab346d..770819ec9 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) { |