diff options
Diffstat (limited to 'src/org/traccar/database/DriversManager.java')
-rw-r--r-- | src/org/traccar/database/DriversManager.java | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java index 14b74bab1..d3866a5f0 100644 --- a/src/org/traccar/database/DriversManager.java +++ b/src/org/traccar/database/DriversManager.java @@ -20,11 +20,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.traccar.model.Driver; -import org.traccar.model.BaseModel; -public class DriversManager extends ExtendedObjectManager { +public class DriversManager extends ExtendedObjectManager<Driver> { - private Map<String, Driver> driversByUniqueId; + private Map<String, Long> driversByUniqueId; public DriversManager(DataManager dataManager) { super(dataManager, Driver.class); @@ -32,21 +31,20 @@ public class DriversManager extends ExtendedObjectManager { private void putUniqueDriverId(Driver driver) { if (driversByUniqueId == null) { - driversByUniqueId = new ConcurrentHashMap<>(); + driversByUniqueId = new ConcurrentHashMap<>(getAllItems().size()); } - driversByUniqueId.put(driver.getUniqueId(), driver); + driversByUniqueId.put(driver.getUniqueId(), driver.getId()); } @Override - protected void addNewItem(BaseModel item) { - super.addNewItem(item); - putUniqueDriverId((Driver) item); + protected void addNewItem(Driver driver) { + super.addNewItem(driver); + putUniqueDriverId(driver); } @Override - protected void updateCachedItem(BaseModel item) { - Driver driver = (Driver) item; - Driver cachedDriver = (Driver) getById(driver.getId()); + protected void updateCachedItem(Driver driver) { + Driver cachedDriver = getById(driver.getId()); cachedDriver.setName(driver.getName()); if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) { driversByUniqueId.remove(cachedDriver.getUniqueId()); @@ -58,7 +56,7 @@ public class DriversManager extends ExtendedObjectManager { @Override protected void removeCachedItem(long driverId) { - Driver cachedDriver = (Driver) getById(driverId); + Driver cachedDriver = getById(driverId); if (cachedDriver != null) { String driverUniqueId = cachedDriver.getUniqueId(); super.removeCachedItem(driverId); @@ -67,6 +65,6 @@ public class DriversManager extends ExtendedObjectManager { } public Driver getDriverByUniqueId(String uniqueId) { - return driversByUniqueId.get(uniqueId); + return getById(driversByUniqueId.get(uniqueId)); } } |