aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-30 13:55:05 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-30 13:55:05 +1300
commitcefc12afe98f610aa0f266bcac4361f9ec414ee5 (patch)
tree48d47a0eec0c2d8a3ee7f448f8d535d7d826d546 /src/org/traccar/database
parentc6692703c8099577cb86c3eace5d8d1bc11f212d (diff)
parent1a25796d62bdf88f2cba0387a09e2eb71599e588 (diff)
downloadtrackermap-server-cefc12afe98f610aa0f266bcac4361f9ec414ee5.tar.gz
trackermap-server-cefc12afe98f610aa0f266bcac4361f9ec414ee5.tar.bz2
trackermap-server-cefc12afe98f610aa0f266bcac4361f9ec414ee5.zip
Merge master of guterresrafael/traccar into rest
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/DataManager.java58
-rw-r--r--src/org/traccar/database/PermissionsManager.java8
2 files changed, 66 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index da87c6c27..31d7155d3 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -31,6 +31,7 @@ import java.util.Map;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import org.traccar.Config;
+import org.traccar.helper.Clazz;
import org.traccar.helper.DriverDelegate;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -386,4 +387,61 @@ public class DataManager implements IdentityManager {
.executeUpdate();
}
+ public <T> Collection<T> get(Class<T> clazz) throws SQLException {
+ if (clazz.equals(User.class)) {
+ return (Collection<T>) getUsers();
+ } else if (clazz.equals(Device.class)) {
+ return (Collection<T>) getAllDevices();
+ }
+ return null;
+ }
+
+ public <T> T get(T entity) throws Exception {
+ if (entity instanceof User) {
+ return (T) getUser(Clazz.getId(entity));
+ } else if (entity instanceof Device) {
+ return (T) getDeviceById(Clazz.getId(entity));
+ }
+ return null;
+ }
+
+ public void add(Object entity) throws SQLException {
+ if (entity instanceof User) {
+ addUser((User) entity);
+ } else if (entity instanceof Device) {
+ addDevice((Device) entity);
+ } else if (entity instanceof Position) {
+ addPosition((Position) entity);
+ }
+ }
+
+ public void update(Object entity) throws SQLException {
+ if (entity instanceof User) {
+ updateUser((User) entity);
+ } else if (entity instanceof Device) {
+ updateDevice((Device) entity);
+ } else if (entity instanceof Server) {
+ updateServer((Server) entity);
+ }
+ }
+
+ public void remove(Object entity) throws SQLException {
+ if (entity instanceof User) {
+ removeUser((User) entity);
+ } else if (entity instanceof Device) {
+ removeDevice((Device) entity);
+ }
+ }
+
+ public void link(Class clazz, long userId, long entityId) throws SQLException {
+ if (clazz.equals(Device.class)) {
+ linkDevice(userId, entityId);
+ }
+ }
+
+ public void unlink(Class clazz, long userId, long entityId) throws SQLException {
+ if (clazz.equals(Device.class)) {
+ unlinkDevice(userId, entityId);
+ }
+ }
}
diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java
index a38a29c32..0a43f4ff4 100644
--- a/src/org/traccar/database/PermissionsManager.java
+++ b/src/org/traccar/database/PermissionsManager.java
@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.traccar.helper.Log;
+import org.traccar.model.Device;
import org.traccar.model.Permission;
import org.traccar.model.User;
@@ -82,4 +83,11 @@ public class PermissionsManager {
}
}
+ public <T> void check(Class<T> clazz, long userId, long entityId) throws SecurityException {
+ if (clazz.equals(User.class)) {
+ checkUser(userId, entityId);
+ } else if (clazz.equals(Device.class)) {
+ checkDevice(userId, entityId);
+ }
+ }
}