aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/model/DatabaseDataManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-09-28 13:40:00 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-09-28 13:40:00 +1200
commit53494de4e41e1c4d4440c9afc0c4a9dfa6480558 (patch)
tree9dc441029fbcb5ea71b83c49ef89599012bcccc8 /src/org/traccar/model/DatabaseDataManager.java
parentc1b6fb0e25020b845b059aef0adebeac7d90ed7c (diff)
downloadtrackermap-server-53494de4e41e1c4d4440c9afc0c4a9dfa6480558.tar.gz
trackermap-server-53494de4e41e1c4d4440c9afc0c4a9dfa6480558.tar.bz2
trackermap-server-53494de4e41e1c4d4440c9afc0c4a9dfa6480558.zip
Remove optional fields
Diffstat (limited to 'src/org/traccar/model/DatabaseDataManager.java')
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index ce781da1a..f56782b44 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -16,13 +16,21 @@
package org.traccar.model;
import java.io.File;
+import java.io.StringReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.sql.*;
import java.util.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
import org.traccar.helper.AdvancedConnection;
import org.traccar.helper.DriverDelegate;
+import org.traccar.helper.Log;
import org.traccar.helper.NamedParameterStatement;
+import org.xml.sax.InputSource;
/**
* Database abstraction class
@@ -140,7 +148,6 @@ public class DatabaseDataManager implements DataManager {
if (queryAddPosition != null) {
queryAddPosition.prepare(Statement.RETURN_GENERATED_KEYS);
- queryAddPosition.setLong("id", position.getId());
queryAddPosition.setLong("device_id", position.getDeviceId());
queryAddPosition.setTimestamp("time", position.getTime());
queryAddPosition.setBoolean("valid", position.getValid());
@@ -149,9 +156,28 @@ public class DatabaseDataManager implements DataManager {
queryAddPosition.setDouble("longitude", position.getLongitude());
queryAddPosition.setDouble("speed", position.getSpeed());
queryAddPosition.setDouble("course", position.getCourse());
- queryAddPosition.setDouble("power", position.getPower());
queryAddPosition.setString("address", position.getAddress());
queryAddPosition.setString("extended_info", position.getExtendedInfo());
+
+ // DELME: Temporary compatibility support
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ InputSource source = new InputSource(new StringReader(position.getExtendedInfo()));
+ try {
+ String index = xpath.evaluate("/info/index", source);
+ if (!index.isEmpty()) {
+ queryAddPosition.setLong("id", Long.valueOf(index));
+ } else {
+ queryAddPosition.setLong("id", null);
+ }
+ String power = xpath.evaluate("/info/power", source);
+ if (!power.isEmpty()) {
+ queryAddPosition.setDouble("power", Double.valueOf(power));
+ } else {
+ queryAddPosition.setLong("power", null);
+ }
+ } catch (XPathExpressionException ex) {
+ Log.warning(ex);
+ }
queryAddPosition.executeUpdate();