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
@@ -1,7 +1,6 @@
|
||||
package netneutrality.db;
|
||||
|
||||
|
||||
import org.mariadb.jdbc.MariaDbPoolDataSource;
|
||||
import com.mysql.cj.jdbc.MysqlDataSource;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -27,14 +26,16 @@ public class MysqlConnector {
|
||||
* @return {@link MysqlConnector}
|
||||
*/
|
||||
public MysqlConnector connect() throws SQLException {
|
||||
|
||||
MariaDbPoolDataSource dataSource = new MariaDbPoolDataSource();
|
||||
MysqlDataSource dataSource = new MysqlDataSource();
|
||||
dataSource.setUser(dbUser);
|
||||
dataSource.setPassword(dbPass);
|
||||
dataSource.setServerName(dbHost);
|
||||
dataSource.setPort(3306);
|
||||
dataSource.setDatabaseName(dbName);
|
||||
dataSource.setAutoReconnect(true);
|
||||
dataSource.setAutoReconnectForPools(true);
|
||||
c = dataSource.getConnection();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,7 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.sql.Timestamp;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import netneutrality.MusicBot;
|
||||
import netneutrality.db.entities.EntityInterface;
|
||||
@@ -24,13 +22,13 @@ import org.slf4j.LoggerFactory;
|
||||
public class MysqlDatabase {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MysqlDatabase.class);
|
||||
private Connection connection;
|
||||
protected Connection connection;
|
||||
private final String dbName;
|
||||
|
||||
protected enum CommandType {
|
||||
SELECT("SELECT"), INSERT("INSERT"), UPDATE("UPDATE"), DELETE("DELETE");
|
||||
|
||||
private String type;
|
||||
private final String type;
|
||||
|
||||
CommandType(String type) {
|
||||
this.type = type;
|
||||
@@ -49,10 +47,10 @@ public class MysqlDatabase {
|
||||
String dbHost = Settings.getInstance().get("mysql.host");
|
||||
|
||||
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();
|
||||
} catch (SQLException e) {
|
||||
logger.error("Error connecting to database. Shutting down..");
|
||||
logger.error("Error connecting to database. Shutting down..", e);
|
||||
MusicBot.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -114,13 +112,9 @@ public class MysqlDatabase {
|
||||
return executeUpdate(sql, params);
|
||||
}
|
||||
|
||||
public synchronized boolean exists(String table, String key, String value) {
|
||||
ResultSet rs = prepareAndExecute("SELECT 1 FROM " + table + " WHERE " + key + " = ?", value);
|
||||
try {
|
||||
return rs.next();
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
public boolean exists(String table, String key, String value) {
|
||||
return prepareAndExecuteAsync("SELECT 1 FROM " + table + " WHERE " + key + " = ?", value).blocking().isEmpty();
|
||||
|
||||
}
|
||||
|
||||
private synchronized int executeUpdate(String sql, Object[] params) {
|
||||
|
||||
Reference in new issue
Block a user