From eab80ba585ae61a3ddef7a785a87ead7f39e9efe Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 19 Dec 2017 15:44:50 +0300 Subject: jdbc: do not delete last jid --- .../src/main/java/com/juick/service/UserServiceImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'juick-server-jdbc/src/main/java/com/juick/service') diff --git a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java index b8835c7f..6196af86 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/UserServiceImpl.java @@ -703,7 +703,12 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional @Override public boolean deleteJID(int uid, String jid) { - return getJdbcTemplate().update("DELETE FROM jids WHERE user_id=? AND jid=?", uid, jid) > 0; + return getNamedParameterJdbcTemplate().update("DELETE FROM jids " + + "WHERE (SELECT COUNT(*) cnt FROM (select user_id, jid FROM jids j) c WHERE user_id=:uid) > 1 " + + "AND user_id=:uid AND jid=:jid", + new MapSqlParameterSource() + .addValue("uid", uid) + .addValue("jid", jid)) > 0; } @Transactional -- cgit v1.2.3