aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/server/MessagesQueries.java48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/main/java/com/juick/server/MessagesQueries.java b/src/main/java/com/juick/server/MessagesQueries.java
index 91ee1913..4086cb13 100644
--- a/src/main/java/com/juick/server/MessagesQueries.java
+++ b/src/main/java/com/juick/server/MessagesQueries.java
@@ -272,35 +272,25 @@ public class MessagesQueries {
});
}
- public static com.juick.Message getReply(Connection sql, int mid, int rid) {
- com.juick.Message msg = null;
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- try {
- stmt = sql.prepareStatement("SELECT replies.user_id,users.nick,replies.replyto,DATE_FORMAT(replies.ts,'%Y-%m-%d %H:%i:%s'),replies.attach,replies.txt FROM replies INNER JOIN users ON replies.user_id=users.id WHERE replies.message_id=? AND replies.reply_id=?");
- stmt.setInt(1, mid);
- stmt.setInt(2, rid);
- rs = stmt.executeQuery();
- if (rs.first()) {
- msg = new com.juick.Message();
- msg.MID = mid;
- msg.RID = rid;
- msg.User = new com.juick.User();
- msg.User.UID = rs.getInt(1);
- msg.User.UName = rs.getString(2);
- msg.ReplyTo = rs.getInt(3);
- msg.TimestampString = rs.getString(4);
- msg.AttachmentType = rs.getString(5);
- msg.Text = rs.getString(6);
- }
- } catch (SQLException e) {
- LOGGER.log(Level.SEVERE, "sql exception", e);
- } finally {
- Utils.finishSQL(rs, stmt);
- }
-
- return msg;
+ public static com.juick.Message getReply(JdbcTemplate sql, int mid, int rid) {
+ return sql.queryForObject("SELECT replies.user_id,users.nick,"
+ + "replies.replyto,DATE_FORMAT(replies.ts,'%Y-%m-%d %H:%i:%s'),"
+ + "replies.attach,replies.txt FROM replies INNER JOIN users "
+ + "ON replies.user_id=users.id "
+ + "WHERE replies.message_id=? AND replies.reply_id=?",
+ new Object[]{mid, rid}, (rs, num) -> {
+ Message msg = new Message();
+ msg.MID = mid;
+ msg.RID = rid;
+ msg.User = new com.juick.User();
+ msg.User.UID = rs.getInt(1);
+ msg.User.UName = rs.getString(2);
+ msg.ReplyTo = rs.getInt(3);
+ msg.TimestampString = rs.getString(4);
+ msg.AttachmentType = rs.getString(5);
+ msg.Text = rs.getString(6);
+ return msg;
+ });
}
public static User getMessageAuthor(JdbcTemplate sql, int mid) {