diff options
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 0aecaf2e7..e5a245568 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -398,6 +398,33 @@ public class DataManager { .executeQuery(Position.class); } + public void clearPositionsHistory() throws SQLException { + //SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd"); + 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 ); + //String dt = s.format(dateBefore); + + 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); |