aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2012-05-07 21:08:44 +0400
committerAnton Tananaev <anton.tananaev@gmail.com>2012-05-07 21:08:44 +0400
commitaf8205cb3b609d4618691cd1ba81da34b341df3d (patch)
tree0246a43a219ee596343d4dcad717588162cb2003
parent88544e0f367a5ab5a3522ef9cea1f78fda19d7da (diff)
downloadtrackermap-server-af8205cb3b609d4618691cd1ba81da34b341df3d.tar.gz
trackermap-server-af8205cb3b609d4618691cd1ba81da34b341df3d.tar.bz2
trackermap-server-af8205cb3b609d4618691cd1ba81da34b341df3d.zip
Added database schema creation
-rw-r--r--default.cfg22
-rw-r--r--src/org/traccar/model/DatabaseDataManager.java10
2 files changed, 21 insertions, 11 deletions
diff --git a/default.cfg b/default.cfg
index 77312d588..b5c76fd42 100644
--- a/default.cfg
+++ b/default.cfg
@@ -13,11 +13,11 @@
<!-- Database refresh delay in seconds -->
<entry key="database.refreshDelay">300</entry>
- <!-->
- Create database:
- CREATE TABLE devices (id INT IDENTITY imei VARCHAR(16))
- CREATE TABLE positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE)
- <-->
+ <!-- Create database schema -->
+ <entry key="database.initialize">
+ CREATE TABLE IF NOT EXISTS devices (id INT IDENTITY, imei VARCHAR(16));
+ CREATE TABLE IF NOT EXISTS positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE);
+ </entry>
<!-->
id - Integer
@@ -25,7 +25,7 @@
<-->
<entry key="database.selectDevice">
SELECT id, imei
- FROM devices
+ FROM devices;
</entry>
<!-->
@@ -33,7 +33,7 @@
<-->
<entry key="database.insertDevice">
INSERT INTO devices (imei)
- VALUES (:imei)
+ VALUES (:imei);
</entry>
<!-->
@@ -43,7 +43,7 @@
<entry key="database.updateDevice">
UPDATE devices
SET imei = :imei
- WHERE id = :id
+ WHERE id = :id;
</entry>
<!-->
@@ -51,7 +51,7 @@
<-->
<entry key="database.deleteDevice">
DELETE FROM devices
- WHERE id = :id
+ WHERE id = :id;
</entry>
<!-->
@@ -60,7 +60,7 @@
<entry key="database.selectPosition">
SELECT *
FROM positions
- WHERE device_id = :device_id
+ WHERE device_id = :device_id;
</entry>
<!-->
@@ -76,7 +76,7 @@
<-->
<entry key="database.insertPosition">
INSERT INTO positions (device_id, time, valid, latitude, longitude, speed, course, power)
- VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power)
+ VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power);
</entry>
<!-- Web interface port -->
diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java
index c5492bc8a..ece8014ce 100644
--- a/src/org/traccar/model/DatabaseDataManager.java
+++ b/src/org/traccar/model/DatabaseDataManager.java
@@ -87,6 +87,16 @@ public class DatabaseDataManager implements DataManager {
query = properties.getProperty("database.insertPosition");
queryAddPosition = new NamedParameterStatement(connection, query);
+
+ // Create database schema
+ query = properties.getProperty("database.initialize");
+ if (query != null) try {
+ NamedParameterStatement initializeQuery = new NamedParameterStatement(connection, query);
+ initializeQuery.prepare();
+ initializeQuery.executeUpdate();
+ } catch (Exception error) {
+ System.out.println(error.getMessage());
+ }
}
public synchronized List<Device> getDevices() throws SQLException {