aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r--src/org/traccar/database/AttributesManager.java7
-rw-r--r--src/org/traccar/database/BaseObjectManager.java2
-rw-r--r--src/org/traccar/database/CalendarManager.java5
-rw-r--r--src/org/traccar/database/DeviceManager.java14
-rw-r--r--src/org/traccar/database/DriversManager.java9
-rw-r--r--src/org/traccar/database/GeofenceManager.java7
-rw-r--r--src/org/traccar/database/GroupsManager.java5
-rw-r--r--src/org/traccar/database/UsersManager.java11
8 files changed, 45 insertions, 15 deletions
diff --git a/src/org/traccar/database/AttributesManager.java b/src/org/traccar/database/AttributesManager.java
index 4dc70eeb7..e80d57c4e 100644
--- a/src/org/traccar/database/AttributesManager.java
+++ b/src/org/traccar/database/AttributesManager.java
@@ -26,9 +26,14 @@ public class AttributesManager extends ExtendedObjectManager {
}
@Override
+ public Attribute getById(long calendarId) {
+ return (Attribute) super.getById(calendarId);
+ }
+
+ @Override
public void updateCachedItem(BaseModel item) {
Attribute attribute = (Attribute) item;
- Attribute cachedAttribute = (Attribute) getById(item.getId());
+ Attribute cachedAttribute = getById(item.getId());
cachedAttribute.setDescription(attribute.getDescription());
cachedAttribute.setAttribute(attribute.getAttribute());
cachedAttribute.setExpression(attribute.getExpression());
diff --git a/src/org/traccar/database/BaseObjectManager.java b/src/org/traccar/database/BaseObjectManager.java
index d515fc2a9..92cfd9b6b 100644
--- a/src/org/traccar/database/BaseObjectManager.java
+++ b/src/org/traccar/database/BaseObjectManager.java
@@ -48,7 +48,7 @@ public class BaseObjectManager {
return baseClass;
}
- public final BaseModel getById(long itemId) {
+ public BaseModel getById(long itemId) {
return items.get(itemId);
}
diff --git a/src/org/traccar/database/CalendarManager.java b/src/org/traccar/database/CalendarManager.java
index 6874020ec..b8d0914ee 100644
--- a/src/org/traccar/database/CalendarManager.java
+++ b/src/org/traccar/database/CalendarManager.java
@@ -24,4 +24,9 @@ public class CalendarManager extends SimpleObjectManager {
super(dataManager, Calendar.class);
}
+ @Override
+ public Calendar getById(long calendarId) {
+ return (Calendar) super.getById(calendarId);
+ }
+
}
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index ac66f1bb8..1fe7ddfa5 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -143,8 +143,8 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
@Override
protected void addNewItem(BaseModel item) {
- Device device = (Device) item;
super.addNewItem(item);
+ Device device = (Device) item;
putUniqueDeviceId(device);
if (device.getPhone() != null && !device.getPhone().isEmpty()) {
putPhone(device);
@@ -160,7 +160,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
@Override
protected void updateCachedItem(BaseModel item) {
Device device = (Device) item;
- Device cachedDevice = (Device) getById(device.getId());
+ Device cachedDevice = getDeviceById(device.getId());
cachedDevice.setName(device.getName());
cachedDevice.setGroupId(device.getGroupId());
cachedDevice.setCategory(device.getCategory());
@@ -182,7 +182,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
@Override
protected void removeCachedItem(long deviceId) {
- Device cachedDevice = (Device) getById(deviceId);
+ Device cachedDevice = getDeviceById(deviceId);
if (cachedDevice != null) {
String deviceUniqueId = cachedDevice.getUniqueId();
String phone = cachedDevice.getPhone();
@@ -197,7 +197,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
public void updateDeviceStatus(Device device) throws SQLException {
getDataManager().updateDeviceStatus(device);
- Device cachedDevice = (Device) getById(device.getId());
+ Device cachedDevice = getDeviceById(device.getId());
if (cachedDevice != null) {
cachedDevice.setStatus(device.getStatus());
}
@@ -226,7 +226,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
getDataManager().updateLatestPosition(position);
- Device device = (Device) getById(position.getDeviceId());
+ Device device = getDeviceById(position.getDeviceId());
if (device != null) {
device.setPositionId(position.getId());
}
@@ -311,7 +311,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
if (result == null && lookupGroupsAttribute) {
long groupId = device.getGroupId();
while (groupId != 0) {
- Group group = (Group) Context.getGroupsManager().getById(groupId);
+ Group group = Context.getGroupsManager().getById(groupId);
if (group != null) {
result = group.getString(attributeName);
if (result != null) {
@@ -352,7 +352,7 @@ public class DeviceManager extends BaseObjectManager implements IdentityManager,
Position lastPosition = getLastPosition(deviceId);
if (lastPosition != null) {
BaseProtocol protocol = Context.getServerManager().getProtocol(lastPosition.getProtocol());
- protocol.sendTextCommand(((Device) getById(deviceId)).getPhone(), command);
+ protocol.sendTextCommand(getDeviceById(deviceId).getPhone(), command);
} else if (command.getType().equals(Command.TYPE_CUSTOM)) {
Context.getSmppManager().sendMessageSync(((Device) getById(deviceId)).getPhone(),
command.getString(Command.KEY_DATA), true);
diff --git a/src/org/traccar/database/DriversManager.java b/src/org/traccar/database/DriversManager.java
index 14b74bab1..420824dbb 100644
--- a/src/org/traccar/database/DriversManager.java
+++ b/src/org/traccar/database/DriversManager.java
@@ -30,6 +30,11 @@ public class DriversManager extends ExtendedObjectManager {
super(dataManager, Driver.class);
}
+ @Override
+ public Driver getById(long driverId) {
+ return (Driver) super.getById(driverId);
+ }
+
private void putUniqueDriverId(Driver driver) {
if (driversByUniqueId == null) {
driversByUniqueId = new ConcurrentHashMap<>();
@@ -46,7 +51,7 @@ public class DriversManager extends ExtendedObjectManager {
@Override
protected void updateCachedItem(BaseModel item) {
Driver driver = (Driver) item;
- Driver cachedDriver = (Driver) getById(driver.getId());
+ Driver cachedDriver = getById(driver.getId());
cachedDriver.setName(driver.getName());
if (!driver.getUniqueId().equals(cachedDriver.getUniqueId())) {
driversByUniqueId.remove(cachedDriver.getUniqueId());
@@ -58,7 +63,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);
diff --git a/src/org/traccar/database/GeofenceManager.java b/src/org/traccar/database/GeofenceManager.java
index 2c3c32c56..4bc3909cd 100644
--- a/src/org/traccar/database/GeofenceManager.java
+++ b/src/org/traccar/database/GeofenceManager.java
@@ -30,6 +30,11 @@ public class GeofenceManager extends ExtendedObjectManager {
}
@Override
+ public Geofence getById(long geofenceId) {
+ return (Geofence) super.getById(geofenceId);
+ }
+
+ @Override
public final void refreshExtendedPermissions() {
super.refreshExtendedPermissions();
recalculateDevicesGeofences();
@@ -38,7 +43,7 @@ public class GeofenceManager extends ExtendedObjectManager {
public List<Long> getCurrentDeviceGeofences(Position position) {
List<Long> result = new ArrayList<>();
for (long geofenceId : getAllDeviceItems(position.getDeviceId())) {
- Geofence geofence = (Geofence) getById(geofenceId);
+ Geofence geofence = getById(geofenceId);
if (geofence != null && geofence.getGeometry()
.containsPoint(position.getLatitude(), position.getLongitude())) {
result.add(geofenceId);
diff --git a/src/org/traccar/database/GroupsManager.java b/src/org/traccar/database/GroupsManager.java
index e92158fd6..095e7a22c 100644
--- a/src/org/traccar/database/GroupsManager.java
+++ b/src/org/traccar/database/GroupsManager.java
@@ -37,6 +37,11 @@ public class GroupsManager extends BaseObjectManager implements ManagableObjects
DeviceManager.DEFAULT_REFRESH_DELAY) * 1000;
}
+ @Override
+ public Group getById(long groupId) {
+ return (Group) super.getById(groupId);
+ }
+
private void checkGroupCycles(BaseModel group) {
Set<Long> groups = new HashSet<>();
while (group != null) {
diff --git a/src/org/traccar/database/UsersManager.java b/src/org/traccar/database/UsersManager.java
index cb4ea623f..e53409b4f 100644
--- a/src/org/traccar/database/UsersManager.java
+++ b/src/org/traccar/database/UsersManager.java
@@ -32,6 +32,11 @@ public class UsersManager extends SimpleObjectManager {
super(dataManager, User.class);
}
+ @Override
+ public User getById(long userId) {
+ return (User) super.getById(userId);
+ }
+
private void putToken(User user) {
if (usersTokens == null) {
usersTokens = new ConcurrentHashMap<>();
@@ -50,7 +55,7 @@ public class UsersManager extends SimpleObjectManager {
@Override
protected void updateCachedItem(BaseModel item) {
User user = (User) item;
- User cachedUser = (User) getById(item.getId());
+ User cachedUser = getById(item.getId());
super.updateCachedItem(item);
if (user.getToken() != null) {
usersTokens.put(user.getToken(), user.getId());
@@ -62,7 +67,7 @@ public class UsersManager extends SimpleObjectManager {
@Override
protected void removeCachedItem(long userId) {
- User cachedUser = (User) getById(userId);
+ User cachedUser = getById(userId);
if (cachedUser != null) {
String userToken = cachedUser.getToken();
super.removeCachedItem(userId);
@@ -81,7 +86,7 @@ public class UsersManager extends SimpleObjectManager {
}
public User getUserByToken(String token) {
- return (User) getById(usersTokens.get(token));
+ return getById(usersTokens.get(token));
}
}