diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2011-11-16 11:37:11 +0000 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2011-11-16 11:37:11 +0000 |
commit | 710bdd092b193704fabdf6136bd5bffe0d8e01e7 (patch) | |
tree | a07c70ca1fbd6b7f103977327652eb32d35490d9 /src | |
parent | 822f9eb02153f12bb435d467074cf85eb9e581fb (diff) | |
download | traccar-server-710bdd092b193704fabdf6136bd5bffe0d8e01e7.tar.gz traccar-server-710bdd092b193704fabdf6136bd5bffe0d8e01e7.tar.bz2 traccar-server-710bdd092b193704fabdf6136bd5bffe0d8e01e7.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/Server.java | 38 | ||||
-rw-r--r-- | src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java | 3 |
2 files changed, 18 insertions, 23 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 305edecde..c7d52337e 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -28,6 +28,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.Calendar; import java.util.Date; import java.util.logging.Logger; import java.util.logging.FileHandler; @@ -102,10 +103,10 @@ public class Server implements DataManager { * Database connection */ private Connection connection; - - private NamedParameterStatement selectDevice; - - private NamedParameterStatement insertPosition; + + private String selectDeviceQuery; + + private String insertPositionQuery; /** * Init database @@ -130,27 +131,23 @@ public class Server implements DataManager { connection = DriverManager.getConnection(url); } - // Init statements - String selectDeviceQuery = properties.getProperty("database.selectDevice"); - if (selectDeviceQuery != null) { - selectDevice = new NamedParameterStatement(connection, selectDeviceQuery); - } - - String insertPositionQuery = properties.getProperty("database.insertPosition"); - if (insertPositionQuery != null) { - insertPosition = new NamedParameterStatement(connection, insertPositionQuery); - } + selectDeviceQuery = properties.getProperty("database.selectDevice"); + insertPositionQuery = properties.getProperty("database.insertPosition"); } /** * Devices */ private Map devices; + private Calendar devicesLastUpdate; + private Long devicesListRefreshDelay = new Long(5 * 60 * 1000); public synchronized List getDevices() throws SQLException { List deviceList = new LinkedList(); + NamedParameterStatement selectDevice = + new NamedParameterStatement(connection, selectDeviceQuery); ResultSet result = selectDevice.executeQuery(); while (result.next()) { Device device = new Device(); @@ -161,18 +158,16 @@ public class Server implements DataManager { return deviceList; } - + public Device getDeviceByImei(String imei) throws SQLException { - - // Init device list - if (devices == null) { + + if ((devices == null) || (Calendar.getInstance().getTimeInMillis() - devicesLastUpdate.getTimeInMillis() > devicesListRefreshDelay)) { devices = new HashMap(); - List deviceList = getDevices(); - for (Object device: deviceList) { devices.put(((Device) device).getImei(), device); } + devicesLastUpdate = Calendar.getInstance(); } return (Device) devices.get(imei); @@ -180,6 +175,9 @@ public class Server implements DataManager { public synchronized void setPosition(Position position) throws SQLException { + NamedParameterStatement insertPosition = + new NamedParameterStatement(connection, insertPositionQuery); + insertPosition.setLong("device_id", position.getDeviceId()); insertPosition.setTimestamp("time", position.getTime()); insertPosition.setBoolean("valid", position.getValid()); diff --git a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java index f7ff9f528..8f1b53328 100644 --- a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java +++ b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java @@ -78,9 +78,6 @@ public class Xexun2ProtocolDecoder extends OneToOneDecoder { "F:(\\d+.\\d+)V," + // Power ".*"); - //"111111120009,+436763737552,GPRMC,120009.590,A,4639.6774,N,01418.5737,E,0.00,0.00,111111" - //",,,A*68,F,, imei:012207000694569,04,481.2,F:4.15V,0,139,2689,232,03,2725,0576" - /** * Decode message */ |