diff options
author | Abyss777 <abyss@fox5.ru> | 2017-05-10 13:27:49 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-05-12 17:55:01 +0500 |
commit | 6c17f85d04b224ff2a09265918765c9f4fc8cf94 (patch) | |
tree | 5bbebd7f66b5af547267751fdb4de21283489716 /src/org/traccar/database/DataManager.java | |
parent | 4ce5dd893d3b95fc759fd1d0e0dbf09d0d559936 (diff) | |
download | trackermap-server-6c17f85d04b224ff2a09265918765c9f4fc8cf94.tar.gz trackermap-server-6c17f85d04b224ff2a09265918765c9f4fc8cf94.tar.bz2 trackermap-server-6c17f85d04b224ff2a09265918765c9f4fc8cf94.zip |
Implement computed attributes
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 0c5f458a2..acbaac17b 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; @@ -548,4 +552,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(); + } + } |