diff options
author | Vitaly Takmazov | 2022-11-15 20:56:07 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2022-11-15 20:56:07 +0300 |
commit | d5875f2edf13d64ed58f4257caa944e678fcb949 (patch) | |
tree | 445ecb695fc8a0466e0ffcba14e0a51910b45d8d /src/main/java/com/juick | |
parent | 7e391970e2d0b59fb0c351c5fa9907875d68b9a7 (diff) |
SubscriptionService: handle duplicated key case in subscribeMessage() correctly
* this will prevent MariaDB warning
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r-- | src/main/java/com/juick/service/SubscriptionServiceImpl.java | 13 |
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 |