From 97b37acdaee5d1665c2393254bc764bb4562729c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sun, 7 Apr 2019 02:12:25 +0300 Subject: Replies should have properties too --- src/main/java/com/juick/service/MessagesService.java | 5 +++-- .../java/com/juick/service/MessagesServiceImpl.java | 17 +++++++++-------- .../java/com/juick/service/TelegramServiceImpl.java | 1 - 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/main/java/com/juick/service') diff --git a/src/main/java/com/juick/service/MessagesService.java b/src/main/java/com/juick/service/MessagesService.java index b29337b2e..8f8c3e624 100644 --- a/src/main/java/com/juick/service/MessagesService.java +++ b/src/main/java/com/juick/service/MessagesService.java @@ -141,6 +141,7 @@ public interface MessagesService { boolean deleteReply(URI userUri, URI replyUri); - String getMessageProperty(Integer mid, String key); - void setMessageProperty(Integer mid, String key, String value); + String getMessageProperty(Integer mid, Integer rid, String key); + + void setMessageProperty(Integer mid, Integer rid, String key, String value); } diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index 2bae04e6a..798502b3d 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -1186,10 +1186,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional(readOnly = true) @Override - public String getMessageProperty(Integer mid, String key) { + public String getMessageProperty(Integer mid, Integer rid, String key) { List results = jdbcTemplate.queryForList( - "SELECT property_value FROM messages_properties WHERE message_id=? AND property_key=?", - String.class, mid, key); + "SELECT property_value FROM messages_properties WHERE message_id=? AND reply_id=? AND property_key=?", + String.class, mid, rid, key); if (results.size() > 0) { return results.get(0); } @@ -1198,22 +1198,23 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ @Transactional @Override - public void setMessageProperty(Integer mid, String key, String value) { + public void setMessageProperty(Integer mid, Integer rid, String key, String value) { SqlParameterSource parameterSource = new MapSqlParameterSource() .addValue("mid", mid) + .addValue("rid", rid) .addValue("key", key) .addValue("value", value); if (StringUtils.isNotEmpty(value)) { try { - getNamedParameterJdbcTemplate().update("INSERT INTO messages_properties(message_id, property_key, property_value) " + - "VALUES(:mid, :key, :value)", parameterSource); + getNamedParameterJdbcTemplate().update("INSERT INTO messages_properties(message_id, reply_id, property_key, property_value) " + + "VALUES(:mid, :rid, :key, :value)", parameterSource); } catch (DataIntegrityViolationException ex) { getNamedParameterJdbcTemplate().update("UPDATE messages_properties SET property_value=:value " + - "WHERE message_id=:mid AND property_key=:key", parameterSource); + "WHERE message_id=:mid AND reply_id=:rid AND property_key=:key", parameterSource); } } else { getNamedParameterJdbcTemplate().update("DELETE FROM messages_properties " + - "WHERE message_id=:mid AND property_key=:key", parameterSource); + "WHERE message_id=:mid AND reply_id=:rid AND property_key=:key", parameterSource); } } } diff --git a/src/main/java/com/juick/service/TelegramServiceImpl.java b/src/main/java/com/juick/service/TelegramServiceImpl.java index 99cbabf63..8fb138382 100644 --- a/src/main/java/com/juick/service/TelegramServiceImpl.java +++ b/src/main/java/com/juick/service/TelegramServiceImpl.java @@ -18,7 +18,6 @@ package com.juick.service; import com.juick.User; -import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -- cgit v1.2.3