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.java46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index 02adb0455..8be53ad7b 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.SQLException;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -48,6 +47,7 @@ import org.traccar.model.GroupPermission;
import org.traccar.model.Notification;
import org.traccar.model.Position;
import org.traccar.model.Server;
+import org.traccar.model.Statistics;
import org.traccar.model.User;
import org.traccar.model.DeviceGeofence;
import org.traccar.model.GeofencePermission;
@@ -159,12 +159,6 @@ public class DataManager {
.executeQuery(User.class);
}
- public User getUser(long userId) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectUser"))
- .setLong("id", userId)
- .executeQuerySingle(User.class);
- }
-
public void addUser(User user) throws SQLException {
user.setId(QueryBuilder.create(dataSource, getQuery("database.insertUser"), true)
.setObject(user)
@@ -286,6 +280,12 @@ public class DataManager {
.executeQuery(Position.class);
}
+ public Position getPosition(long positionId) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectPosition"))
+ .setLong("id", positionId)
+ .executeQuerySingle(Position.class);
+ }
+
public void addPosition(Position position) throws SQLException {
position.setId(QueryBuilder.create(dataSource, getQuery("database.insertPosition"), true)
.setDate("now", new Date())
@@ -337,33 +337,19 @@ public class DataManager {
.executeUpdate());
}
- public Collection<Event> getEvents(long deviceId, String type, Date from, Date to) throws SQLException {
+ public Collection<Event> getEvents(long deviceId, 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 from = calendar.getTime();
- return getEvents(deviceId, type, from, new Date());
- }
-
public Collection<Geofence> getGeofences() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectGeofencesAll"))
.executeQuery(Geofence.class);
}
- public Geofence getGeofence(long geofenceId) throws SQLException {
- return QueryBuilder.create(dataSource, getQuery("database.selectGeofences"))
- .setLong("id", geofenceId)
- .executeQuerySingle(Geofence.class);
- }
-
public void addGeofence(Geofence geofence) throws SQLException {
geofence.setId(QueryBuilder.create(dataSource, getQuery("database.insertGeofence"), true)
.setObject(geofence)
@@ -484,4 +470,18 @@ public class DataManager {
.setLong("id", attributeAliasId)
.executeUpdate();
}
+
+ public Collection<Statistics> getStatistics(Date from, Date to) throws SQLException {
+ return QueryBuilder.create(dataSource, getQuery("database.selectStatistics"))
+ .setDate("from", from)
+ .setDate("to", to)
+ .executeQuery(Statistics.class);
+ }
+
+ public void addStatistics(Statistics statistics) throws SQLException {
+ statistics.setId(QueryBuilder.create(dataSource, getQuery("database.insertStatistics"), true)
+ .setObject(statistics)
+ .executeUpdate());
+ }
+
}