aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/service/MessagesServiceImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r--src/main/java/com/juick/service/MessagesServiceImpl.java39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java
index def6324a..3e09d204 100644
--- a/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -33,6 +33,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.ConnectionCallback;
@@ -1162,21 +1163,57 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
}
}
+ @Transactional
@Override
public boolean updateReplyUri(Message reply, URI replyUri) {
return jdbcTemplate.update("UPDATE replies SET reply_uri=?, html=0 WHERE message_id=? AND reply_id=?",
replyUri.toASCIIString(), reply.getMid(), reply.getRid()) > 0;
}
+ @Transactional(readOnly = true)
@Override
public boolean replyExists(URI replyUri) {
return jdbcTemplate.queryForList("SELECT reply_id FROM replies WHERE reply_uri=?",
Integer.class, replyUri.toASCIIString()).size() > 0;
}
+ @Transactional
@Override
public boolean deleteReply(URI userUri, URI replyUri) {
- return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?",
+ return jdbcTemplate.update("DELETE FROM replies WHERE user_uri=? AND reply_uri=?",
userUri.toASCIIString(), replyUri.toASCIIString()) > 0;
}
+
+ @Transactional(readOnly = true)
+ @Override
+ public String getMessageProperty(Integer mid, String key) {
+ List<String> results = jdbcTemplate.queryForList(
+ "SELECT property_value FROM messages_properties WHERE message_id=? AND property_key=?",
+ String.class, mid, key);
+ if (results.size() > 0) {
+ return results.get(0);
+ }
+ return StringUtils.EMPTY;
+ }
+
+ @Transactional
+ @Override
+ public void setMessageProperty(Integer mid, String key, String value) {
+ SqlParameterSource parameterSource = new MapSqlParameterSource()
+ .addValue("mid", mid)
+ .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);
+ } catch (DataIntegrityViolationException ex) {
+ getNamedParameterJdbcTemplate().update("UPDATE messages_properties SET property_value=:value " +
+ "WHERE message_id=:mid AND property_key=:key", parameterSource);
+ }
+ } else {
+ getNamedParameterJdbcTemplate().update("DELETE FROM messages_properties " +
+ "WHERE message_id=:mid AND property_key=:key", parameterSource);
+ }
+ }
}