aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/web/server/model/DataServiceImpl.java
diff options
context:
space:
mode:
authorKhurshid Fayzullaev <khurshidfayzullaev@yahoo.com>2014-04-10 15:34:17 -0400
committerKhurshid Fayzullaev <khurshidfayzullaev@yahoo.com>2014-04-10 15:34:17 -0400
commit4f0750af0eabce7b6689847d070a0237b1130955 (patch)
tree59f4a58db5fb34b1f0fbf02147af70560d1ac8b7 /src/org/traccar/web/server/model/DataServiceImpl.java
parentf8bc5fb042fb2477ea159fc359fdc06b493f0f3e (diff)
downloadtrackermap-web-4f0750af0eabce7b6689847d070a0237b1130955.tar.gz
trackermap-web-4f0750af0eabce7b6689847d070a0237b1130955.tar.bz2
trackermap-web-4f0750af0eabce7b6689847d070a0237b1130955.zip
Update DataServiceImpl.java
Diffstat (limited to 'src/org/traccar/web/server/model/DataServiceImpl.java')
-rw-r--r--src/org/traccar/web/server/model/DataServiceImpl.java17
1 files changed, 10 insertions, 7 deletions
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<Device> query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class);
+ query.setParameter("id", device.getUniqueId());
+ List<Device> results = query.getResultList();
+
entityManager.getTransaction().begin();
try {
- TypedQuery<Device> query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class);
- query.setParameter("id", device.getUniqueId());
- List<Device> 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<Device> query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class);
+ query.setParameter("id", device.getUniqueId());
+ List<Device> results = query.getResultList();
+
entityManager.getTransaction().begin();
try {
- TypedQuery<Device> query = entityManager.createQuery("SELECT x FROM Device x WHERE x.uniqueId = :id", Device.class);
- query.setParameter("id", device.getUniqueId());
- List<Device> results = query.getResultList();
if (results.isEmpty()) {
device = entityManager.merge(device);
entityManager.getTransaction().commit();