aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/storage
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-04 06:33:02 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-04 06:33:02 -0700
commitec76482c15094a7e04964c67d3011a7e8e1ad6a9 (patch)
tree3ef0d23e1b9f4ba7ef02f68b08db33f3db1972ab /src/main/java/org/traccar/storage
parent4030d3207c157a3fcee2653c18440898b6b2a2e6 (diff)
downloadtrackermap-server-ec76482c15094a7e04964c67d3011a7e8e1ad6a9.tar.gz
trackermap-server-ec76482c15094a7e04964c67d3011a7e8e1ad6a9.tar.bz2
trackermap-server-ec76482c15094a7e04964c67d3011a7e8e1ad6a9.zip
Refactor commands manager
Diffstat (limited to 'src/main/java/org/traccar/storage')
-rw-r--r--src/main/java/org/traccar/storage/DatabaseStorage.java16
-rw-r--r--src/main/java/org/traccar/storage/query/Condition.java16
2 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/storage/DatabaseStorage.java b/src/main/java/org/traccar/storage/DatabaseStorage.java
index 91dd6b077..fc468182e 100644
--- a/src/main/java/org/traccar/storage/DatabaseStorage.java
+++ b/src/main/java/org/traccar/storage/DatabaseStorage.java
@@ -209,6 +209,11 @@ public class DatabaseStorage extends Storage {
} else {
results.put(Permission.getKey(condition.getPropertyClass()), condition.getPropertyId());
}
+ } else if (genericCondition instanceof Condition.LatestPositions) {
+ var condition = (Condition.LatestPositions) genericCondition;
+ if (condition.getDeviceId() > 0) {
+ results.put("deviceId", condition.getDeviceId());
+ }
}
return results;
}
@@ -262,6 +267,17 @@ public class DatabaseStorage extends Storage {
result.append(formatPermissionQuery(condition));
result.append(")");
+ } else if (genericCondition instanceof Condition.LatestPositions) {
+
+ var condition = (Condition.LatestPositions) genericCondition;
+ result.append("id IN (");
+ result.append("SELECT positionId FROM ");
+ result.append(getStorageName(Device.class));
+ if (condition.getDeviceId() > 0) {
+ result.append(" WHERE id = :deviceId");
+ }
+ result.append(")");
+
}
}
return result.toString();
diff --git a/src/main/java/org/traccar/storage/query/Condition.java b/src/main/java/org/traccar/storage/query/Condition.java
index 91ede236c..136b0402b 100644
--- a/src/main/java/org/traccar/storage/query/Condition.java
+++ b/src/main/java/org/traccar/storage/query/Condition.java
@@ -196,4 +196,20 @@ public interface Condition {
}
}
+ class LatestPositions implements Condition {
+ private final long deviceId;
+
+ public LatestPositions(long deviceId) {
+ this.deviceId = deviceId;
+ }
+
+ public LatestPositions() {
+ this(0);
+ }
+
+ public long getDeviceId() {
+ return deviceId;
+ }
+ }
+
}