From bf246bdd20e94141c6b1b99886108f33995f4f36 Mon Sep 17 00:00:00 2001 From: Jed Date: Tue, 9 Sep 2014 13:42:03 +0800 Subject: Removed Other changes to prepare for pull request --- src/org/traccar/model/DatabaseDataManager.java | 45 ++------------------------ 1 file changed, 2 insertions(+), 43 deletions(-) (limited to 'src/org/traccar') 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 devices; - private Map devices_id; @Override public Device getDeviceByImei(String imei) throws SQLException { @@ -135,28 +128,8 @@ public class DatabaseDataManager implements DataManager { return devices.get(imei); } - @Override - public Device getDeviceById(Long id) throws SQLException { - - if (devices_id == null || !devices_id.containsKey(id)) { - devices_id = new HashMap(); - 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); } -- cgit v1.2.3