diff options
Diffstat (limited to 'src/org/traccar/database')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 51 | ||||
-rw-r--r-- | src/org/traccar/database/QueryBuilder.java | 2 |
2 files changed, 28 insertions, 25 deletions
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 7f30fc6f3..66134d51e 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -144,18 +144,20 @@ public class DataManager implements IdentityManager { if (config.getString("web.type", "new").equals("new") || config.getString("web.type", "new").equals("api")) { - Connection connection = dataSource.getConnection(); - ResultSet result = connection.getMetaData().getTables( - connection.getCatalog(), null, null, null); - boolean exist = false; - String checkTable = config.getString("database.checkTable"); - while (result.next()) { - if (result.getString("TABLE_NAME").equalsIgnoreCase(checkTable)) { - exist = true; - break; + + try (Connection connection = dataSource.getConnection(); + ResultSet result = connection.getMetaData().getTables(connection.getCatalog(), null, null, null)) { + + String checkTable = config.getString("database.checkTable"); + while (result.next()) { + if (result.getString("TABLE_NAME").equalsIgnoreCase(checkTable)) { + exist = true; + break; + } } } + if (exist) { String schemaVersionQuery = getQuery("database.selectSchemaVersion"); @@ -174,25 +176,26 @@ public class DataManager implements IdentityManager { } } - return; - } + } else { - QueryBuilder.create(dataSource, getQuery("database.createSchema")).executeUpdate(); + QueryBuilder.create(dataSource, getQuery("database.createSchema")).executeUpdate(); - User admin = new User(); - admin.setName("admin"); - admin.setEmail("admin"); - admin.setAdmin(true); - admin.setPassword("admin"); - addUser(admin); + User admin = new User(); + admin.setName("admin"); + admin.setEmail("admin"); + admin.setAdmin(true); + admin.setPassword("admin"); + addUser(admin); - Server server = new Server(); - server.setRegistration(true); - QueryBuilder.create(dataSource, getQuery("database.insertServer")) - .setObject(server) - .executeUpdate(); + Server server = new Server(); + server.setRegistration(true); + QueryBuilder.create(dataSource, getQuery("database.insertServer")) + .setObject(server) + .executeUpdate(); - mockData(admin.getId()); + mockData(admin.getId()); + + } } } diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 5846d4285..07a351c05 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -41,7 +41,7 @@ import org.traccar.helper.Log; import org.traccar.model.Factory; import org.traccar.model.MiscFormatter; -public class QueryBuilder { +public final class QueryBuilder { private final Map<String, List<Integer>> indexMap = new HashMap<>(); private Connection connection; |