aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java18
-rw-r--r--src/org/traccar/database/IdentityManager.java2
2 files changed, 15 insertions, 5 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 48f3228ce..f134f87cb 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -50,7 +50,8 @@ public class DataManager implements IdentityManager {
private DataSource dataSource;
- private final Map<String, Device> devices = new HashMap<>();
+ private final Map<Long, Device> devicesById = new HashMap<>();
+ private final Map<String, Device> devicesByUniqueId = new HashMap<>();
private long devicesLastUpdate;
private final long devicesRefreshDelay;
@@ -107,20 +108,27 @@ public class DataManager implements IdentityManager {
dataSource = ds;
}
}
+
+ @Override
+ public Device getDeviceById(long id) {
+ return devicesById.get(id);
+ }
@Override
public Device getDeviceByUniqueId(String uniqueId) throws SQLException {
- if ((new Date().getTime() - devicesLastUpdate > devicesRefreshDelay) || !devices.containsKey(uniqueId)) {
+ if ((new Date().getTime() - devicesLastUpdate > devicesRefreshDelay) || !devicesByUniqueId.containsKey(uniqueId)) {
- devices.clear();
+ devicesById.clear();
+ devicesByUniqueId.clear();
for (Device device : getAllDevices()) {
- devices.put(device.getUniqueId(), device);
+ devicesById.put(device.getId(), device);
+ devicesByUniqueId.put(device.getUniqueId(), device);
}
devicesLastUpdate = new Date().getTime();
}
- return devices.get(uniqueId);
+ return devicesByUniqueId.get(uniqueId);
}
private String getQuery(String key) {
diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java
index c3861ad72..84f246363 100644
--- a/src/org/traccar/database/IdentityManager.java
+++ b/src/org/traccar/database/IdentityManager.java
@@ -19,6 +19,8 @@ import org.traccar.model.Device;
public interface IdentityManager {
+ public Device getDeviceById(long id);
+
public Device getDeviceByUniqueId(String uniqueId) throws Exception;
}