From a4fb24732188e4e0b7cc44079eea02c85e142028 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 1 Dec 2015 14:37:26 +1300 Subject: Refactor base and other resource classes --- src/org/traccar/database/DataManager.java | 72 +++++++------------------------ 1 file changed, 15 insertions(+), 57 deletions(-) (limited to 'src/org/traccar/database') 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 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 Collection get(Class clazz) throws SQLException { - if (clazz.equals(User.class)) { - return (Collection) getUsers(); - } else if (clazz.equals(Device.class)) { - return (Collection) getAllDevices(); - } - return null; - } - - public 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); - } - } } -- cgit v1.2.3