aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-15 15:20:29 +0300
committerGravatar Vitaly Takmazov2016-01-15 15:20:29 +0300
commit0ac9d76d6348f487ada697678395d15abee244c9 (patch)
treeeb8de5d8cd31f9692d638cdd99a77a36ffbc8d2c /src/main/java/com/juick
parent392b0e333248665a72eaf1febee4ccea9a7edf1f (diff)
spring-jdbc WIP
Diffstat (limited to 'src/main/java/com/juick')
-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) {