diff options
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 0aecaf2e7..3c8529eff 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -398,6 +398,31 @@ public class DataManager { .executeQuery(Position.class); } + public void clearPositionsHistory() throws SQLException { + int histDays = config.getInteger("database.positionsHistoryDays"); + if (histDays == 0) { + return; + } + + String sql = getQuery("database.clearPositionsHistory"); + if (sql == null) { + return; + } + + for (Device device : getAllDevices()) { + Date lastUpdate = device.getLastUpdate(); + if(lastUpdate != null){ + + Date dateBefore = new Date(lastUpdate.getTime() - histDays * 24 * 3600 * 1000); + + QueryBuilder.create(dataSource, sql) + .setLong("deviceId", device.getId()) + .setDate("serverTime", dateBefore) + .executeUpdate(); + } + } + } + public Server getServer() throws SQLException { return QueryBuilder.create(dataSource, getQuery("database.selectServers")) .executeQuerySingle(Server.class); |