Reverted to MySQL connector for ease of use
This commit is contained in:
1 parent
df731d467b
commit
da82ed9491
5 files changed
+34
-29
No files matched your search
+16
-6
@@ -9,15 +9,25 @@ cache:
|
|||||||
- .m2/repository/
|
- .m2/repository/
|
||||||
- target/
|
- target/
|
||||||
|
|
||||||
build:
|
stages:
|
||||||
stage: build
|
- compile
|
||||||
|
- test
|
||||||
|
- package
|
||||||
|
|
||||||
|
compile:
|
||||||
|
stage: compile
|
||||||
script:
|
script:
|
||||||
- "mvn --batch-mode package"
|
- "mvn --batch-mode compile"
|
||||||
artifacts:
|
|
||||||
paths:
|
|
||||||
- target/netneutrality-jar-with-dependencies.jar
|
|
||||||
|
|
||||||
test:
|
test:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- "mvn --batch-mode test"
|
- "mvn --batch-mode test"
|
||||||
|
|
||||||
|
package:
|
||||||
|
stage: package
|
||||||
|
script:
|
||||||
|
- "mvn --batch-mode package"
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- target/netneutrality-jar-with-dependencies.jar
|
||||||
@@ -108,9 +108,9 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mariadb.jdbc</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mariadb-java-client</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>2.7.4</version>
|
<version>8.0.26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
<artifactId>commons-logging</artifactId>
|
<artifactId>commons-logging</artifactId>
|
||||||
<version>1.1.1</version>
|
<version>1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package netneutrality.db;
|
package netneutrality.db;
|
||||||
|
|
||||||
|
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||||
import org.mariadb.jdbc.MariaDbPoolDataSource;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -27,14 +26,16 @@ public class MysqlConnector {
|
|||||||
* @return {@link MysqlConnector}
|
* @return {@link MysqlConnector}
|
||||||
*/
|
*/
|
||||||
public MysqlConnector connect() throws SQLException {
|
public MysqlConnector connect() throws SQLException {
|
||||||
|
MysqlDataSource dataSource = new MysqlDataSource();
|
||||||
MariaDbPoolDataSource dataSource = new MariaDbPoolDataSource();
|
|
||||||
dataSource.setUser(dbUser);
|
dataSource.setUser(dbUser);
|
||||||
dataSource.setPassword(dbPass);
|
dataSource.setPassword(dbPass);
|
||||||
dataSource.setServerName(dbHost);
|
dataSource.setServerName(dbHost);
|
||||||
dataSource.setPort(3306);
|
dataSource.setPort(3306);
|
||||||
dataSource.setDatabaseName(dbName);
|
dataSource.setDatabaseName(dbName);
|
||||||
|
dataSource.setAutoReconnect(true);
|
||||||
|
dataSource.setAutoReconnectForPools(true);
|
||||||
c = dataSource.getConnection();
|
c = dataSource.getConnection();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import netneutrality.MusicBot;
|
import netneutrality.MusicBot;
|
||||||
import netneutrality.db.entities.EntityInterface;
|
import netneutrality.db.entities.EntityInterface;
|
||||||
@@ -24,13 +22,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
public class MysqlDatabase {
|
public class MysqlDatabase {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(MysqlDatabase.class);
|
private final static Logger logger = LoggerFactory.getLogger(MysqlDatabase.class);
|
||||||
private Connection connection;
|
protected Connection connection;
|
||||||
private final String dbName;
|
private final String dbName;
|
||||||
|
|
||||||
protected enum CommandType {
|
protected enum CommandType {
|
||||||
SELECT("SELECT"), INSERT("INSERT"), UPDATE("UPDATE"), DELETE("DELETE");
|
SELECT("SELECT"), INSERT("INSERT"), UPDATE("UPDATE"), DELETE("DELETE");
|
||||||
|
|
||||||
private String type;
|
private final String type;
|
||||||
|
|
||||||
CommandType(String type) {
|
CommandType(String type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -49,10 +47,10 @@ public class MysqlDatabase {
|
|||||||
String dbHost = Settings.getInstance().get("mysql.host");
|
String dbHost = Settings.getInstance().get("mysql.host");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.info("Connecting to database...");
|
logger.info(String.format("Connecting to database '%1$s' at %2$s:3306", dbName, dbHost));
|
||||||
connection = new MysqlConnector(dbName, dbUser, dbHost, dbPass).connect().getConnection();
|
connection = new MysqlConnector(dbName, dbUser, dbHost, dbPass).connect().getConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
logger.error("Error connecting to database. Shutting down..");
|
logger.error("Error connecting to database. Shutting down..", e);
|
||||||
MusicBot.shutdown();
|
MusicBot.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,13 +112,9 @@ public class MysqlDatabase {
|
|||||||
return executeUpdate(sql, params);
|
return executeUpdate(sql, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean exists(String table, String key, String value) {
|
public boolean exists(String table, String key, String value) {
|
||||||
ResultSet rs = prepareAndExecute("SELECT 1 FROM " + table + " WHERE " + key + " = ?", value);
|
return prepareAndExecuteAsync("SELECT 1 FROM " + table + " WHERE " + key + " = ?", value).blocking().isEmpty();
|
||||||
try {
|
|
||||||
return rs.next();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized int executeUpdate(String sql, Object[] params) {
|
private synchronized int executeUpdate(String sql, Object[] params) {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
<Configuration status="WARN" xmlns="http://logging.apache.org/log4j/2.0/config">
|
<Configuration status="WARN" xmlns="http://logging.apache.org/log4j/2.0/config">
|
||||||
<Appenders>
|
<Appenders>
|
||||||
<Console name="Console" target="SYSTEM_OUT">
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
<PatternLayout pattern="%d{${LOG_DATEFORMAT_PATTERN:-yyyy-MM-dd HH:mm:ss.SSS}} %highlight{${LOG_LEVEL_PATTERN:-%5p}}{FATAL=red blink, ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue} [%15.15t] %style{%-40.40C}{cyan} : %m%n" />
|
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight{%-5level}{STYLE=Logback} %logger - %msg%n" />
|
||||||
</Console>
|
</Console>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Logger name="netneutrality" level="trace" additivity="false">
|
<Logger name="netneutrality" level="info" additivity="false">
|
||||||
<AppenderRef ref="Console"/>
|
<AppenderRef ref="Console"/>
|
||||||
</Logger>
|
</Logger>
|
||||||
<Root level="error">
|
<Root level="error">
|
||||||
|
|||||||
Reference in new issue
Block a user