aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r--src/main/java/org/traccar/database/DataManager.java24
-rw-r--r--src/main/java/org/traccar/database/DeviceManager.java93
-rw-r--r--src/main/java/org/traccar/database/IdentityManager.java5
3 files changed, 2 insertions, 120 deletions
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index aa600e375..f80f429e1 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -24,20 +24,17 @@ import org.traccar.storage.Storage;
import org.traccar.storage.StorageException;
import org.traccar.storage.query.Columns;
import org.traccar.storage.query.Condition;
-import org.traccar.storage.query.Limit;
-import org.traccar.storage.query.Order;
import org.traccar.storage.query.Request;
import javax.inject.Inject;
import java.util.Collection;
-import java.util.Date;
public class DataManager {
private final Storage storage;
@Inject
- public DataManager(Storage storage) throws Exception {
+ public DataManager(Storage storage) {
this.storage = storage;
}
@@ -47,25 +44,6 @@ public class DataManager {
new Condition.Equals("id", "id")));
}
- public Position getPrecedingPosition(long deviceId, Date date) throws StorageException {
- return storage.getObject(Position.class, new Request(
- new Columns.All(),
- new Condition.And(
- new Condition.Equals("deviceId", "deviceId", deviceId),
- new Condition.Compare("fixTime", "<=", "time", date)),
- new Order(true, "fixTime"),
- new Limit(1)));
- }
-
- public void updateLatestPosition(Position position) throws StorageException {
- Device device = new Device();
- device.setId(position.getDeviceId());
- device.setPositionId(position.getId());
- storage.updateObject(device, new Request(
- new Columns.Include("positionId"),
- new Condition.Equals("id", "id")));
- }
-
public Collection<Position> getLatestPositions() throws StorageException {
return storage.getObjects(Position.class, new Request(
new Columns.All(),
diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java
index 841915f1c..4516255c1 100644
--- a/src/main/java/org/traccar/database/DeviceManager.java
+++ b/src/main/java/org/traccar/database/DeviceManager.java
@@ -15,21 +15,13 @@
*/
package org.traccar.database;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.traccar.Context;
import org.traccar.config.Config;
import org.traccar.config.Keys;
import org.traccar.model.Device;
-import org.traccar.model.Position;
-import org.traccar.session.ConnectionManager;
import org.traccar.session.DeviceState;
import org.traccar.storage.StorageException;
import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@@ -37,23 +29,15 @@ import java.util.concurrent.atomic.AtomicLong;
public class DeviceManager extends BaseObjectManager<Device> implements IdentityManager {
- private static final Logger LOGGER = LoggerFactory.getLogger(DeviceManager.class);
-
- private final ConnectionManager connectionManager;
private final long dataRefreshDelay;
private final AtomicLong devicesLastUpdate = new AtomicLong();
- private final Map<Long, Position> positions = new ConcurrentHashMap<>();
-
private final Map<Long, DeviceState> deviceStates = new ConcurrentHashMap<>();
- public DeviceManager(
- Config config, DataManager dataManager, ConnectionManager connectionManager) {
+ public DeviceManager(Config config, DataManager dataManager) {
super(dataManager, Device.class);
- this.connectionManager = connectionManager;
dataRefreshDelay = config.getLong(Keys.DATABASE_REFRESH_DELAY) * 1000;
- refreshLastPositions();
}
public void updateDeviceCache(boolean force) {
@@ -78,25 +62,6 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
return getItems(getAllItems());
}
- public Set<Long> getAllUserItems(long userId) {
- return Context.getPermissionsManager().getDevicePermissions(userId);
- }
-
- public Set<Long> getUserItems(long userId) {
- if (Context.getPermissionsManager() != null) {
- Set<Long> result = new HashSet<>();
- for (long deviceId : Context.getPermissionsManager().getDevicePermissions(userId)) {
- Device device = getById(deviceId);
- if (device != null && !device.getDisabled()) {
- result.add(deviceId);
- }
- }
- return result;
- } else {
- return new HashSet<>();
- }
- }
-
@Override
protected void updateCachedItem(Device device) {
Device cachedDevice = getById(device.getId());
@@ -117,7 +82,6 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
if (cachedDevice != null) {
super.removeCachedItem(deviceId);
}
- positions.remove(deviceId);
}
public void updateDeviceStatus(Device device) throws StorageException {
@@ -128,61 +92,6 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
}
}
- private void refreshLastPositions() {
- if (getDataManager() != null) {
- try {
- for (Position position : getDataManager().getLatestPositions()) {
- positions.put(position.getDeviceId(), position);
- }
- } catch (StorageException error) {
- LOGGER.warn("Load latest positions error", error);
- }
- }
- }
-
- public boolean isLatestPosition(Position position) {
- Position lastPosition = getLastPosition(position.getDeviceId());
- return lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) >= 0;
- }
-
- public void updateLatestPosition(Position position) throws StorageException {
-
- if (isLatestPosition(position)) {
-
- getDataManager().updateLatestPosition(position);
-
- Device device = getById(position.getDeviceId());
- if (device != null) {
- device.setPositionId(position.getId());
- }
-
- positions.put(position.getDeviceId(), position);
-
- connectionManager.updatePosition(position);
- }
- }
-
- @Override
- public Position getLastPosition(long deviceId) {
- return positions.get(deviceId);
- }
-
- public Collection<Position> getInitialState(long userId) {
-
- List<Position> result = new LinkedList<>();
-
- if (Context.getPermissionsManager() != null) {
- for (long deviceId : Context.getPermissionsManager().getUserAdmin(userId)
- ? getAllUserItems(userId) : getUserItems(userId)) {
- if (positions.containsKey(deviceId)) {
- result.add(positions.get(deviceId));
- }
- }
- }
-
- return result;
- }
-
public DeviceState getDeviceState(long deviceId) {
DeviceState deviceState = deviceStates.get(deviceId);
if (deviceState == null) {
diff --git a/src/main/java/org/traccar/database/IdentityManager.java b/src/main/java/org/traccar/database/IdentityManager.java
index b42d4c292..1e0eb00c5 100644
--- a/src/main/java/org/traccar/database/IdentityManager.java
+++ b/src/main/java/org/traccar/database/IdentityManager.java
@@ -16,14 +16,9 @@
package org.traccar.database;
import org.traccar.model.Device;
-import org.traccar.model.Position;
public interface IdentityManager {
Device getById(long id);
- Position getLastPosition(long deviceId);
-
- boolean isLatestPosition(Position position);
-
}