From c6ce35720e315b0c28a52ef11ada67bf00642270 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 21 May 2015 16:13:31 +1200 Subject: Add mock position data --- src/org/traccar/database/DataManager.java | 40 +++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'src/org') 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 deviceResultSetProcessor = new NamedParameterStatement.ResultSetProcessor() { @@ -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 { -- cgit v1.2.3