Remove the user & password settings for database, as they should be added to the jdbc-connection string

This commit is contained in:
Lukas Rieger (Blue) 2022-08-17 23:27:56 +02:00
parent 89ca7053dd
commit bd88b2979d
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
4 changed files with 21 additions and 49 deletions

View File

@ -40,9 +40,7 @@ public class SQLConfig extends StorageConfig implements SQLStorageSettings {
@DebugDump private String driverJar = null;
@DebugDump private String driverClass = null;
@DebugDump private String dbUrl = "jdbc:mysql://localhost:3306/bluemap";
@DebugDump private String user = "root";
private String password = "";
private String connectionUrl = "jdbc:mysql://localhost/bluemap?permitMysqlScheme";
@DebugDump private Compression compression = Compression.GZIP;
@ -65,18 +63,8 @@ public Optional<String> getDriverClass() {
}
@Override
public String getDbUrl() {
return dbUrl;
}
@Override
public String getUser() {
return user;
}
@Override
public String getPassword() {
return password;
public String getConnectionUrl() {
return connectionUrl;
}
@Override

View File

@ -9,21 +9,17 @@
storage-type: SQL
# The JDBC-Connection URL that is used to connect to the database.
# The format for this url is: jdbc:[driver]://[host]:[port]/[database]
db-url: "jdbc:mysql://localhost:3306/bluemap"
# The user that is used to connect to the database
user: "root"
# The password that is used to connect to the database
# (If this is empty, no password is used to connect to the database)
password: ""
# The format for this url is usually something like: jdbc:[driver]://[host]:[port]/[database]?user=[user]&password=[password]
# The exact format of the url is determined by the JDBC-Driver you are using.
db-connection-url: "jdbc:mysql://localhost/bluemap?permitMysqlScheme"
#db-connection-url: "jdbc:mariadb://localhost/bluemap?user=root"
#db-connection-url: "jdbc:mysql://localhost:3306/bluemap?user=root&password=password"
# This can be used to load a custom jdbc-driver from a .jar file.
# E.g. if your runtime-environment is not already providing the sql-driver you need,
# you could download the MariaDB JDBC-Connector from https://mariadb.com/downloads/connectors/connectors-data-access/java8-connector/
# place it in the './bluemap' folder and use is like this:
#driver-jar: "bluemap/mariadb-java-client-2.7.4.jar"
#driver-jar: "bluemap/mariadb-java-client-3.0.7.jar"
# This is the driver-class that bluemap will try to load and use.
# Check the documentation of the driver you are using if you don't know this.

View File

@ -81,13 +81,13 @@ public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDr
"Instead you'll need to add your driver-jar to the classpath when starting your server," +
"e.g. using the '-classpath' command-line argument", ex);*/
}
this.dataSource = createDataSource(config.getDbUrl(), config.getUser(), config.getPassword(), driver);
this.dataSource = createDataSource(config.getConnectionUrl(), driver);
} else {
Class.forName(config.getDriverClass().get());
this.dataSource = createDataSource(config.getDbUrl(), config.getUser(), config.getPassword());
this.dataSource = createDataSource(config.getConnectionUrl());
}
} else {
this.dataSource = createDataSource(config.getDbUrl(), config.getUser(), config.getPassword());
this.dataSource = createDataSource(config.getConnectionUrl());
}
} catch (ClassNotFoundException ex) {
throw new SQLDriverException("The driver-class does not exist.", ex);
@ -98,8 +98,8 @@ public SQLStorage(SQLStorageSettings config) throws MalformedURLException, SQLDr
this.hiresCompression = config.getCompression();
}
public SQLStorage(String dbUrl, String user, String password, Compression compression) {
this.dataSource = createDataSource(dbUrl, user, password);
public SQLStorage(String dbUrl, Compression compression) {
this.dataSource = createDataSource(dbUrl);
this.hiresCompression = compression;
}
@ -621,25 +621,17 @@ private int lookupFK(String table, String idField, String valueField, String val
}, 2);
}
private DataSource createDataSource(String dbUrl, String user, String password) {
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
dbUrl,
user,
password
);
return createDataSource(connectionFactory);
private DataSource createDataSource(String dbUrl) {
Logger.global.logInfo("Creating datasource for: " + dbUrl);
return createDataSource(new DriverManagerConnectionFactory(dbUrl));
}
private DataSource createDataSource(String dbUrl, String user, String password, Driver driver) {
Properties properties = new Properties();
properties.put("user", user);
properties.put("password", password);
private DataSource createDataSource(String dbUrl, Driver driver) {
Logger.global.logInfo("Creating driver-datasource for: " + dbUrl);
ConnectionFactory connectionFactory = new DriverConnectionFactory(
driver,
dbUrl,
properties
new Properties()
);
return createDataSource(connectionFactory);

View File

@ -12,11 +12,7 @@ public interface SQLStorageSettings {
Optional<String> getDriverClass();
String getDbUrl();
String getUser();
String getPassword();
String getConnectionUrl();
Compression getCompression();