aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-12-22 14:56:55 +0300
committerGravatar Vitaly Takmazov2017-12-22 14:56:55 +0300
commit667682533fb1246c4aff07082bf1710851454db7 (patch)
tree0bcac54fd7f6133579e2dbc05449716b53aaa7a7 /juick-server-jdbc/src
parentaedd466c0caf6a95bfebc2de10371bc944bec2c3 (diff)
jdbc: fix reply creation
Diffstat (limited to 'juick-server-jdbc/src')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java12
-rw-r--r--juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java3
2 files changed, 6 insertions, 9 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
index 0c53740d..c4eb67db 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -182,19 +182,15 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public int createReply(final int mid, final int rid, final int uid, final String txt, final String attachment) {
int ridnew = getReplyIDIncrement(mid);
-
- getJdbcTemplate().update(
- "INSERT INTO replies(message_id, reply_id, user_id, replyto, attach, txt) VALUES (?, ?, ?, ?, ?, ?)",
+ getJdbcTemplate().execute("SET @ts=CURRENT_TIMESTAMP()");
+ getJdbcTemplate().update("INSERT INTO replies(message_id, reply_id, user_id, replyto, attach, txt, ts) " +
+ "VALUES (?, ?, ?, ?, ?, ?, @ts)",
new Object[]{mid, ridnew, uid, rid, attachment, txt},
new int[]{Types.INTEGER, Types.SMALLINT, Types.INTEGER, Types.SMALLINT, Types.CHAR, Types.VARCHAR});
if (ridnew > 0) {
getJdbcTemplate().update(
- "UPDATE messages SET replies = replies + 1 WHERE message_id = ?",
- mid);
- getJdbcTemplate().update(
- "UPDATE messages, (SELECT ts FROM replies) as r " +
- "SET messages.updated = r.ts WHERE message_id = ?",
+ "UPDATE messages SET replies = replies + 1, updated=@ts WHERE message_id = ?",
mid);
}
return ridnew;
diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
index 6bab2b1c..90feb0ea 100644
--- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
+++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java
@@ -192,11 +192,12 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests {
assertThat(emailService.deleteEmail(ugnich_id, "first@localhost"), equalTo(false));
}
@Test
- public void messageUpdatedTimeShouldMatchLastReplyTime() {
+ public void messageUpdatedTimeShouldMatchLastReplyTime() throws InterruptedException {
int ugnich_id = userService.createUser("hugnich4", "x");
int mid = messagesService.createMessage(ugnich_id, "yo", null, null);
Instant ts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?",
Timestamp.class, mid).toInstant();
+ Thread.sleep(1000);
int rid = messagesService.createReply(mid, 0, ugnich_id, "people", null);
Instant rts = jdbcTemplate.queryForObject("SELECT updated FROM messages WHERE message_id=?",
Timestamp.class, mid).toInstant();