aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-05-27 17:14:47 +0500
committerAbyss777 <abyss@fox5.ru>2016-05-27 17:14:47 +0500
commit6e00239038002aa383cce39be7f53b85f3d03a94 (patch)
tree6b32aab5891ba74b2fba550b29601a6d5c373273 /src/org/traccar
parentc6cc8a87eb593dbf765814d1aaa09d5d231fa7fe (diff)
downloadtraccar-server-6e00239038002aa383cce39be7f53b85f3d03a94.tar.gz
traccar-server-6e00239038002aa383cce39be7f53b85f3d03a94.tar.bz2
traccar-server-6e00239038002aa383cce39be7f53b85f3d03a94.zip
- Synchronization device cache on updateLatestPosition and updateDeviceStatus
- Better latest position identification in BaseEventHandler
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/BaseEventHandler.java10
-rw-r--r--src/org/traccar/database/DataManager.java5
2 files changed, 12 insertions, 3 deletions
diff --git a/src/org/traccar/BaseEventHandler.java b/src/org/traccar/BaseEventHandler.java
index 3c2016af0..fde57748c 100644
--- a/src/org/traccar/BaseEventHandler.java
+++ b/src/org/traccar/BaseEventHandler.java
@@ -1,5 +1,6 @@
package org.traccar;
+import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -14,9 +15,12 @@ public abstract class BaseEventHandler extends BaseDataHandler {
@Override
protected Position handlePosition(Position position) {
- Position lastPosition = Context.getConnectionManager().getLastPosition(position.getDeviceId());
- if (lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0) {
- isLastPosition = true;
+ Device device = Context.getDataManager().getDeviceById(position.getDeviceId());
+ if (device != null) {
+ long lastPositionId = device.getPositionId();
+ if (position.getId() == lastPositionId) {
+ isLastPosition = true;
+ }
}
Event event = analizePosition(position);
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 4e14f6c97..fcb8899bc 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -358,6 +358,9 @@ public class DataManager implements IdentityManager {
QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus"))
.setObject(device)
.executeUpdate();
+ Device cachedDevice = getDeviceById(device.getId());
+ cachedDevice.setStatus(device.getStatus());
+ cachedDevice.setMotion(device.getMotion());
}
public void removeDevice(long deviceId) throws SQLException {
@@ -466,6 +469,8 @@ public class DataManager implements IdentityManager {
.setDate("now", new Date())
.setObject(position)
.executeUpdate();
+ Device device = getDeviceById(position.getDeviceId());
+ device.setPositionId(position.getId());
}
public Collection<Position> getLatestPositions() throws SQLException {