From d6c7cdf1e103c977ed94b737dc838d7ac22b9fa7 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 16:25:34 +0500 Subject: Optimize caching and class structure --- src/org/traccar/database/AttributesManager.java | 7 +--- src/org/traccar/database/CalendarManager.java | 1 - src/org/traccar/database/DriversManager.java | 27 ++------------- .../traccar/database/ExtendedObjectManager.java | 1 + src/org/traccar/database/GeofenceManager.java | 2 -- src/org/traccar/database/SimpleObjectManager.java | 39 +++++++++++++++------- 6 files changed, 31 insertions(+), 46 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/AttributesManager.java b/src/org/traccar/database/AttributesManager.java index 266fc5526..4dc70eeb7 100644 --- a/src/org/traccar/database/AttributesManager.java +++ b/src/org/traccar/database/AttributesManager.java @@ -16,8 +16,6 @@ */ package org.traccar.database; -import java.sql.SQLException; - import org.traccar.model.Attribute; import org.traccar.model.BaseModel; @@ -25,14 +23,11 @@ public class AttributesManager extends ExtendedObjectManager { public AttributesManager(DataManager dataManager) { super(dataManager, Attribute.class); - refreshItems(); - refreshExtendedPermissions(); } @Override - public void updateItem(BaseModel item) throws SQLException { + public void updateCachedItem(BaseModel item) { Attribute attribute = (Attribute) item; - getDataManager().updateObject(attribute); Attribute cachedAttribute = (Attribute) getById(item.getId()); cachedAttribute.setDescription(attribute.getDescription()); cachedAttribute.setAttribute(attribute.getAttribute()); diff --git a/src/org/traccar/database/CalendarManager.java b/src/org/traccar/database/CalendarManager.java index 80bb79db2..6874020ec 100644 --- a/src/org/traccar/database/CalendarManager.java +++ b/src/org/traccar/database/CalendarManager.java @@ -22,7 +22,6 @@ public class CalendarManager extends SimpleObjectManager { public CalendarManager(DataManager dataManager) { super(dataManager, Calendar.class); - refreshItems(); } } diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 0dc2b102d..e3ae07a65 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -20,7 +20,6 @@ import java.sql.SQLException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.traccar.helper.Log; import org.traccar.model.Driver; import org.traccar.model.BaseModel; @@ -30,24 +29,6 @@ public class DriversManager extends ExtendedObjectManager { public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); - refreshItems(); - refreshExtendedPermissions(); - } - - @Override - public void refreshItems() { - if (getDataManager() != null) { - try { - clearItems(); - for (BaseModel item : getDataManager().getObjects(getBaseClass())) { - putItem(item.getId(), item); - driversByUniqueId.put(((Driver) item).getUniqueId(), (Driver) item); - } - } catch (SQLException error) { - Log.warning(error); - } - } - refreshUserItems(); } @Override @@ -57,9 +38,8 @@ public class DriversManager extends ExtendedObjectManager { } @Override - public void updateItem(BaseModel item) throws SQLException { + protected void updateCachedItem(BaseModel item) { Driver driver = (Driver) item; - getDataManager().updateObject(driver); Driver cachedDriver = (Driver) getById(driver.getId()); cachedDriver.setName(driver.getName()); if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) { @@ -71,16 +51,13 @@ public class DriversManager extends ExtendedObjectManager { } @Override - public void removeItem(long driverId) throws SQLException { + protected void removeCachedItem(long driverId) { Driver cachedDriver = (Driver) getById(driverId); - getDataManager().removeObject(Driver.class, driverId); if (cachedDriver != null) { String driverUniqueId = cachedDriver.getUniqueId(); removeCachedItem(driverId); driversByUniqueId.remove(driverUniqueId); } - refreshUserItems(); - refreshExtendedPermissions(); } public Driver getDriverByUniqueId(String uniqueId) { diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java index 483c3a09e..a9dc7d28a 100644 --- a/src/org/traccar/database/ExtendedObjectManager.java +++ b/src/org/traccar/database/ExtendedObjectManager.java @@ -37,6 +37,7 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager { protected ExtendedObjectManager(DataManager dataManager, Class baseClass) { super(dataManager, baseClass); + refreshExtendedPermissions(); } public final Set getGroupItems(long groupId) { diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java index bc2c27a65..2c3c32c56 100644 --- a/src/org/traccar/database/GeofenceManager.java +++ b/src/org/traccar/database/GeofenceManager.java @@ -27,8 +27,6 @@ public class GeofenceManager extends ExtendedObjectManager { public GeofenceManager(DataManager dataManager) { super(dataManager, Geofence.class); - refreshItems(); - refreshExtendedPermissions(); } @Override diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 0db8af658..49ad4707c 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -33,7 +33,7 @@ public abstract class SimpleObjectManager { private final DataManager dataManager; - private final Map items = new ConcurrentHashMap<>(); + private Map items; private final Map> userItems = new ConcurrentHashMap<>(); private Class baseClass; @@ -43,6 +43,7 @@ public abstract class SimpleObjectManager { this.dataManager = dataManager; this.baseClass = baseClass; baseClassIdName = DataManager.makeNameId(baseClass); + refreshItems(); } protected final DataManager getDataManager() { @@ -65,11 +66,7 @@ public abstract class SimpleObjectManager { items.clear(); } - protected final void putItem(long itemId, BaseModel item) { - items.put(itemId, item); - } - - protected final void removeCachedItem(long itemId) { + protected void removeCachedItem(long itemId) { items.remove(itemId); } @@ -91,9 +88,23 @@ public abstract class SimpleObjectManager { public void refreshItems() { if (dataManager != null) { try { - clearItems(); - for (BaseModel item : dataManager.getObjects(this.baseClass)) { - putItem(item.getId(), item); + Collection databaseItems = dataManager.getObjects(baseClass); + if (items == null) { + items = new ConcurrentHashMap<>(databaseItems.size()); + } + Set databaseItemIds = new HashSet<>(); + for (BaseModel item : databaseItems) { + databaseItemIds.add(item.getId()); + if (items.containsKey(item.getId())) { + updateCachedItem(item); + } else { + items.put(item.getId(), item); + } + } + for (Long cachedItemId : items.keySet()) { + if (!databaseItemIds.contains(cachedItemId)) { + items.remove(cachedItemId); + } } } catch (SQLException error) { Log.warning(error); @@ -118,12 +129,16 @@ public abstract class SimpleObjectManager { public void addItem(BaseModel item) throws SQLException { dataManager.addObject(item); - putItem(item.getId(), item); + items.put(item.getId(), item); + } + + protected void updateCachedItem(BaseModel item) { + items.put(item.getId(), item); } public void updateItem(BaseModel item) throws SQLException { dataManager.updateObject(item); - putItem(item.getId(), item); + updateCachedItem(item); } public void removeItem(long itemId) throws SQLException { @@ -143,7 +158,7 @@ public abstract class SimpleObjectManager { return result; } - public final Set getAllItems() { + public Set getAllItems() { return items.keySet(); } -- cgit v1.2.3 From af00329fd0addf84071927dbc18cb0b4e5345f2b Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 17:02:39 +0500 Subject: Use Permission instead of Map --- src/org/traccar/database/DataManager.java | 8 +++---- .../traccar/database/ExtendedObjectManager.java | 20 +++++++--------- src/org/traccar/database/PermissionsManager.java | 28 ++++++++++------------ src/org/traccar/database/QueryBuilder.java | 11 +++++---- src/org/traccar/database/SimpleObjectManager.java | 8 +++---- 5 files changed, 35 insertions(+), 40 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 80b9f98e9..862efbc91 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -23,7 +23,6 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; -import java.util.Map; import javax.naming.InitialContext; import javax.sql.DataSource; @@ -41,6 +40,7 @@ import org.traccar.helper.Log; import org.traccar.model.AttributeAlias; import org.traccar.model.Device; import org.traccar.model.Event; +import org.traccar.model.Permission; import org.traccar.model.BaseModel; import org.traccar.model.Position; import org.traccar.model.Server; @@ -293,10 +293,10 @@ public class DataManager { return QueryBuilder.create(dataSource, getQuery(query)).executeQuery(clazz); } - public Collection> getPermissions(Class owner, - Class property) throws SQLException { + public Collection getPermissions(Class owner, + Class property) throws SQLException, ClassNotFoundException { String query = "database.select" + owner.getSimpleName() + property.getSimpleName() + "s"; - return QueryBuilder.create(dataSource, getQuery(query)).executeMapQuery(Long.class); + return QueryBuilder.create(dataSource, getQuery(query)).executePermissionsQuery(); } public void addObject(BaseModel entity) throws SQLException { diff --git a/src/org/traccar/database/ExtendedObjectManager.java b/src/org/traccar/database/ExtendedObjectManager.java index a9dc7d28a..2833b3bae 100644 --- a/src/org/traccar/database/ExtendedObjectManager.java +++ b/src/org/traccar/database/ExtendedObjectManager.java @@ -27,6 +27,7 @@ import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Group; +import org.traccar.model.Permission; import org.traccar.model.BaseModel; public abstract class ExtendedObjectManager extends SimpleObjectManager { @@ -79,27 +80,24 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager { if (getDataManager() != null) { try { - Collection> databaseGroupPermissions = + Collection databaseGroupPermissions = getDataManager().getPermissions(Group.class, getBaseClass()); clearGroupItems(); - for (Map groupPermission : databaseGroupPermissions) { - getGroupItems(groupPermission.get(DataManager.makeNameId(Group.class))) - .add(groupPermission.get(getBaseClassIdName())); + for (Permission groupPermission : databaseGroupPermissions) { + getGroupItems(groupPermission.getOwnerId()).add(groupPermission.getPropertyId()); } - Collection> databaseDevicePermissions = + Collection databaseDevicePermissions = getDataManager().getPermissions(Device.class, getBaseClass()); Collection allDevices = Context.getDeviceManager().getAllDevices(); clearDeviceItems(); deviceItemsWithGroups.clear(); - for (Map devicePermission : databaseDevicePermissions) { - getDeviceItems(devicePermission.get(DataManager.makeNameId(Device.class))) - .add(devicePermission.get(getBaseClassIdName())); - getAllDeviceItems(devicePermission.get(DataManager.makeNameId(Device.class))) - .add(devicePermission.get(getBaseClassIdName())); + for (Permission devicePermission : databaseDevicePermissions) { + getDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId()); + getAllDeviceItems(devicePermission.getOwnerId()).add(devicePermission.getPropertyId()); } for (Device device : allDevices) { @@ -114,7 +112,7 @@ public abstract class ExtendedObjectManager extends SimpleObjectManager { } } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } } diff --git a/src/org/traccar/database/PermissionsManager.java b/src/org/traccar/database/PermissionsManager.java index b9cdfc36b..70969d749 100644 --- a/src/org/traccar/database/PermissionsManager.java +++ b/src/org/traccar/database/PermissionsManager.java @@ -115,11 +115,10 @@ public class PermissionsManager { public final void refreshUserPermissions() { userPermissions.clear(); try { - for (Map permission : dataManager.getPermissions(User.class, User.class)) { - getUserPermissions(permission.get(DataManager.makeNameId(User.class))) - .add(permission.get(DataManager.makeNameId(ManagedUser.class))); + for (Permission permission : dataManager.getPermissions(User.class, User.class)) { + getUserPermissions(permission.getOwnerId()).add(permission.getPropertyId()); } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } } @@ -130,23 +129,20 @@ public class PermissionsManager { try { GroupTree groupTree = new GroupTree(Context.getDeviceManager().getAllGroups(), Context.getDeviceManager().getAllDevices()); - for (Map groupPermission : dataManager.getPermissions(User.class, Group.class)) { - Set userGroupPermissions = getGroupPermissions(groupPermission - .get(DataManager.makeNameId(User.class))); - Set userDevicePermissions = getDevicePermissions(groupPermission - .get(DataManager.makeNameId(User.class))); - userGroupPermissions.add(groupPermission.get(DataManager.makeNameId(Group.class))); - for (Group group : groupTree.getGroups(groupPermission.get(DataManager.makeNameId(Group.class)))) { + for (Permission groupPermission : dataManager.getPermissions(User.class, Group.class)) { + Set userGroupPermissions = getGroupPermissions(groupPermission.getOwnerId()); + Set userDevicePermissions = getDevicePermissions(groupPermission.getOwnerId()); + userGroupPermissions.add(groupPermission.getPropertyId()); + for (Group group : groupTree.getGroups(groupPermission.getPropertyId())) { userGroupPermissions.add(group.getId()); } - for (Device device : groupTree.getDevices(groupPermission.get(DataManager.makeNameId(Group.class)))) { + for (Device device : groupTree.getDevices(groupPermission.getPropertyId())) { userDevicePermissions.add(device.getId()); } } - for (Map devicePermission : dataManager.getPermissions(User.class, Device.class)) { - getDevicePermissions(devicePermission.get(DataManager.makeNameId(User.class))) - .add(devicePermission.get(DataManager.makeNameId(Device.class))); + for (Permission devicePermission : dataManager.getPermissions(User.class, Device.class)) { + getDevicePermissions(devicePermission.getOwnerId()).add(devicePermission.getPropertyId()); } groupDevices.clear(); @@ -156,7 +152,7 @@ public class PermissionsManager { } } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 440690a76..af33458a8 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.MiscFormatter; +import org.traccar.model.Permission; import javax.sql.DataSource; import java.io.IOException; @@ -488,19 +489,19 @@ public final class QueryBuilder { return 0; } - public Collection> executeMapQuery(Class clazz) throws SQLException { - List> result = new LinkedList<>(); + public Collection executePermissionsQuery() throws SQLException, ClassNotFoundException { + List result = new LinkedList<>(); if (query != null) { try { try (ResultSet resultSet = statement.executeQuery()) { ResultSetMetaData resultMetaData = resultSet.getMetaData(); while (resultSet.next()) { - LinkedHashMap map = new LinkedHashMap<>(); + LinkedHashMap map = new LinkedHashMap<>(); for (int i = 1; i <= resultMetaData.getColumnCount(); i++) { String label = resultMetaData.getColumnLabel(i); - map.put(label, resultSet.getObject(label, clazz)); + map.put(label, resultSet.getLong(label)); } - result.add(map); + result.add(new Permission(map)); } } } finally { diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 49ad4707c..031f91fc5 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.traccar.Context; import org.traccar.helper.Log; import org.traccar.model.BaseModel; +import org.traccar.model.Permission; import org.traccar.model.User; public abstract class SimpleObjectManager { @@ -117,11 +118,10 @@ public abstract class SimpleObjectManager { if (dataManager != null) { try { clearUserItems(); - for (Map permission : dataManager.getPermissions(User.class, baseClass)) { - getUserItems(permission.get(DataManager.makeNameId(User.class))) - .add(permission.get(baseClassIdName)); + for (Permission permission : dataManager.getPermissions(User.class, baseClass)) { + getUserItems(permission.getOwnerId()).add(permission.getPropertyId()); } - } catch (SQLException error) { + } catch (SQLException | ClassNotFoundException error) { Log.warning(error); } } -- cgit v1.2.3 From 6e08953f5a482b6cecc439bd79b94c03638f77cf Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 17:03:54 +0500 Subject: Fix group cache update --- src/org/traccar/database/DeviceManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java index ba360f165..6637df91c 100644 --- a/src/org/traccar/database/DeviceManager.java +++ b/src/org/traccar/database/DeviceManager.java @@ -306,7 +306,7 @@ public class DeviceManager implements IdentityManager { } for (Long cachedGroupId : groupsById.keySet()) { if (!databaseGroupsIds.contains(cachedGroupId)) { - devicesById.remove(cachedGroupId); + groupsById.remove(cachedGroupId); } } databaseGroupsIds.clear(); -- cgit v1.2.3 From 0e3c39e9d6f165c65e6156e05edc048bad9f57bc Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 17:51:01 +0500 Subject: Fix initial cache fill --- src/org/traccar/database/DriversManager.java | 5 ++--- src/org/traccar/database/SimpleObjectManager.java | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index e3ae07a65..f843568b4 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -16,7 +16,6 @@ */ package org.traccar.database; -import java.sql.SQLException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -32,8 +31,8 @@ public class DriversManager extends ExtendedObjectManager { } @Override - public void addItem(BaseModel item) throws SQLException { - super.addItem(item); + protected void addNewItem(BaseModel item) { + super.addNewItem(item); driversByUniqueId.put(((Driver) item).getUniqueId(), (Driver) item); } diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 031f91fc5..0f6a9e6a4 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -99,7 +99,7 @@ public abstract class SimpleObjectManager { if (items.containsKey(item.getId())) { updateCachedItem(item); } else { - items.put(item.getId(), item); + addNewItem(item); } } for (Long cachedItemId : items.keySet()) { @@ -127,9 +127,13 @@ public abstract class SimpleObjectManager { } } + protected void addNewItem(BaseModel item) { + items.put(item.getId(), item); + } + public void addItem(BaseModel item) throws SQLException { dataManager.addObject(item); - items.put(item.getId(), item); + addNewItem(item); } protected void updateCachedItem(BaseModel item) { -- cgit v1.2.3 From 4e2fe7bc908e0288345a4aef2f31c357215a7586 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 17:57:24 +0500 Subject: Fix item removing --- src/org/traccar/database/DriversManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index f843568b4..349e5dccf 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -54,7 +54,7 @@ public class DriversManager extends ExtendedObjectManager { Driver cachedDriver = (Driver) getById(driverId); if (cachedDriver != null) { String driverUniqueId = cachedDriver.getUniqueId(); - removeCachedItem(driverId); + super.removeCachedItem(driverId); driversByUniqueId.remove(driverUniqueId); } } -- cgit v1.2.3 From 870a919f53986724c023bcde9d0eddf8888e9007 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 24 Jul 2017 18:13:53 +0500 Subject: Fix order of objects constructions --- src/org/traccar/database/DriversManager.java | 13 ++++++++++--- src/org/traccar/database/SimpleObjectManager.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 349e5dccf..14b74bab1 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -24,16 +24,23 @@ import org.traccar.model.BaseModel; public class DriversManager extends ExtendedObjectManager { - private final Map driversByUniqueId = new ConcurrentHashMap<>(); + private Map driversByUniqueId; public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); } + private void putUniqueDriverId(Driver driver) { + if (driversByUniqueId == null) { + driversByUniqueId = new ConcurrentHashMap<>(); + } + driversByUniqueId.put(driver.getUniqueId(), driver); + } + @Override protected void addNewItem(BaseModel item) { super.addNewItem(item); - driversByUniqueId.put(((Driver) item).getUniqueId(), (Driver) item); + putUniqueDriverId((Driver) item); } @Override @@ -44,7 +51,7 @@ public class DriversManager extends ExtendedObjectManager { if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) { driversByUniqueId.remove(cachedDriver.getUniqueId()); cachedDriver.setUniqueId(driver.getUniqueId()); - driversByUniqueId.put(cachedDriver.getUniqueId(), cachedDriver); + putUniqueDriverId(cachedDriver); } cachedDriver.setAttributes(driver.getAttributes()); } diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 0f6a9e6a4..6cb7ff260 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -162,7 +162,7 @@ public abstract class SimpleObjectManager { return result; } - public Set getAllItems() { + public final Set getAllItems() { return items.keySet(); } -- cgit v1.2.3 From f35961c2f4a3104a009d6e3cd6bc862e6810b998 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Tue, 25 Jul 2017 08:23:23 +0500 Subject: Use function for removing --- src/org/traccar/database/SimpleObjectManager.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/org/traccar/database') diff --git a/src/org/traccar/database/SimpleObjectManager.java b/src/org/traccar/database/SimpleObjectManager.java index 6cb7ff260..282dea46e 100644 --- a/src/org/traccar/database/SimpleObjectManager.java +++ b/src/org/traccar/database/SimpleObjectManager.java @@ -67,10 +67,6 @@ public abstract class SimpleObjectManager { items.clear(); } - protected void removeCachedItem(long itemId) { - items.remove(itemId); - } - public final Set getUserItems(long userId) { if (!userItems.containsKey(userId)) { userItems.put(userId, new HashSet()); @@ -104,7 +100,7 @@ public abstract class SimpleObjectManager { } for (Long cachedItemId : items.keySet()) { if (!databaseItemIds.contains(cachedItemId)) { - items.remove(cachedItemId); + removeCachedItem(cachedItemId); } } } catch (SQLException error) { @@ -145,6 +141,10 @@ public abstract class SimpleObjectManager { updateCachedItem(item); } + protected void removeCachedItem(long itemId) { + items.remove(itemId); + } + public void removeItem(long itemId) throws SQLException { BaseModel item = getById(itemId); if (item != null) { -- cgit v1.2.3