diff options
Diffstat (limited to 'src/main/java/com/juick/service/MessagesServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/MessagesServiceImpl.java | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/main/java/com/juick/service/MessagesServiceImpl.java b/src/main/java/com/juick/service/MessagesServiceImpl.java index bb50d953..add8db22 100644 --- a/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -30,7 +30,6 @@ 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; @@ -871,17 +870,15 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ return Collections.emptyList(); } - @Transactional(readOnly = true) - @Override - public Map<Integer, Set<Reaction>> updateReactionsFor(final List<Integer> mids) { - - return getNamedParameterJdbcTemplate().query( - "select f.message_id as mid, f.like_id as lid," + " r.description as descr, count(f.like_id) as cnt" - + " from favorites f LEFT JOIN reactions r ON f.like_id = r.like_id " - + " where f.message_id IN (:mids) " + " group by f.message_id, f.like_id, r.description", + private Map<Integer, Set<Reaction>> updateReactionsFor(final List<Integer> mids) { + // This method always called from the transactional block, so it should not be marked as transactional itself + return getNamedParameterJdbcTemplate().query(""" + select f.message_id as mid, f.like_id as lid, + r.description as descr, count(f.like_id) as cnt + from favorites f LEFT JOIN reactions r ON f.like_id = r.like_id + where f.message_id IN (:mids) group by f.message_id, f.like_id, r.description""", new MapSqlParameterSource("mids", mids), (ResultSet rs) -> { Map<Integer, Set<Reaction>> results = new HashMap<>(); - while (rs.next()) { int messageId = rs.getInt("mid"); int likeId = rs.getInt("lid"); @@ -893,7 +890,6 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ results.computeIfAbsent(messageId, HashSet::new); results.get(messageId).add(reaction); } - return results; }); |