aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database/DataManager.java
diff options
context:
space:
mode:
authordrecchia <danilo@deltatecnologia.com>2016-06-01 21:08:05 -0300
committerdrecchia <danilo@deltatecnologia.com>2016-06-01 21:08:05 -0300
commite4ba1ebf54838041fae352d95e399b1fb3483458 (patch)
tree334626820ff4efa4583bb5257d19a18cd0ebf631 /src/org/traccar/database/DataManager.java
parent5df7c128af15e9d1021b7570f081185f14467f09 (diff)
parentd2c85b59bde4729d027ef1bb6e874d1fd1a02c68 (diff)
downloadtrackermap-server-e4ba1ebf54838041fae352d95e399b1fb3483458.tar.gz
trackermap-server-e4ba1ebf54838041fae352d95e399b1fb3483458.tar.bz2
trackermap-server-e4ba1ebf54838041fae352d95e399b1fb3483458.zip
Merge branch 'master' of https://github.com/tananaev/traccar
Conflicts: src/org/traccar/database/DataManager.java
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r--src/org/traccar/database/DataManager.java36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 19560db5c..839cf8cad 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -21,6 +21,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -46,6 +47,7 @@ import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.DevicePermission;
+import org.traccar.model.Event;
import org.traccar.model.Group;
import org.traccar.model.GroupPermission;
import org.traccar.model.Position;
@@ -363,6 +365,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 {
@@ -471,6 +476,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 {
@@ -488,4 +495,33 @@ public class DataManager implements IdentityManager {
.setObject(server)
.executeUpdate();
}
+
+ public Event getEvent(long eventId) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectEvent"))
+ .setLong("id", eventId)
+ .executeQuerySingle(Event.class);
+ }
+
+ public void addEvent(Event event) throws SQLException {
+ event.setId(QueryBuilder.create(dataSource, getQuery("database.insertEvent"), true)
+ .setObject(event)
+ .executeUpdate());
+ }
+
+ public Collection<Event> getEvents(long deviceId, String type, Date from, Date to) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectEvents"))
+ .setLong("deviceId", deviceId)
+ .setString("type", type)
+ .setDate("from", from)
+ .setDate("to", to)
+ .executeQuery(Event.class);
+ }
+
+ public Collection<Event> getLastEvents(long deviceId, String type, int interval) throws SQLException {
+ Calendar calendar = Calendar.getInstance();
+ calendar.add(Calendar.SECOND, -interval);
+ Date to = calendar.getTime();
+ return getEvents(deviceId, type, new Date(), to);
+ }
+
}