diff options
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index a32d31d68..f5df1b84b 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -342,11 +342,34 @@ public class DataManager implements IdentityManager { .executeQuery(GroupPermission.class); } - public Collection<Device> getAllDevices() throws SQLException { + private Collection<Device> getAllDevices() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectDevicesAll")) .executeQuery(Device.class); } + public Collection<Device> getAllDevicesCached() { + boolean forceUpdate; + devicesLock.readLock().lock(); + try { + forceUpdate = devicesById.values().isEmpty(); + } finally { + devicesLock.readLock().unlock(); + } + + try { + updateDeviceCache(forceUpdate); + } catch (SQLException e) { + Log.warning(e); + } + + devicesLock.readLock().lock(); + try { + return devicesById.values(); + } finally { + devicesLock.readLock().unlock(); + } + } + public Collection<Device> getDevices(long userId) throws SQLException { Collection<Device> devices = new ArrayList<>(); for (long id : Context.getPermissionsManager().getDevicePermissions(userId)) { |