diff options
author | 2016-07-11 10:16:36 +0300 | |
---|---|---|
committer | 2016-07-11 10:16:36 +0300 | |
commit | 7eb3b141e5e4e719e1ef77ea06b6bac7610ae913 (patch) | |
tree | 1573abb9b47f5001053ed07b8ba9164c8fc5a188 /juick-core/src/main/java/com/juick/server/MessagesQueries.java | |
parent | f0a60dd95eff153c022bca0c71fed39b901dd547 (diff) |
cleanup sql
Diffstat (limited to 'juick-core/src/main/java/com/juick/server/MessagesQueries.java')
-rw-r--r-- | juick-core/src/main/java/com/juick/server/MessagesQueries.java | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/juick-core/src/main/java/com/juick/server/MessagesQueries.java b/juick-core/src/main/java/com/juick/server/MessagesQueries.java index a0242543..3d0d734d 100644 --- a/juick-core/src/main/java/com/juick/server/MessagesQueries.java +++ b/juick-core/src/main/java/com/juick/server/MessagesQueries.java @@ -26,6 +26,7 @@ import org.springframework.jdbc.core.ConnectionCallback; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; +import org.springframework.util.StringUtils; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -485,7 +486,7 @@ public class MessagesQueries { } if (mids.size() > 0) { return sql.queryForList("SELECT message_id FROM messages WHERE message_id " + - "IN (" + Utils.convertArrayInt2String(mids) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20", + "IN (" + StringUtils.arrayToCommaDelimitedString(mids.toArray()) + ") AND privacy>0 ORDER BY message_id DESC LIMIT 20", Integer.class); } return mids; @@ -556,53 +557,54 @@ public class MessagesQueries { if (mids.size() > 0) { return sql.queryForList("SELECT message_id FROM messages WHERE message_id IN (" + - Utils.convertArrayInt2String(mids) + ") AND privacy>=" + privacy + " ORDER BY message_id DESC", + StringUtils.arrayToCommaDelimitedString(mids.toArray()) + ") AND privacy>=" + privacy + " ORDER BY message_id DESC", Integer.class); } return mids; } public static List<com.juick.Message> getMessages(JdbcTemplate sql, List<Integer> mids) { - List<com.juick.Message> msgs = new ArrayList<>(20); - - return sql.query("SELECT messages.message_id,messages.user_id,users.nick," - + "messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt," - + "TIMESTAMPDIFF(MINUTE,messages.ts,NOW())," - + "messages.ts,messages.replies," - + "messages_txt.repliesby,messages.attach,messages.lat," - + "messages.lon,messages.likes " - + "FROM (messages INNER JOIN messages_txt " - + "ON messages.message_id=messages_txt.message_id) " - + "INNER JOIN users ON messages.user_id=users.id " - + "WHERE messages.message_id " - + "IN (" + Utils.convertArrayInt2String(mids) + ") " - + "ORDER BY messages.message_id DESC", (rs, rowNum) -> { - com.juick.Message msg = new com.juick.Message(); - msg.setUser(new User()); - - msg.setMID(rs.getInt(1)); - msg.getUser().setUID(rs.getInt(2)); - msg.getUser().setUName(rs.getString(3)); - if (rs.getString(4) != null) { - msg.parseTags(rs.getString(4)); - } - msg.ReadOnly = rs.getInt(5) == 1; - msg.Privacy = rs.getInt(6); - msg.FriendsOnly = msg.Privacy < 0; - msg.setText(rs.getString(7)); - msg.TimeAgo = rs.getInt(8); - msg.setDate(rs.getTimestamp(9)); - msg.Replies = rs.getInt(10); - msg.RepliesBy = rs.getString(11); - msg.AttachmentType = rs.getString(12); - if (rs.getDouble(13) != 0) { - msg.Place = new com.juick.Place(); - msg.Place.lat = rs.getDouble(13); - msg.Place.lon = rs.getDouble(14); - } - msg.Likes = rs.getInt(15); - return msg; - }); + if (!mids.isEmpty()) { + return sql.query("SELECT messages.message_id,messages.user_id,users.nick," + + "messages_txt.tags,messages.readonly,messages.privacy,messages_txt.txt," + + "TIMESTAMPDIFF(MINUTE,messages.ts,NOW())," + + "messages.ts,messages.replies," + + "messages_txt.repliesby,messages.attach,messages.lat," + + "messages.lon,messages.likes " + + "FROM (messages INNER JOIN messages_txt " + + "ON messages.message_id=messages_txt.message_id) " + + "INNER JOIN users ON messages.user_id=users.id " + + "WHERE messages.message_id " + + "IN (" + StringUtils.arrayToCommaDelimitedString(mids.toArray()) + ") " + + "ORDER BY messages.message_id DESC", (rs, rowNum) -> { + com.juick.Message msg = new com.juick.Message(); + msg.setUser(new User()); + + msg.setMID(rs.getInt(1)); + msg.getUser().setUID(rs.getInt(2)); + msg.getUser().setUName(rs.getString(3)); + if (rs.getString(4) != null) { + msg.parseTags(rs.getString(4)); + } + msg.ReadOnly = rs.getInt(5) == 1; + msg.Privacy = rs.getInt(6); + msg.FriendsOnly = msg.Privacy < 0; + msg.setText(rs.getString(7)); + msg.TimeAgo = rs.getInt(8); + msg.setDate(rs.getTimestamp(9)); + msg.Replies = rs.getInt(10); + msg.RepliesBy = rs.getString(11); + msg.AttachmentType = rs.getString(12); + if (rs.getDouble(13) != 0) { + msg.Place = new com.juick.Place(); + msg.Place.lat = rs.getDouble(13); + msg.Place.lon = rs.getDouble(14); + } + msg.Likes = rs.getInt(15); + return msg; + }); + } + return Collections.emptyList(); } public static List<com.juick.Message> getReplies(JdbcTemplate sql, int mid) { |