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

View File

@ -9,21 +9,17 @@
storage-type: SQL storage-type: SQL
# The JDBC-Connection URL that is used to connect to the database. # The JDBC-Connection URL that is used to connect to the database.
# The format for this url is: jdbc:[driver]://[host]:[port]/[database] # The format for this url is usually something like: jdbc:[driver]://[host]:[port]/[database]?user=[user]&password=[password]
db-url: "jdbc:mysql://localhost:3306/bluemap" # The exact format of the url is determined by the JDBC-Driver you are using.
db-connection-url: "jdbc:mysql://localhost/bluemap?permitMysqlScheme"
# The user that is used to connect to the database #db-connection-url: "jdbc:mariadb://localhost/bluemap?user=root"
user: "root" #db-connection-url: "jdbc:mysql://localhost:3306/bluemap?user=root&password=password"
# The password that is used to connect to the database
# (If this is empty, no password is used to connect to the database)
password: ""
# This can be used to load a custom jdbc-driver from a .jar file. # 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, # 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/ # 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: # 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. # 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. # 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," + "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);*/ "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 { } else {
Class.forName(config.getDriverClass().get()); Class.forName(config.getDriverClass().get());
this.dataSource = createDataSource(config.getDbUrl(), config.getUser(), config.getPassword()); this.dataSource = createDataSource(config.getConnectionUrl());
} }
} else { } else {
this.dataSource = createDataSource(config.getDbUrl(), config.getUser(), config.getPassword()); this.dataSource = createDataSource(config.getConnectionUrl());
} }
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
throw new SQLDriverException("The driver-class does not exist.", 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(); this.hiresCompression = config.getCompression();
} }
public SQLStorage(String dbUrl, String user, String password, Compression compression) { public SQLStorage(String dbUrl, Compression compression) {
this.dataSource = createDataSource(dbUrl, user, password); this.dataSource = createDataSource(dbUrl);
this.hiresCompression = compression; this.hiresCompression = compression;
} }
@ -621,25 +621,17 @@ private int lookupFK(String table, String idField, String valueField, String val
}, 2); }, 2);
} }
private DataSource createDataSource(String dbUrl, String user, String password) { private DataSource createDataSource(String dbUrl) {
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( Logger.global.logInfo("Creating datasource for: " + dbUrl);
dbUrl, return createDataSource(new DriverManagerConnectionFactory(dbUrl));
user,
password
);
return createDataSource(connectionFactory);
} }
private DataSource createDataSource(String dbUrl, String user, String password, Driver driver) { private DataSource createDataSource(String dbUrl, Driver driver) {
Properties properties = new Properties(); Logger.global.logInfo("Creating driver-datasource for: " + dbUrl);
properties.put("user", user);
properties.put("password", password);
ConnectionFactory connectionFactory = new DriverConnectionFactory( ConnectionFactory connectionFactory = new DriverConnectionFactory(
driver, driver,
dbUrl, dbUrl,
properties new Properties()
); );
return createDataSource(connectionFactory); return createDataSource(connectionFactory);

View File

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