From b0cfa955c77c4e36bd334324d0ccb2ff24ff549f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Nov 2018 15:16:08 +0300 Subject: versioned avatars in www --- .../java/com/juick/service/UserServiceImpl.java | 28 ++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/juick/service') 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) -- cgit v1.2.3