mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-11-10 09:59:30 +01:00
Refactored new code for #23
This commit is contained in:
parent
0358a634b2
commit
85a6c0a7c9
@ -88,7 +88,7 @@ public class PlayerPositions {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTables() {
|
||||
private void checkTables() {
|
||||
String tableName = PluginConfig.getTableName();
|
||||
try {
|
||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName +
|
||||
|
@ -3,8 +3,8 @@ package de.butzlabben.world.util.database;
|
||||
import java.sql.*;
|
||||
|
||||
public abstract class DatabaseConnection implements DatabaseUtil {
|
||||
protected Connection connection;
|
||||
protected Object lock = new Object();
|
||||
Connection connection;
|
||||
final Object lock = new Object();
|
||||
|
||||
public void close() {
|
||||
synchronized (lock) {
|
||||
@ -44,12 +44,4 @@ public abstract class DatabaseConnection implements DatabaseUtil {
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
synchronized (lock) {
|
||||
if (connection == null || connection.isClosed())
|
||||
connect();
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.butzlabben.world.util.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -9,7 +8,6 @@ public interface DatabaseUtil {
|
||||
|
||||
ResultSet executeQuery(PreparedStatement preparedStatement) throws SQLException;
|
||||
int executeUpdate(PreparedStatement preparedStatement) throws SQLException;
|
||||
public Connection getConnection() throws SQLException;
|
||||
PreparedStatement prepareStatement(String sql) throws SQLException;
|
||||
void close();
|
||||
void connect();
|
||||
|
@ -6,7 +6,7 @@ import java.sql.*;
|
||||
|
||||
public class MysqlConnection extends DatabaseConnection {
|
||||
|
||||
public void connect(String host, String database, String port, String user, String password) {
|
||||
private void connect(String host, String database, String port, String user, String password) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
@ -6,7 +6,7 @@ import java.sql.*;
|
||||
|
||||
public class SqliteConnection extends DatabaseConnection {
|
||||
|
||||
public void connect(String file) {
|
||||
private void connect(String file) {
|
||||
synchronized (lock) {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
|
Loading…
Reference in New Issue
Block a user