aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-01 14:37:26 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-01 14:37:26 +1300
commita4fb24732188e4e0b7cc44079eea02c85e142028 (patch)
treea2fdc0e6f92d7bfafe2f4e39b01133c2a09fc748 /src/org/traccar/database/DataManager.java
parent40a607faa34d3c21d7b6d8275279fc8ce3c96980 (diff)
downloadtraccar-server-a4fb24732188e4e0b7cc44079eea02c85e142028.tar.gz
traccar-server-a4fb24732188e4e0b7cc44079eea02c85e142028.tar.bz2
traccar-server-a4fb24732188e4e0b7cc44079eea02c85e142028.zip
Refactor base and other resource classes
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java72
1 files changed, 15 insertions, 57 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 31d7155d3..f01280836 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -278,12 +278,19 @@ public class DataManager implements IdentityManager {
}
}
+ @Deprecated
public void removeUser(User user) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.deleteUser"))
.setObject(user)
.executeUpdate();
}
+ public void removeUser(long userId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.deleteUser"))
+ .setLong("id", userId)
+ .executeUpdate();
+ }
+
public Collection<Permission> getPermissions() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.getPermissionsAll"))
.executeQuery(new Permission());
@@ -318,6 +325,7 @@ public class DataManager implements IdentityManager {
.executeUpdate();
}
+ @Deprecated
public void removeDevice(Device device) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.deleteDevice"))
.setObject(device)
@@ -325,6 +333,13 @@ public class DataManager implements IdentityManager {
AsyncServlet.sessionRefreshDevice(device.getId());
}
+ public void removeDevice(long deviceId) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.deleteDevice"))
+ .setLong("id", deviceId)
+ .executeUpdate();
+ AsyncServlet.sessionRefreshDevice(deviceId);
+ }
+
public void linkDevice(long userId, long deviceId) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.linkDevice"))
.setLong("userId", userId)
@@ -387,61 +402,4 @@ 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);
- }
- }
}