aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-05-13 11:01:48 +1200
committerGitHub <noreply@github.com>2017-05-13 11:01:48 +1200
commit713d6c55a007aa80850810f447308976516bfa63 (patch)
tree057e9147e724a56b6e2f3820fcf3d9ab67561fdf /src/org/traccar/database/DataManager.java
parent51920cae6438f8888090f177761a82afff33067f (diff)
parent6c17f85d04b224ff2a09265918765c9f4fc8cf94 (diff)
downloadtrackermap-server-713d6c55a007aa80850810f447308976516bfa63.tar.gz
trackermap-server-713d6c55a007aa80850810f447308976516bfa63.tar.bz2
trackermap-server-713d6c55a007aa80850810f447308976516bfa63.zip
Merge pull request #3156 from Abyss777/computed_attributes
Implement computed attributes
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 2f2cf1275..840a8931c 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -37,13 +37,17 @@ import liquibase.resource.ResourceAccessor;
import org.traccar.Config;
import org.traccar.helper.Log;
import org.traccar.model.AttributeAlias;
+import org.traccar.model.AttributePermission;
import org.traccar.model.Calendar;
import org.traccar.model.CalendarPermission;
+import org.traccar.model.Attribute;
import org.traccar.model.Device;
+import org.traccar.model.DeviceAttribute;
import org.traccar.model.DevicePermission;
import org.traccar.model.Event;
import org.traccar.model.Geofence;
import org.traccar.model.Group;
+import org.traccar.model.GroupAttribute;
import org.traccar.model.GroupGeofence;
import org.traccar.model.GroupPermission;
import org.traccar.model.Notification;
@@ -552,4 +556,84 @@ public class DataManager {
.executeUpdate();
}
+ public Collection<Attribute> getAttributes() throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectAttributes"))
+ .executeQuery(Attribute.class);
+ }
+
+ public void addAttribute(Attribute attribute) throws SQLException {
+ attribute.setId(QueryBuilder.create(dataSource, getQuery("database.insertAttribute"), true)
+ .setObject(attribute)
+ .executeUpdate());
+ }
+
+ public void updateAttribute(Attribute attribute) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.updateAttribute"))
+ .setObject(attribute)
+ .executeUpdate();
+ }
+
+ public void removeAttribute(long computedAttributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.deleteAttribute"))
+ .setLong("id", computedAttributeId)
+ .executeUpdate();
+ }
+
+ public Collection<AttributePermission> getAttributePermissions() throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectAttributePermissions"))
+ .executeQuery(AttributePermission.class);
+ }
+
+ public void linkAttribute(long userId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.linkAttribute"))
+ .setLong("userId", userId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
+ public void unlinkAttribute(long userId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.unlinkAttribute"))
+ .setLong("userId", userId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
+ public Collection<GroupAttribute> getGroupAttributes() throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectGroupAttributes"))
+ .executeQuery(GroupAttribute.class);
+ }
+
+ public void linkGroupAttribute(long groupId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.linkGroupAttribute"))
+ .setLong("groupId", groupId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
+ public void unlinkGroupAttribute(long groupId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.unlinkGroupAttribute"))
+ .setLong("groupId", groupId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
+ public Collection<DeviceAttribute> getDeviceAttributes() throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectDeviceAttributes"))
+ .executeQuery(DeviceAttribute.class);
+ }
+
+ public void linkDeviceAttribute(long deviceId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.linkDeviceAttribute"))
+ .setLong("deviceId", deviceId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
+ public void unlinkDeviceAttribute(long deviceId, long attributeId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.unlinkDeviceAttribute"))
+ .setLong("deviceId", deviceId)
+ .setLong("attributeId", attributeId)
+ .executeUpdate();
+ }
+
}