aboutsummaryrefslogtreecommitdiff
path: root/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-12-19 16:36:16 +0300
committerGravatar Vitaly Takmazov2017-12-19 16:36:16 +0300
commit5812cbafc57658120b0d2370342efe897d39661f (patch)
tree620213f74d0442abca5601c06d77c23568286a6d /juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
parentedfb4c9c20bccfcf0cf87124f3946b5e24300a11 (diff)
do not delete last email
Diffstat (limited to 'juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java')
-rw-r--r--juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
index c42641df..57aa59f7 100644
--- a/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
+++ b/juick-server-jdbc/src/main/java/com/juick/service/EmailServiceImpl.java
@@ -20,6 +20,7 @@ package com.juick.service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
@@ -57,7 +58,12 @@ public class EmailServiceImpl extends BaseJdbcService implements EmailService {
@Override
public boolean deleteEmail(Integer userId, String account) {
- return getJdbcTemplate().update("DELETE FROM emails WHERE user_id=? AND email=?", userId, account) > 0;
+ return getNamedParameterJdbcTemplate().update("DELETE FROM emails " +
+ "WHERE (SELECT COUNT(*) cnt FROM (select user_id, email FROM emails e) c WHERE user_id=:uid) > 1 " +
+ "AND user_id=:uid AND email=:email",
+ new MapSqlParameterSource()
+ .addValue("uid", userId)
+ .addValue("email", account)) > 0;
}
@Override