aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-07-28 13:44:05 +0500
committerAbyss777 <abyss@fox5.ru>2016-07-28 13:44:05 +0500
commit70f684945754b6bdadd2bf038ab955d93a95977d (patch)
tree3a4cea9bf89f2b499f2417ab844325369b42e9de /src/org/traccar/database
parentf7e82c4d9a66b8ab1ba90d4cae690f9c798d03a7 (diff)
downloadtrackermap-server-70f684945754b6bdadd2bf038ab955d93a95977d.tar.gz
trackermap-server-70f684945754b6bdadd2bf038ab955d93a95977d.tar.bz2
trackermap-server-70f684945754b6bdadd2bf038ab955d93a95977d.zip
Organized server cache
Moved lookupAttribute function to DeviceManager
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DeviceManager.java32
-rw-r--r--src/org/traccar/database/PermissionsManager.java11
2 files changed, 42 insertions, 1 deletions
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 5a0c87985..3476139f2 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -32,6 +32,7 @@ import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Group;
import org.traccar.model.Position;
+import org.traccar.model.Server;
public class DeviceManager implements IdentityManager {
@@ -40,6 +41,7 @@ public class DeviceManager implements IdentityManager {
private final Config config;
private final DataManager dataManager;
private final long dataRefreshDelay;
+ private boolean lookupGroupsAttribute;
private Map<Long, Device> devicesById;
private Map<String, Device> devicesByUniqueId;
@@ -54,6 +56,7 @@ public class DeviceManager implements IdentityManager {
this.dataManager = dataManager;
this.config = Context.getConfig();
dataRefreshDelay = config.getLong("database.refreshDelay", DEFAULT_REFRESH_DELAY) * 1000;
+ lookupGroupsAttribute = config.getBoolean("deviceManager.lookupGroupsAttribute");
if (dataManager != null) {
try {
updateGroupCache(true);
@@ -312,4 +315,33 @@ public class DeviceManager implements IdentityManager {
dataManager.removeGroup(groupId);
groupsById.remove(groupId);
}
+
+ public String lookupAttribute(long deviceId, String attributeName) {
+ String result = null;
+ Device device = getDeviceById(deviceId);
+ if (device != null) {
+ if (device.getAttributes().containsKey(attributeName)) {
+ result = (String) device.getAttributes().get(attributeName);
+ }
+ if (result == null && lookupGroupsAttribute) {
+ long groupId = device.getGroupId();
+ while (groupId != 0) {
+ if (getGroupById(groupId) != null) {
+ result = (String) getGroupById(groupId).getAttributes().get(attributeName);
+ if (result != null) {
+ break;
+ }
+ groupId = getGroupById(groupId).getGroupId();
+ } else {
+ groupId = 0;
+ }
+ }
+ }
+ if (result == null) {
+ Server server = Context.getPermissionsManager().getServer();
+ result = (String) server.getAttributes().get(attributeName);
+ }
+ }
+ return result;
+ }
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index d786dcc4e..92fcc3ebd 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -34,7 +34,7 @@ public class PermissionsManager {
private final DataManager dataManager;
- private Server server;
+ private volatile Server server;
private final Map<Long, User> users = new HashMap<>();
@@ -153,4 +153,13 @@ public class PermissionsManager {
}
}
+ public Server getServer() {
+ return server;
+ }
+
+ public void updateServer(Server server) throws SQLException {
+ dataManager.updateServer(server);
+ this.server = server;
+ }
+
}