diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-14 19:34:58 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-07-14 19:34:58 +1200 |
commit | f9b7908c1fe0c04e9dcb93b4261b9fe0b4bb1617 (patch) | |
tree | 057957543cb18c20bf66de6d363fdc821700832d /src/org/traccar/database | |
parent | e98b18b8b0a8c99d24ac8010c1393978d071baa2 (diff) | |
download | traccar-server-f9b7908c1fe0c04e9dcb93b4261b9fe0b4bb1617.tar.gz traccar-server-f9b7908c1fe0c04e9dcb93b4261b9fe0b4bb1617.tar.bz2 traccar-server-f9b7908c1fe0c04e9dcb93b4261b9fe0b4bb1617.zip |
Reduce dependencies on data manager (fix #954)
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/ConnectionManager.java | 17 | ||||
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 10 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java index 0d357a41c..dc125d7b0 100644 --- a/src/org/traccar/database/ConnectionManager.java +++ b/src/org/traccar/database/ConnectionManager.java @@ -31,18 +31,19 @@ import org.traccar.model.Position; public class ConnectionManager { - private Map<String, ActiveDevice> activeDevices = new HashMap<>(); + private final Map<String, ActiveDevice> activeDevices = new HashMap<>(); private final Map<Long, Position> positions = new HashMap<>(); private final Map<Long, Set<DataCacheListener>> listeners = new HashMap<>(); - public void init(DataManager dataManager) { - try { - Collection<Position> positions = dataManager.getLatestPositions(); - for (Position position : positions) { - this.positions.put(position.getDeviceId(), position); + public ConnectionManager(DataManager dataManager) { + if (dataManager != null) { + try { + for (Position position : dataManager.getLatestPositions()) { + this.positions.put(position.getDeviceId(), position); + } + } catch (SQLException error) { + Log.warning(error); } - } catch (SQLException error) { - Log.warning(error); } } diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index 40783ad98..cfbbb9a39 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -21,13 +21,14 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Permission; import org.traccar.model.User; public class PermissionsManager { + private final DataManager dataManager; + private final Map<Long, User> users = new HashMap<>(); private final Map<Long, Set<Long>> permissions = new HashMap<>(); @@ -39,7 +40,8 @@ public class PermissionsManager { return permissions.get(userId); } - public PermissionsManager() { + public PermissionsManager(DataManager dataManager) { + this.dataManager = dataManager; refresh(); } @@ -47,10 +49,10 @@ public class PermissionsManager { users.clear(); permissions.clear(); try { - for (User user : Context.getDataManager().getUsers()) { + for (User user : dataManager.getUsers()) { users.put(user.getId(), user); } - for (Permission permission : Context.getDataManager().getPermissions()) { + for (Permission permission : dataManager.getPermissions()) { getNotNull(permission.getUserId()).add(permission.getDeviceId()); } } catch (SQLException error) { |