aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
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/DataManager.java
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/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);
+ }
+ }
}