From d5875f2edf13d64ed58f4257caa944e678fcb949 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 15 Nov 2022 20:56:07 +0300 Subject: SubscriptionService: handle duplicated key case in subscribeMessage() correctly * this will prevent MariaDB warning --- .../java/com/juick/service/SubscriptionServiceImpl.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src') 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 -- cgit v1.2.3