aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml4
-rw-r--r--src/org/traccar/database/ConnectionManager.java15
-rw-r--r--src/org/traccar/database/DataManager.java6
3 files changed, 22 insertions, 3 deletions
diff --git a/debug.xml b/debug.xml
index 47f17bdae..b09a73d0a 100644
--- a/debug.xml
+++ b/debug.xml
@@ -209,6 +209,10 @@
UPDATE device SET name = :name, uniqueId = :uniqueId WHERE id = :id;
</entry>
+ <entry key='database.updateDeviceStatus'>
+ UPDATE device SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
+ </entry>
+
<entry key='database.deleteDevice'>
DELETE FROM device WHERE id = :id;
</entry>
diff --git a/src/org/traccar/database/ConnectionManager.java b/src/org/traccar/database/ConnectionManager.java
index 450f2f61f..cb7b4b6d8 100644
--- a/src/org/traccar/database/ConnectionManager.java
+++ b/src/org/traccar/database/ConnectionManager.java
@@ -26,6 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.netty.channel.Channel;
+import org.traccar.Context;
import org.traccar.Protocol;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -68,9 +69,17 @@ public class ConnectionManager {
}
public synchronized void updateDevice(long deviceId, String status, Date time) {
- // TODO update cache and call listener
- /*Log.debug(deviceId + " " + status + " "
- + new SimpleDateFormat(Log.DATE_FORMAT).format(time));*/
+ Device device = Context.getIdentityManager().getDeviceById(deviceId);
+ device.setStatus(status);
+ device.setLastUpdate(time);
+
+ try {
+ Context.getDataManager().updateDeviceStatus(device);
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
+
+ // TODO call listener
}
public synchronized void updatePosition(Position position) {
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 24a07a05c..a40b87d24 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -310,6 +310,12 @@ public class DataManager implements IdentityManager {
.executeUpdate();
}
+ public void updateDeviceStatus(Device device) throws SQLException {
+ QueryBuilder.create(dataSource, getQuery("database.updateDeviceStatus"))
+ .setObject(device)
+ .executeUpdate();
+ }
+
public void removeDevice(Device device) throws SQLException {
QueryBuilder.create(dataSource, getQuery("database.deleteDevice"))
.setObject(device)