diff options
author | Khurshid Fayzullaev <khurshidfayzullaev@yahoo.com> | 2014-03-24 10:33:02 -0400 |
---|---|---|
committer | Khurshid Fayzullaev <khurshidfayzullaev@yahoo.com> | 2014-03-24 10:33:02 -0400 |
commit | 4694754957f733c88e0e2f39fad6f02a42140adb (patch) | |
tree | a5bf6ecf0624d0dd1733865ebc30ef5133fb2d66 /src | |
parent | f40f6e306d055ebc46b0e22c850a21f0cd0cfb6c (diff) | |
download | trackermap-web-4694754957f733c88e0e2f39fad6f02a42140adb.tar.gz trackermap-web-4694754957f733c88e0e2f39fad6f02a42140adb.tar.bz2 trackermap-web-4694754957f733c88e0e2f39fad6f02a42140adb.zip |
Admin cannot add a user with an existing username
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/web/server/model/DataServiceImpl.java | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java index 3ae4d21d..509bca4a 100644 --- a/src/org/traccar/web/server/model/DataServiceImpl.java +++ b/src/org/traccar/web/server/model/DataServiceImpl.java @@ -193,9 +193,21 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService synchronized (entityManager) { entityManager.getTransaction().begin(); try { - entityManager.persist(user); - entityManager.getTransaction().commit(); - return user; + String login = user.getLogin(); + TypedQuery<User> query = entityManager.createQuery( + "SELECT x FROM User x WHERE x.login = :login", User.class); + query.setParameter("login", login); + List<User> results = query.getResultList(); + + if (results.isEmpty()) { + entityManager.persist(user); + entityManager.getTransaction().commit(); + return user; + } + else + { + throw new IllegalStateException(); + } } catch (RuntimeException e) { entityManager.getTransaction().rollback(); throw e; |