aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/model/DatabaseDataManager.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-03-26 20:22:09 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2013-03-26 20:22:09 +1300
commit1fe18b404796c47e0eec31b4a40c9e4087e997b9 (patch)
tree7c20d4f1b570e4db9d4def27877ed42e6ad3f354 /src/org/traccar/model/DatabaseDataManager.java
parent8bae4d69ba4db1a36201fa7c2745a85719902233 (diff)
downloadtrackermap-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.tar.gz
trackermap-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.tar.bz2
trackermap-server-1fe18b404796c47e0eec31b4a40c9e4087e997b9.zip
Small code improvements
Diffstat (limited to 'src/org/traccar/model/DatabaseDataManager.java')
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java70
1 files changed, 38 insertions, 32 deletions
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();
+ }
}
}