mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2025-02-27 03:32:22 +01:00
Add option to handle database connections from the PCGF PluginLib
This commit is contained in:
parent
63b97cc201
commit
74d2a547be
@ -2,7 +2,9 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="SqlDialectMappings">
|
<component name="SqlDialectMappings">
|
||||||
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java" dialect="MySQL" />
|
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQL.java" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/MySQLShared.java" dialect="MySQL" />
|
||||||
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java" dialect="GenericSQL" />
|
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQL.java" dialect="GenericSQL" />
|
||||||
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java" dialect="SQLite" />
|
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLite.java" dialect="SQLite" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/SQLiteShared.java" dialect="SQLite" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
8
pom.xml
8
pom.xml
@ -6,13 +6,13 @@
|
|||||||
<version>2.0-BETA-SNAPSHOT</version>
|
<version>2.0-BETA-SNAPSHOT</version>
|
||||||
|
|
||||||
<scm>
|
<scm>
|
||||||
<connection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</connection>
|
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
|
||||||
<developerConnection>scm:git:git@github.com:GeorgH93/Bukkit_Minepacks.git</developerConnection>
|
<developerConnection>scm:git:git@github.com:GeorgH93/Minepacks.git</developerConnection>
|
||||||
<url>git@github.com:GeorgH93/Bukkit_Minepacks.git</url>
|
<url>git@github.com:GeorgH93/Minepacks.git</url>
|
||||||
</scm>
|
</scm>
|
||||||
<issueManagement>
|
<issueManagement>
|
||||||
<system>GitHub</system>
|
<system>GitHub</system>
|
||||||
<url>https://github.com/GeorgH93/Bukkit_Minepacks/issues</url>
|
<url>https://github.com/GeorgH93/Minepacks/issues</url>
|
||||||
</issueManagement>
|
</issueManagement>
|
||||||
<ciManagement>
|
<ciManagement>
|
||||||
<system>jenkins</system>
|
<system>jenkins</system>
|
||||||
|
@ -29,7 +29,7 @@ AllowedGameModes: [ "SURVIVAL" ]
|
|||||||
# Defines how long a player have to wait till he can reopen his backpack.
|
# Defines how long a player have to wait till he can reopen his backpack.
|
||||||
# Time is in seconds. Values < 1 disable the cooldown.
|
# Time is in seconds. Values < 1 disable the cooldown.
|
||||||
CommandCooldown: -1
|
CommandCooldown: -1
|
||||||
# If enabled whe cooldown will be synced between servers (bungeecord network). It will also prevent players from leaving and joining to bypass the cooldown.
|
# If enabled whe cooldown will be synced between servers (BungeeCord network). It will also prevent players from leaving and joining to bypass the cooldown.
|
||||||
SyncCooldown: false
|
SyncCooldown: false
|
||||||
|
|
||||||
# Controls for the auto pickup on full inventory function
|
# Controls for the auto pickup on full inventory function
|
||||||
|
@ -17,11 +17,14 @@
|
|||||||
|
|
||||||
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.ConsoleColor;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
|
import at.pcgamingfreaks.Minepacks.Bukkit.API.Callback;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Backpack;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.OnDisconnect;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.OnDisconnect;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.UnCacheStrategie;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Database.UnCacheStrategies.UnCacheStrategie;
|
||||||
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
import at.pcgamingfreaks.PluginLib.Bukkit.PluginLib;
|
||||||
|
import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -69,20 +72,36 @@ public void close()
|
|||||||
unCacheStrategie.close();
|
unCacheStrategie.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Database getDatabase(Minepacks Plugin)
|
public static Database getDatabase(Minepacks plugin)
|
||||||
{
|
{
|
||||||
Database database;
|
Database database;
|
||||||
switch(Plugin.config.getDatabaseType().toLowerCase())
|
switch(plugin.config.getDatabaseType().toLowerCase())
|
||||||
{
|
{
|
||||||
case "mysql":
|
case "mysql":
|
||||||
database = new MySQL(Plugin); break;
|
database = new MySQL(plugin); break;
|
||||||
case "flat":
|
case "flat":
|
||||||
case "file":
|
case "file":
|
||||||
case "files":
|
case "files":
|
||||||
database = new Files(Plugin); break;
|
database = new Files(plugin); break;
|
||||||
|
case "external":
|
||||||
|
case "global":
|
||||||
|
case "shared":
|
||||||
|
DatabaseConnectionPool pool = PluginLib.getInstance().getDatabaseConnectionPool();
|
||||||
|
if(pool == null)
|
||||||
|
{
|
||||||
|
plugin.getLogger().warning(ConsoleColor.RED + "The shared connection pool is not initialized correctly!" + ConsoleColor.RESET);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch(pool.getDatabaseType().toLowerCase())
|
||||||
|
{
|
||||||
|
case "mysql": database = new MySQLShared(plugin, pool); break;
|
||||||
|
case "sqlite": database = new SQLiteShared(plugin, pool); break;
|
||||||
|
default: plugin.getLogger().warning(ConsoleColor.RED + "The database type of the shared pool is currently not supported!" + ConsoleColor.RESET); return null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
default:
|
default:
|
||||||
database = new SQLite(Plugin);
|
database = new SQLite(plugin);
|
||||||
}
|
}
|
||||||
database.init();
|
database.init();
|
||||||
return database;
|
return database;
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 GeorgH93
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class MySQLShared extends MySQL
|
||||||
|
{
|
||||||
|
private DatabaseConnectionPool pool;
|
||||||
|
|
||||||
|
protected MySQLShared(Minepacks minepacks, DatabaseConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(minepacks);
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HikariConfig getPoolConfig()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public Connection getConnection() throws SQLException
|
||||||
|
{
|
||||||
|
return pool.getConnection();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 GeorgH93
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package at.pcgamingfreaks.Minepacks.Bukkit.Database;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.Minepacks.Bukkit.Minepacks;
|
||||||
|
import at.pcgamingfreaks.PluginLib.Database.DatabaseConnectionPool;
|
||||||
|
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
|
||||||
|
public class SQLiteShared extends SQLite
|
||||||
|
{
|
||||||
|
private DatabaseConnectionPool pool;
|
||||||
|
|
||||||
|
protected SQLiteShared(Minepacks minepacks, DatabaseConnectionPool pool)
|
||||||
|
{
|
||||||
|
super(minepacks);
|
||||||
|
this.pool = pool;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected HikariConfig getPoolConfig()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Connection getConnection() throws SQLException
|
||||||
|
{
|
||||||
|
Connection connection = pool.getConnection();
|
||||||
|
try(Statement statement = connection.createStatement())
|
||||||
|
{
|
||||||
|
statement.execute("PRAGMA foreign_keys = ON"); // We need foreign keys!
|
||||||
|
}
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user