diff options
Diffstat (limited to 'src/org/traccar/model/DatabaseDataManager.java')
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 30 |
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(); |