aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java58
1 files changed, 58 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);
+ }
+ }
}