aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-02-17 23:53:48 +0300
committerGravatar Vitaly Takmazov2018-02-22 13:15:59 +0300
commit8799068b593b9dd40b569a520c32b7e7dd541783 (patch)
tree4688be0d41490453370135c5e009aac511f04cd9 /juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java
parent2b267c04f4c77c6fae5c591e45d987b3f4b3bab3 (diff)
run tests on h2 database
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/SubscriptionServiceImpl.java17
1 files changed, 13 insertions, 4 deletions
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 9dd41721..66b62833 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
@@ -21,6 +21,7 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.server.helpers.NotifyOpts;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.dao.DuplicateKeyException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
@@ -147,8 +148,12 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
@Transactional
@Override
public boolean subscribeMessage(final int mid, final int vuid) {
- return getJdbcTemplate().update(
- "INSERT IGNORE INTO subscr_messages(suser_id, message_id) VALUES (?, ?)", vuid, mid) == 1;
+ try {
+ return getJdbcTemplate().update(
+ "INSERT INTO subscr_messages(suser_id, message_id) VALUES (?, ?)", vuid, mid) == 1;
+ } catch (DuplicateKeyException e) {
+ return true;
+ }
}
@Transactional
@@ -161,8 +166,12 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
@Transactional
@Override
public boolean subscribeUser(final User user, final User toUser) {
- return getJdbcTemplate().update(
- "INSERT IGNORE INTO subscr_users(user_id,suser_id) VALUES (?,?)", toUser.getUid(), user.getUid()) == 1;
+ try {
+ return getJdbcTemplate().update(
+ "INSERT INTO subscr_users(user_id,suser_id) VALUES (?,?)", toUser.getUid(), user.getUid()) == 1;
+ } catch (DuplicateKeyException e) {
+ return true;
+ }
}
@Transactional