aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-09-30 23:06:59 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-09-30 23:06:59 -0700
commitef5f959f737a6277b146e5eb4e34827638b1f93c (patch)
tree05dae02283339e64ace42ff062281a68a4f14df8 /src/main/java/org/traccar/database
parent1e06b00e5f6068a191d0652798f12df77f0b0e0a (diff)
downloadtrackermap-server-ef5f959f737a6277b146e5eb4e34827638b1f93c.tar.gz
trackermap-server-ef5f959f737a6277b146e5eb4e34827638b1f93c.tar.bz2
trackermap-server-ef5f959f737a6277b146e5eb4e34827638b1f93c.zip
Various minor code cleanup
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r--src/main/java/org/traccar/database/BaseObjectManager.java2
-rw-r--r--src/main/java/org/traccar/database/CommandsManager.java2
-rw-r--r--src/main/java/org/traccar/database/DataManager.java2
-rw-r--r--src/main/java/org/traccar/database/DeviceManager.java4
-rw-r--r--src/main/java/org/traccar/database/PermissionsManager.java2
-rw-r--r--src/main/java/org/traccar/database/QueryBuilder.java116
6 files changed, 52 insertions, 76 deletions
diff --git a/src/main/java/org/traccar/database/BaseObjectManager.java b/src/main/java/org/traccar/database/BaseObjectManager.java
index d0024c005..be6310033 100644
--- a/src/main/java/org/traccar/database/BaseObjectManager.java
+++ b/src/main/java/org/traccar/database/BaseObjectManager.java
@@ -38,8 +38,8 @@ public class BaseObjectManager<T extends BaseModel> {
private final DataManager dataManager;
+ private final Class<T> baseClass;
private Map<Long, T> items;
- private Class<T> baseClass;
protected BaseObjectManager(DataManager dataManager, Class<T> baseClass) {
this.dataManager = dataManager;
diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java
index 485402807..843c89e82 100644
--- a/src/main/java/org/traccar/database/CommandsManager.java
+++ b/src/main/java/org/traccar/database/CommandsManager.java
@@ -41,7 +41,7 @@ public class CommandsManager extends ExtendedObjectManager<Command> {
private final Map<Long, Queue<Command>> deviceQueues = new ConcurrentHashMap<>();
- private boolean queueing;
+ private final boolean queueing;
public CommandsManager(DataManager dataManager, boolean queueing) {
super(dataManager, Command.class);
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index 8e9071736..8b9690f77 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -79,7 +79,7 @@ public class DataManager {
private boolean generateQueries;
- private boolean forceLdap;
+ private final boolean forceLdap;
public DataManager(Config config) throws Exception {
this.config = config;
diff --git a/src/main/java/org/traccar/database/DeviceManager.java b/src/main/java/org/traccar/database/DeviceManager.java
index fe17f7ced..e621e6058 100644
--- a/src/main/java/org/traccar/database/DeviceManager.java
+++ b/src/main/java/org/traccar/database/DeviceManager.java
@@ -45,11 +45,11 @@ public class DeviceManager extends BaseObjectManager<Device> implements Identity
private final Config config;
private final long dataRefreshDelay;
- private boolean lookupGroupsAttribute;
+ private final boolean lookupGroupsAttribute;
private Map<String, Device> devicesByUniqueId;
private Map<String, Device> devicesByPhone;
- private AtomicLong devicesLastUpdate = new AtomicLong();
+ private final AtomicLong devicesLastUpdate = new AtomicLong();
private final Map<Long, Position> positions = new ConcurrentHashMap<>();
diff --git a/src/main/java/org/traccar/database/PermissionsManager.java b/src/main/java/org/traccar/database/PermissionsManager.java
index ced0df1c0..d2dc62394 100644
--- a/src/main/java/org/traccar/database/PermissionsManager.java
+++ b/src/main/java/org/traccar/database/PermissionsManager.java
@@ -196,7 +196,7 @@ public class PermissionsManager {
public void checkDeviceLimit(long userId) throws SecurityException {
int deviceLimit = getUser(userId).getDeviceLimit();
if (deviceLimit != -1) {
- int deviceCount = 0;
+ int deviceCount;
if (getUserManager(userId)) {
deviceCount = Context.getDeviceManager().getAllManagedItems(userId).size();
} else {
diff --git a/src/main/java/org/traccar/database/QueryBuilder.java b/src/main/java/org/traccar/database/QueryBuilder.java
index 5528b2320..f57f27e88 100644
--- a/src/main/java/org/traccar/database/QueryBuilder.java
+++ b/src/main/java/org/traccar/database/QueryBuilder.java
@@ -318,96 +318,72 @@ public final class QueryBuilder {
final Class<?> parameterType, final Method method, final String name) {
if (parameterType.equals(boolean.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getBoolean(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getBoolean(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(int.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getInt(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getInt(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(long.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getLong(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getLong(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(double.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getDouble(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getDouble(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(String.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getString(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getString(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(Date.class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- Timestamp timestamp = resultSet.getTimestamp(name);
- if (timestamp != null) {
- method.invoke(object, new Date(timestamp.getTime()));
- }
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
+ processors.add((object, resultSet) -> {
+ try {
+ Timestamp timestamp = resultSet.getTimestamp(name);
+ if (timestamp != null) {
+ method.invoke(object, new Date(timestamp.getTime()));
}
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else if (parameterType.equals(byte[].class)) {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- try {
- method.invoke(object, resultSet.getBytes(name));
- } catch (IllegalAccessException | InvocationTargetException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ try {
+ method.invoke(object, resultSet.getBytes(name));
+ } catch (IllegalAccessException | InvocationTargetException error) {
+ LOGGER.warn("Set property error", error);
}
});
} else {
- processors.add(new ResultSetProcessor<T>() {
- @Override
- public void process(T object, ResultSet resultSet) throws SQLException {
- String value = resultSet.getString(name);
- if (value != null && !value.isEmpty()) {
- try {
- method.invoke(object, Context.getObjectMapper().readValue(value, parameterType));
- } catch (InvocationTargetException | IllegalAccessException | IOException error) {
- LOGGER.warn("Set property error", error);
- }
+ processors.add((object, resultSet) -> {
+ String value = resultSet.getString(name);
+ if (value != null && !value.isEmpty()) {
+ try {
+ method.invoke(object, Context.getObjectMapper().readValue(value, parameterType));
+ } catch (InvocationTargetException | IllegalAccessException | IOException error) {
+ LOGGER.warn("Set property error", error);
}
}
});
@@ -453,12 +429,12 @@ public final class QueryBuilder {
while (resultSet.next()) {
try {
- T object = clazz.newInstance();
+ T object = clazz.getDeclaredConstructor().newInstance();
for (ResultSetProcessor<T> processor : processors) {
processor.process(object, resultSet);
}
result.add(object);
- } catch (InstantiationException | IllegalAccessException e) {
+ } catch (ReflectiveOperationException e) {
throw new IllegalArgumentException();
}
}