aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 0dc3c5c52..239fc1930 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -525,6 +525,33 @@ public class DataManager implements IdentityManager {
.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 ); //Subtract histDays days
+ //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);