From 4f0750af0eabce7b6689847d070a0237b1130955 Mon Sep 17 00:00:00 2001 From: Khurshid Fayzullaev Date: Thu, 10 Apr 2014 15:34:17 -0400 Subject: Update DataServiceImpl.java --- src/org/traccar/web/server/model/DataServiceImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/org/traccar/web/server/model/DataServiceImpl.java b/src/org/traccar/web/server/model/DataServiceImpl.java index cc0b30e0..3164b102 100644 --- a/src/org/traccar/web/server/model/DataServiceImpl.java +++ b/src/org/traccar/web/server/model/DataServiceImpl.java @@ -304,12 +304,13 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService EntityManager entityManager = getSessionEntityManager(); synchronized (entityManager) { User user = getSessionUser(); + + TypedQuery query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class); + query.setParameter("id", device.getUniqueId()); + List results = query.getResultList(); + entityManager.getTransaction().begin(); try { - TypedQuery query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class); - query.setParameter("id", device.getUniqueId()); - List results = query.getResultList(); - if (results.isEmpty()) { entityManager.persist(device); user.getDevices().add(device); @@ -331,11 +332,13 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService public Device updateDevice(Device device) { EntityManager entityManager = getSessionEntityManager(); synchronized (entityManager) { + + TypedQuery query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class); + query.setParameter("id", device.getUniqueId()); + List results = query.getResultList(); + entityManager.getTransaction().begin(); try { - TypedQuery query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class); - query.setParameter("id", device.getUniqueId()); - List results = query.getResultList(); if (results.isEmpty()) { device = entityManager.merge(device); entityManager.getTransaction().commit(); -- cgit v1.2.3