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.java16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 7fd672849..a9fc09448 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -521,22 +521,24 @@ public class DataManager implements IdentityManager {
.executeQuery(Position.class);
}
- //added by Erez
public void clearPositionsHistory() throws SQLException {
//SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
- String histDays = config.getString("database.positionsHistoryDays");
- if (histDays == null) {
- histDays = "7";
+ int histDays = config.getInteger("database.positionsHistoryDays");
+ if (histDays == 0) {
+ return;
+ }
+
+ String sql = getQuery("database.clearPositionsHistory");
+ if (sql == null) {
+ return;
}
- int n = Integer.parseInt(histDays);
for (Device device : getAllDevices()) {
Date lastUpdate = device.getLastUpdate();
if(lastUpdate != null){
- Date dateBefore = new Date(lastUpdate.getTime() - n * 24 * 3600 * 1000 ); //Subtract n days
+ Date dateBefore = new Date(lastUpdate.getTime() - histDays * 24 * 3600 * 1000 ); //Subtract histDays days
//String dt = s.format(dateBefore);
- String sql = "DELETE FROM positions WHERE deviceid=:deviceId and servertime<:serverTime";
QueryBuilder.create(dataSource, sql)
.setLong("deviceId", device.getId())