aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 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;