diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 23 | ||||
-rw-r--r-- | src/org/traccar/database/IdentityManager.java | 2 |
2 files changed, 13 insertions, 12 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 943dcb53c..deb31094e 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -111,17 +111,8 @@ public class DataManager implements IdentityManager { } } - @Override - public Device getDeviceById(long id) { - return devicesById.get(id); - } - - @Override - public Device getDeviceByUniqueId(String uniqueId) throws SQLException { - - if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay - || !devicesByUniqueId.containsKey(uniqueId)) { - + private void updateDeviceCache(boolean force) throws SQLException { + if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay || force) { devicesById.clear(); devicesByUniqueId.clear(); for (Device device : getAllDevices()) { @@ -130,7 +121,17 @@ public class DataManager implements IdentityManager { } devicesLastUpdate = System.currentTimeMillis(); } + } + @Override + public Device getDeviceById(long id) throws SQLException { + updateDeviceCache(!devicesById.containsKey(id)); + return devicesById.get(id); + } + + @Override + public Device getDeviceByUniqueId(String uniqueId) throws SQLException { + updateDeviceCache(!devicesByUniqueId.containsKey(uniqueId)); return devicesByUniqueId.get(uniqueId); } diff --git a/src/org/traccar/database/IdentityManager.java b/src/org/traccar/database/IdentityManager.java index 8bdce09a3..761219dd5 100644 --- a/src/org/traccar/database/IdentityManager.java +++ b/src/org/traccar/database/IdentityManager.java @@ -19,7 +19,7 @@ import org.traccar.model.Device; public interface IdentityManager { - Device getDeviceById(long id); + Device getDeviceById(long id) throws Exception; Device getDeviceByUniqueId(String uniqueId) throws Exception; |