diff options
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 58 | ||||
-rw-r--r-- | src/org/traccar/database/PermissionsManager.java | 8 |
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); + } + } } |