diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-21 16:13:31 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-05-21 16:13:31 +1200 |
commit | c6ce35720e315b0c28a52ef11ada67bf00642270 (patch) | |
tree | 53005ddfafa038ea8cad468a534428458a7476df /src/org | |
parent | dc76207257da485eeb4887202335c24e46d90263 (diff) | |
download | trackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.tar.gz trackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.tar.bz2 trackermap-server-c6ce35720e315b0c28a52ef11ada67bf00642270.zip |
Add mock position data
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 82e312c7e..4c65a3995 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -27,7 +27,10 @@ import java.sql.SQLException; import java.sql.Statement; import java.util.*; import javax.sql.DataSource; + +import org.traccar.Context; import org.traccar.helper.DriverDelegate; +import org.traccar.helper.Log; import org.traccar.model.Device; import org.traccar.model.Permission; import org.traccar.model.Position; @@ -89,10 +92,6 @@ public class DataManager { ds.setIdleConnectionTestPeriod(600); ds.setTestConnectionOnCheckin(true); dataSource = ds; - - if (useNewDatabase) { - createDatabaseSchema(); - } // Load statements from configuration String query; @@ -111,6 +110,10 @@ public class DataManager { if (query != null) { queryUpdateLatestPosition = new NamedParameterStatement(query, dataSource); } + + if (useNewDatabase) { + createDatabaseSchema(); + } } private final NamedParameterStatement.ResultSetProcessor<Device> deviceResultSetProcessor = new NamedParameterStatement.ResultSetProcessor<Device>() { @@ -302,12 +305,29 @@ public class DataManager { admin.setPassword("admin"); admin.setAdmin(true); addUser(admin); - - Device device = new Device(); - device.setName("test1"); - device.setUniqueId("123456789012345"); - addDevice(device); - linkDevice(admin.getId(), device.getId()); + + mockData(admin.getId()); + } + + private void mockData(long userId) { + if (Boolean.valueOf(Context.getProps().getProperty("database.mock"))) { + try { + + Device device = new Device(); + device.setName("test1"); + device.setUniqueId("123456789012345"); + addDevice(device); + linkDevice(userId, device.getId()); + + Position position = new Position(); + position.setDeviceId(device.getId()); + position.setTime(new Date()); + addPosition(position); + + } catch (SQLException error) { + Log.warning(error); + } + } } public User login(String email, String password) throws SQLException { |