aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-12-27 17:33:00 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2020-12-27 17:33:00 -0800
commit21e5246ace0f6ecfd00248e5d29fd64a564e03c1 (patch)
treeba9cc6e7a0e5c5a36b65e286aab330d6055dee8b /src
parent9ca9f706524e5ac72d805dcafc21c12ccc109e5e (diff)
downloadtrackermap-server-21e5246ace0f6ecfd00248e5d29fd64a564e03c1.tar.gz
trackermap-server-21e5246ace0f6ecfd00248e5d29fd64a564e03c1.tar.bz2
trackermap-server-21e5246ace0f6ecfd00248e5d29fd64a564e03c1.zip
Migrate more config keys
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/Context.java3
-rw-r--r--src/main/java/org/traccar/config/Keys.java44
-rw-r--r--src/main/java/org/traccar/database/DataManager.java29
-rw-r--r--src/main/java/org/traccar/web/ConsoleServlet.java9
4 files changed, 66 insertions, 19 deletions
diff --git a/src/main/java/org/traccar/Context.java b/src/main/java/org/traccar/Context.java
index 2b031cfd3..2fb6998b8 100644
--- a/src/main/java/org/traccar/Context.java
+++ b/src/main/java/org/traccar/Context.java
@@ -23,6 +23,7 @@ import org.eclipse.jetty.util.URIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Config;
+import org.traccar.config.Keys;
import org.traccar.database.AttributesManager;
import org.traccar.database.BaseObjectManager;
import org.traccar.database.CalendarManager;
@@ -294,7 +295,7 @@ public final class Context {
client = ClientBuilder.newClient().register(new ObjectMapperContextResolver());
- if (config.hasKey("database.url")) {
+ if (config.hasKey(Keys.DATABASE_URL)) {
dataManager = new DataManager(config);
}
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index 77b42943b..206295499 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -76,6 +76,50 @@ public final class Keys {
"extra.handlers", String.class);
/**
+ * Path to the database driver JAR file. Traccar includes drivers for MySQL, PostgreSQL and H2 databases. If you use
+ * one of those, you don't need to specify this parameter.
+ */
+ public static final ConfigKey DATABASE_DRIVER_FILE = new ConfigKey(
+ "database.driverFile", String.class);
+
+ /**
+ * Database driver Java class. For H2 use 'org.h2.Driver'. MySQL driver class name is 'com.mysql.jdbc.Driver'.
+ */
+ public static final ConfigKey DATABASE_DRIVER = new ConfigKey(
+ "database.driver", String.class);
+
+ /**
+ * Database connection URL. By default Traccar uses H2 database.
+ */
+ public static final ConfigKey DATABASE_URL = new ConfigKey(
+ "database.url", String.class);
+
+ /**
+ * Database user name. Default administrator user for H2 database is 'sa'.
+ */
+ public static final ConfigKey DATABASE_USER = new ConfigKey(
+ "database.user", String.class);
+
+ /**
+ * Database user password. Default password for H2 admin (sa) user is empty.
+ */
+ public static final ConfigKey DATABASE_PASSWORD = new ConfigKey(
+ "database.password", String.class);
+
+ /**
+ * Path to Liquibase master changelog file.
+ */
+ public static final ConfigKey DATABASE_CHANGELOG = new ConfigKey(
+ "database.changelog", String.class);
+
+ /**
+ * SQL query to check connection status. Default value is 'SELECT 1'. For Oracle database you can use
+ * 'SELECT 1 FROM DUAL'.
+ */
+ public static final ConfigKey DATABASE_CHECK_CONNECTION = new ConfigKey(
+ "database.checkConnection", String.class);
+
+ /**
* Store original HEX or string data as "raw" attribute in the corresponding position.
*/
public static final ConfigKey DATABASE_SAVE_ORIGINAL = new ConfigKey(
diff --git a/src/main/java/org/traccar/database/DataManager.java b/src/main/java/org/traccar/database/DataManager.java
index 8b9690f77..ac4749a15 100644
--- a/src/main/java/org/traccar/database/DataManager.java
+++ b/src/main/java/org/traccar/database/DataManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.config.Config;
import org.traccar.Context;
+import org.traccar.config.Keys;
import org.traccar.helper.DateUtil;
import org.traccar.model.Attribute;
import org.traccar.model.Device;
@@ -100,7 +101,7 @@ public class DataManager {
} else {
- String driverFile = config.getString("database.driverFile");
+ String driverFile = config.getString(Keys.DATABASE_DRIVER_FILE);
if (driverFile != null) {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
try {
@@ -115,17 +116,17 @@ public class DataManager {
}
}
- String driver = config.getString("database.driver");
+ String driver = config.getString(Keys.DATABASE_DRIVER);
if (driver != null) {
Class.forName(driver);
}
HikariConfig hikariConfig = new HikariConfig();
- hikariConfig.setDriverClassName(config.getString("database.driver"));
- hikariConfig.setJdbcUrl(config.getString("database.url"));
- hikariConfig.setUsername(config.getString("database.user"));
- hikariConfig.setPassword(config.getString("database.password"));
- hikariConfig.setConnectionInitSql(config.getString("database.checkConnection", "SELECT 1"));
+ hikariConfig.setDriverClassName(driver);
+ hikariConfig.setJdbcUrl(config.getString(Keys.DATABASE_URL));
+ hikariConfig.setUsername(config.getString(Keys.DATABASE_USER));
+ hikariConfig.setPassword(config.getString(Keys.DATABASE_PASSWORD));
+ hikariConfig.setConnectionInitSql(config.getString(Keys.DATABASE_CHECK_CONNECTION, "SELECT 1"));
hikariConfig.setIdleTimeout(600000);
int maxPoolSize = config.getInteger("database.maxPoolSize");
@@ -293,19 +294,19 @@ public class DataManager {
private void initDatabaseSchema() throws SQLException, LiquibaseException {
- if (config.hasKey("database.changelog")) {
+ if (config.hasKey(Keys.DATABASE_CHANGELOG)) {
ResourceAccessor resourceAccessor = new FileSystemResourceAccessor();
Database database = DatabaseFactory.getInstance().openDatabase(
- config.getString("database.url"),
- config.getString("database.user"),
- config.getString("database.password"),
- config.getString("database.driver"),
+ config.getString(Keys.DATABASE_URL),
+ config.getString(Keys.DATABASE_USER),
+ config.getString(Keys.DATABASE_PASSWORD),
+ config.getString(Keys.DATABASE_DRIVER),
null, null, null, resourceAccessor);
Liquibase liquibase = new Liquibase(
- config.getString("database.changelog"), resourceAccessor, database);
+ config.getString(Keys.DATABASE_CHANGELOG), resourceAccessor, database);
liquibase.clearCheckSums();
diff --git a/src/main/java/org/traccar/web/ConsoleServlet.java b/src/main/java/org/traccar/web/ConsoleServlet.java
index 2b38a935a..0f3dcd8fd 100644
--- a/src/main/java/org/traccar/web/ConsoleServlet.java
+++ b/src/main/java/org/traccar/web/ConsoleServlet.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import org.h2.server.web.WebServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.traccar.Context;
+import org.traccar.config.Keys;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -39,9 +40,9 @@ public class ConsoleServlet extends WebServlet {
org.h2.server.web.WebServer server = (org.h2.server.web.WebServer) field.get(this);
ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|"
- + Context.getConfig().getString("database.driver") + "|"
- + Context.getConfig().getString("database.url") + "|"
- + Context.getConfig().getString("database.user"));
+ + Context.getConfig().getString(Keys.DATABASE_DRIVER) + "|"
+ + Context.getConfig().getString(Keys.DATABASE_URL) + "|"
+ + Context.getConfig().getString(Keys.DATABASE_USER));
Method method;