aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server/model/DataServiceImpl.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-03-26 21:18:54 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2014-03-26 21:18:54 +1300
commitf97b868dc1bbf9698d05a9473da6ddd0c01640e8 (patch)
tree429293f0a21238602b76ceb58644bda80e872680 /src/org/traccar/web/server/model/DataServiceImpl.java
parent33dbcf4d450e190228a3a0dffd611f142215380b (diff)
parent7b4306677f47e6e1c12bf3311d6b3394b2b9ff11 (diff)
downloadetbsa-traccar-web-f97b868dc1bbf9698d05a9473da6ddd0c01640e8.tar.gz
etbsa-traccar-web-f97b868dc1bbf9698d05a9473da6ddd0c01640e8.tar.bz2
etbsa-traccar-web-f97b868dc1bbf9698d05a9473da6ddd0c01640e8.zip
Merge pull request #147 from khfayzullaev/master
Admin should not add an existing username
Diffstat (limited to 'src/org/traccar/web/server/model/DataServiceImpl.java')
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java18
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 3ae4d21..509bca4 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;