diff options
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 64 |
1 files changed, 41 insertions, 23 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index abc48f063..afa8b1677 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com) + * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.sql.SQLException; -import java.util.Calendar; import java.util.Collection; import java.util.Date; @@ -37,6 +36,7 @@ import liquibase.resource.ResourceAccessor; import org.traccar.Config; import org.traccar.helper.Log; +import org.traccar.model.AttributeAlias; import org.traccar.model.Device; import org.traccar.model.DevicePermission; import org.traccar.model.Event; @@ -47,6 +47,7 @@ import org.traccar.model.GroupPermission; import org.traccar.model.Notification; import org.traccar.model.Position; import org.traccar.model.Server; +import org.traccar.model.Statistics; import org.traccar.model.User; import org.traccar.model.DeviceGeofence; import org.traccar.model.GeofencePermission; @@ -158,12 +159,6 @@ public class DataManager { .executeQuery(User.class); } - public User getUser(long userId) throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectUser")) - .setLong("id", userId) - .executeQuerySingle(User.class); - } - public void addUser(User user) throws SQLException { user.setId(QueryBuilder.create(dataSource, getQuery("database.insertUser"), true) .setObject(user) @@ -336,33 +331,19 @@ public class DataManager { .executeUpdate()); } - public Collection<Event> getEvents(long deviceId, String type, Date from, Date to) throws SQLException { + public Collection<Event> getEvents(long deviceId, Date from, Date to) throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectEvents")) .setLong("deviceId", deviceId) - .setString("type", type) .setDate("from", from) .setDate("to", to) .executeQuery(Event.class); } - public Collection<Event> getLastEvents(long deviceId, String type, int interval) throws SQLException { - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.SECOND, -interval); - Date from = calendar.getTime(); - return getEvents(deviceId, type, from, new Date()); - } - public Collection<Geofence> getGeofences() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectGeofencesAll")) .executeQuery(Geofence.class); } - public Geofence getGeofence(long geofenceId) throws SQLException { - return QueryBuilder.create(dataSource, getQuery("database.selectGeofences")) - .setLong("id", geofenceId) - .executeQuerySingle(Geofence.class); - } - public void addGeofence(Geofence geofence) throws SQLException { geofence.setId(QueryBuilder.create(dataSource, getQuery("database.insertGeofence"), true) .setObject(geofence) @@ -460,4 +441,41 @@ public class DataManager { .setLong("id", notification.getId()) .executeUpdate(); } + + public Collection<AttributeAlias> getAttributeAliases() throws SQLException { + return QueryBuilder.create(dataSource, getQuery("database.selectAttributeAliases")) + .executeQuery(AttributeAlias.class); + } + + public void addAttributeAlias(AttributeAlias attributeAlias) throws SQLException { + attributeAlias.setId(QueryBuilder.create(dataSource, getQuery("database.insertAttributeAlias"), true) + .setObject(attributeAlias) + .executeUpdate()); + } + + public void updateAttributeAlias(AttributeAlias attributeAlias) throws SQLException { + QueryBuilder.create(dataSource, getQuery("database.updateAttributeAlias")) + .setObject(attributeAlias) + .executeUpdate(); + } + + public void removeAttributeAlias(long attributeAliasId) throws SQLException { + QueryBuilder.create(dataSource, getQuery("database.deleteAttributeAlias")) + .setLong("id", attributeAliasId) + .executeUpdate(); + } + + public Collection<Statistics> getStatistics(Date from, Date to) throws SQLException { + return QueryBuilder.create(dataSource, getQuery("database.selectStatistics")) + .setDate("from", from) + .setDate("to", to) + .executeQuery(Statistics.class); + } + + public void addStatistics(Statistics statistics) throws SQLException { + statistics.setId(QueryBuilder.create(dataSource, getQuery("database.insertStatistics"), true) + .setObject(statistics) + .executeUpdate()); + } + } |