diff options
Diffstat (limited to 'src/org/traccar')
-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(); + } } } |