diff options
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 530ec1779..c98a5ede7 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; @@ -385,6 +386,24 @@ 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); |