finally redid the settings file so DB connections just depend on json file on disk
This commit is contained in:
parent
67298f6734
commit
2d54e2b831
@ -17,14 +17,14 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
||||
*/
|
||||
public class DBCPDataSource {
|
||||
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
|
||||
static {
|
||||
public static Connection getConnection() throws SQLException {
|
||||
BasicDataSource ds = new BasicDataSource();
|
||||
try {
|
||||
settingsInit settingsInit = new settingsInit();
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.racetimerURL);
|
||||
ds.setUsername(settings.racetimerUser);
|
||||
ds.setPassword(settings.racetimerPassword);
|
||||
ds.setUrl(settingsInit.racetimerURL);
|
||||
ds.setUsername(settingsInit.racetimerUser);
|
||||
ds.setPassword(settingsInit.racetimerPassword);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
@ -32,9 +32,6 @@ public class DBCPDataSource {
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,14 @@ import org.apache.commons.dbcp2.BasicDataSource;
|
||||
*/
|
||||
public class DBCPDataSource2 {
|
||||
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
|
||||
static {
|
||||
public static Connection getConnection() throws SQLException {
|
||||
BasicDataSource ds = new BasicDataSource();
|
||||
try {
|
||||
settingsInit settingsInit = new settingsInit();
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.forumURL);
|
||||
ds.setUsername(settings.forumUser);
|
||||
ds.setPassword(settings.forumPassword);
|
||||
ds.setUrl(settingsInit.forumURL);
|
||||
ds.setUsername(settingsInit.forumUser);
|
||||
ds.setPassword(settingsInit.forumPassword);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
@ -32,9 +32,6 @@ public class DBCPDataSource2 {
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSource.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Christian
|
||||
*/
|
||||
public class settingsInit {
|
||||
String text;
|
||||
public static String racetimerURL = "";
|
||||
static String racetimerUser = "";
|
||||
static String racetimerPassword = "";
|
||||
static String forumURL = "";
|
||||
static String forumUser = "";
|
||||
static String forumPassword = "";
|
||||
|
||||
public settingsInit() {
|
||||
try {
|
||||
this.text = new String(Files.readAllBytes(Paths.get("/opt/tomcat/race_backend_settings.json")), StandardCharsets.UTF_8);
|
||||
JSONObject obj = new JSONObject(text);
|
||||
this.racetimerURL = obj.getString("racetimerURL");
|
||||
this.racetimerUser = obj.getString("racetimerUser");
|
||||
this.racetimerPassword = obj.getString("racetimerPassword");
|
||||
this.forumURL = obj.getString("forumURL");
|
||||
this.forumUser = obj.getString("forumUser");
|
||||
this.forumPassword = obj.getString("forumPassword");
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(settingsInit.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user