diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-09 11:43:50 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-09 11:43:50 +1300 |
commit | 81a7fba08c37fd8032c747ada5d9a77340298647 (patch) | |
tree | b7b0534868dfc130d1b8779ff0b8c7bf8c149dc5 /src/org/traccar/database/DataManager.java | |
parent | 8e555ab17b231d93ab51713d6cb25510c0f92476 (diff) | |
download | trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.tar.gz trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.tar.bz2 trackermap-server-81a7fba08c37fd8032c747ada5d9a77340298647.zip |
Fix some FindBugs and style issues
Diffstat (limited to 'src/org/traccar/database/DataManager.java')
-rw-r--r-- | src/org/traccar/database/DataManager.java | 51 |
1 files changed, 27 insertions, 24 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()); + + } } } |