diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-26 20:22:09 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-26 20:22:09 +1300 |
commit | 1fe18b404796c47e0eec31b4a40c9e4087e997b9 (patch) | |
tree | 7c20d4f1b570e4db9d4def27877ed42e6ad3f354 | |
parent | 8bae4d69ba4db1a36201fa7c2745a85719902233 (diff) | |
download | traccar-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.tar.gz traccar-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.tar.bz2 traccar-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.zip |
Small code improvements
-rw-r--r-- | src/org/traccar/BasePipelineFactory.java | 4 | ||||
-rw-r--r-- | src/org/traccar/GlobalChannelFactory.java | 4 | ||||
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 70 |
3 files changed, 40 insertions, 38 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 5bebda925..e44f67205 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -58,8 +58,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { */ protected class StandardLoggingHandler extends LoggingHandler { - static final String HEX_CHARS = "0123456789ABCDEF"; - @Override public void log(ChannelEvent e) { if (e instanceof MessageEvent) { @@ -82,8 +80,8 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { ExceptionEvent event = (ExceptionEvent) e; Log.warning(event.getCause().toString()); } - // TODO: handle other events } + } public BasePipelineFactory(ServerManager serverManager, TrackerServer server, String protocol) { diff --git a/src/org/traccar/GlobalChannelFactory.java b/src/org/traccar/GlobalChannelFactory.java index a93703286..489207e39 100644 --- a/src/org/traccar/GlobalChannelFactory.java +++ b/src/org/traccar/GlobalChannelFactory.java @@ -38,9 +38,7 @@ public class GlobalChannelFactory { public static ChannelFactory getFactory() { if(instance == null) { - instance = new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(), - Executors.newCachedThreadPool()); + instance = new NioServerSocketChannelFactory(); } return instance; } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index ee86e6370..7b98b73fb 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -87,13 +87,15 @@ public class DatabaseDataManager implements DataManager { List<Device> deviceList = new LinkedList<Device>(); - queryGetDevices.prepare(); - ResultSet result = queryGetDevices.executeQuery(); - while (result.next()) { - Device device = new Device(); - device.setId(result.getLong("id")); - device.setImei(result.getString("imei")); - deviceList.add(device); + if (queryGetDevices != null) { + queryGetDevices.prepare(); + ResultSet result = queryGetDevices.executeQuery(); + while (result.next()) { + Device device = new Device(); + device.setId(result.getLong("id")); + device.setImei(result.getString("imei")); + deviceList.add(device); + } } return deviceList; @@ -124,26 +126,28 @@ public class DatabaseDataManager implements DataManager { @Override public synchronized Long addPosition(Position position) throws SQLException { - 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()); - queryAddPosition.setDouble("altitude", position.getAltitude()); - queryAddPosition.setDouble("latitude", position.getLatitude()); - 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()); - - queryAddPosition.executeUpdate(); - - ResultSet result = queryAddPosition.getGeneratedKeys(); - if (result != null && result.next()) { - return result.getLong(1); + 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()); + queryAddPosition.setDouble("altitude", position.getAltitude()); + queryAddPosition.setDouble("latitude", position.getLatitude()); + 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()); + + queryAddPosition.executeUpdate(); + + ResultSet result = queryAddPosition.getGeneratedKeys(); + if (result != null && result.next()) { + return result.getLong(1); + } } return null; @@ -151,13 +155,15 @@ public class DatabaseDataManager implements DataManager { @Override public void updateLatestPosition(Long deviceId, Long positionId) throws SQLException { + + if (queryUpdateLatestPosition != null) { + queryUpdateLatestPosition.prepare(); - queryUpdateLatestPosition.prepare(); + queryUpdateLatestPosition.setLong("device_id", deviceId); + queryUpdateLatestPosition.setLong("id", positionId); - queryUpdateLatestPosition.setLong("device_id", deviceId); - queryUpdateLatestPosition.setLong("id", positionId); - - queryUpdateLatestPosition.executeUpdate(); + queryUpdateLatestPosition.executeUpdate(); + } } } |