mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-11-12 10:13:55 +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();
|
String tableName = PluginConfig.getTableName();
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName +
|
PreparedStatement ps = util.prepareStatement("CREATE TABLE IF NOT EXISTS " + tableName +
|
||||||
|
@ -3,8 +3,8 @@ package de.butzlabben.world.util.database;
|
|||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
public abstract class DatabaseConnection implements DatabaseUtil {
|
public abstract class DatabaseConnection implements DatabaseUtil {
|
||||||
protected Connection connection;
|
Connection connection;
|
||||||
protected Object lock = new Object();
|
final Object lock = new Object();
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
@ -44,12 +44,4 @@ public abstract class DatabaseConnection implements DatabaseUtil {
|
|||||||
return ps.executeUpdate();
|
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;
|
package de.butzlabben.world.util.database;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -9,7 +8,6 @@ public interface DatabaseUtil {
|
|||||||
|
|
||||||
ResultSet executeQuery(PreparedStatement preparedStatement) throws SQLException;
|
ResultSet executeQuery(PreparedStatement preparedStatement) throws SQLException;
|
||||||
int executeUpdate(PreparedStatement preparedStatement) throws SQLException;
|
int executeUpdate(PreparedStatement preparedStatement) throws SQLException;
|
||||||
public Connection getConnection() throws SQLException;
|
|
||||||
PreparedStatement prepareStatement(String sql) throws SQLException;
|
PreparedStatement prepareStatement(String sql) throws SQLException;
|
||||||
void close();
|
void close();
|
||||||
void connect();
|
void connect();
|
||||||
|
@ -6,7 +6,7 @@ import java.sql.*;
|
|||||||
|
|
||||||
public class MysqlConnection extends DatabaseConnection {
|
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) {
|
synchronized (lock) {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
@ -6,7 +6,7 @@ import java.sql.*;
|
|||||||
|
|
||||||
public class SqliteConnection extends DatabaseConnection {
|
public class SqliteConnection extends DatabaseConnection {
|
||||||
|
|
||||||
public void connect(String file) {
|
private void connect(String file) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
try {
|
try {
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
Loading…
Reference in New Issue
Block a user