aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2022-11-15 20:56:07 +0300
committerGravatar Vitaly Takmazov2022-11-15 20:56:07 +0300
commitd5875f2edf13d64ed58f4257caa944e678fcb949 (patch)
tree445ecb695fc8a0466e0ffcba14e0a51910b45d8d /src/main/java/com
parent7e391970e2d0b59fb0c351c5fa9907875d68b9a7 (diff)
SubscriptionService: handle duplicated key case in subscribeMessage() correctly
* this will prevent MariaDB warning
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/service/SubscriptionServiceImpl.java13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/main/java/com/juick/service/SubscriptionServiceImpl.java b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
index b8d32c6a..85980f1a 100644
--- a/src/main/java/com/juick/service/SubscriptionServiceImpl.java
+++ b/src/main/java/com/juick/service/SubscriptionServiceImpl.java
@@ -126,14 +126,11 @@ public class SubscriptionServiceImpl extends BaseJdbcService implements Subscrip
@Transactional
@Override
public boolean subscribeMessage(final Message message, final User user) {
- try {
- boolean result = getJdbcTemplate().update(
- "INSERT INTO subscr_messages(suser_id, message_id) VALUES (?, ?)", user.getUid(), message.getMid()) == 1;
- messagesService.setLastReadComment(user, message.getMid(), message.getReplies());
- return result;
- } catch (DuplicateKeyException e) {
- return true;
- }
+ boolean result = getJdbcTemplate().update(
+ "INSERT INTO subscr_messages(suser_id, message_id) VALUES (?, ?) ON DUPLICATE KEY UPDATE suser_id=?",
+ user.getUid(), message.getMid(), user.getUid()) == 1;
+ messagesService.setLastReadComment(user, message.getMid(), message.getReplies());
+ return result;
}
@Transactional