diff options
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) { |