diff options
Diffstat (limited to 'src/main/java/com/juick/service/UserServiceImpl.java')
-rw-r--r-- | src/main/java/com/juick/service/UserServiceImpl.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/main/java/com/juick/service/UserServiceImpl.java b/src/main/java/com/juick/service/UserServiceImpl.java index fdc4f28c..f05fc93f 100644 --- a/src/main/java/com/juick/service/UserServiceImpl.java +++ b/src/main/java/com/juick/service/UserServiceImpl.java @@ -354,18 +354,22 @@ public class UserServiceImpl extends BaseJdbcService implements UserService { @Transactional @Override public boolean updateUserInfo(final User user, final UserInfo info) { - return getJdbcTemplate().update( - "INSERT INTO usersinfo(user_id, fullname, country, url, descr) VALUES (?, ?, ?, ?, ?) " + - "ON DUPLICATE KEY UPDATE fullname = ?, country = ?, url = ?, descr = ?", - user.getUid(), - info.getFullName(), - info.getCountry(), - info.getUrl(), - info.getDescription(), - info.getFullName(), - info.getCountry(), - info.getUrl(), - info.getDescription()) > 0; + try { + return getJdbcTemplate().update( + "INSERT INTO usersinfo(user_id, fullname, country, url, descr) VALUES (?, ?, ?, ?, ?)", + user.getUid(), + info.getFullName(), + info.getCountry(), + info.getUrl(), + info.getDescription()) > 0; + } catch (DuplicateKeyException e) { + return getJdbcTemplate().update("UPDATE usersinfo SET fullname = ?, country = ?, url = ?, descr = ? WHERE user_id = ?", + info.getFullName(), + info.getCountry(), + info.getUrl(), + info.getDescription(), + user.getUid()) > 0; + } } @Transactional(readOnly = true) |