aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/database
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-09 11:43:50 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-09 11:43:50 +1300
commit81a7fba08c37fd8032c747ada5d9a77340298647 (patch)
treeb7b0534868dfc130d1b8779ff0b8c7bf8c149dc5 /src/org/traccar/database
parent8e555ab17b231d93ab51713d6cb25510c0f92476 (diff)
downloadtrackermap-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')
-rw-r--r--src/org/traccar/database/DataManager.java51
-rw-r--r--src/org/traccar/database/QueryBuilder.java2
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;