aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java45
1 files changed, 2 insertions, 43 deletions
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index adcddd73d..ba07cbbab 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -45,9 +45,6 @@ public class DatabaseDataManager implements DataManager {
private NamedParameterStatement queryGetDevices;
private NamedParameterStatement queryAddPosition;
private NamedParameterStatement queryUpdateLatestPosition;
- private String queryAddPositionTemplate;
- private String queryUpdateLatestPositionTemplate;
- private AdvancedConnection globalConnection;
/**
* Initialize database
@@ -74,7 +71,7 @@ public class DatabaseDataManager implements DataManager {
String user = properties.getProperty("database.user");
String password = properties.getProperty("database.password");
AdvancedConnection connection = new AdvancedConnection(url, user, password);
- globalConnection = connection;
+
// Load statements from configuration
String query;
@@ -84,13 +81,11 @@ public class DatabaseDataManager implements DataManager {
}
query = properties.getProperty("database.insertPosition");
- queryAddPositionTemplate = query;
if (query != null) {
queryAddPosition = new NamedParameterStatement(connection, query);
}
query = properties.getProperty("database.updateLatestPosition");
- queryUpdateLatestPositionTemplate = query;
if (query != null) {
queryUpdateLatestPosition = new NamedParameterStatement(connection, query);
}
@@ -108,7 +103,6 @@ public class DatabaseDataManager implements DataManager {
Device device = new Device();
device.setId(result.getLong("id"));
device.setImei(result.getString("imei"));
- device.setDatabase(result.getString("database"));
deviceList.add(device);
}
}
@@ -120,7 +114,6 @@ public class DatabaseDataManager implements DataManager {
* Devices cache
*/
private Map<String, Device> devices;
- private Map<Long, Device> devices_id;
@Override
public Device getDeviceByImei(String imei) throws SQLException {
@@ -136,27 +129,7 @@ public class DatabaseDataManager implements DataManager {
}
@Override
- public Device getDeviceById(Long id) throws SQLException {
-
- if (devices_id == null || !devices_id.containsKey(id)) {
- devices_id = new HashMap<Long, Device>();
- for (Device device : getDevices()) {
- devices_id.put(device.getId(), device);
- }
- }
-
- return devices_id.get(id);
- }
-
- @Override
public synchronized Long addPosition(Position position) throws SQLException {
- if (queryAddPositionTemplate.contains("_database_")) {
- String query = queryAddPositionTemplate;
- query = query.replace("_database_", this.getDeviceById(position.getDeviceId()).getDatabase());
- if (query != null) {
- queryAddPosition = new NamedParameterStatement(globalConnection, query);
- }
- }
if (queryAddPosition != null) {
queryAddPosition.prepare(Statement.RETURN_GENERATED_KEYS);
@@ -207,14 +180,7 @@ public class DatabaseDataManager implements DataManager {
}
@Override
- public void updateLatestPosition(Position position, Long positionId ) throws SQLException {
- if (queryUpdateLatestPositionTemplate.contains("_database_")) {
- String query = queryUpdateLatestPositionTemplate;
- query = query.replace("_database_", this.getDeviceById(position.getDeviceId()).getDatabase());
- if (query != null) {
- queryUpdateLatestPosition = new NamedParameterStatement(globalConnection, query);
- }
- }
+ public void updateLatestPosition(Position position, Long positionId) throws SQLException {
if (queryUpdateLatestPosition != null) {
queryUpdateLatestPosition.prepare();
@@ -235,12 +201,6 @@ public class DatabaseDataManager implements DataManager {
XPath xpath = XPathFactory.newInstance().newXPath();
try {
InputSource source = new InputSource(new StringReader(position.getExtendedInfo()));
- String index = xpath.evaluate("/info/index", source);
- if (!index.isEmpty()) {
- queryUpdateLatestPosition.setLong("id", Long.valueOf(index));
- } else {
- queryUpdateLatestPosition.setLong("id", null);
- }
source = new InputSource(new StringReader(position.getExtendedInfo()));
String power = xpath.evaluate("/info/power", source);
if (!power.isEmpty()) {
@@ -250,7 +210,6 @@ public class DatabaseDataManager implements DataManager {
}
} catch (XPathExpressionException e) {
Log.warning("Error in XML: " + position.getExtendedInfo(), e);
- queryUpdateLatestPosition.setLong("id", null);
queryUpdateLatestPosition.setLong("power", null);
}