Package wtf.choco.veinminer.data
Class PersistentDataStorageSQL
java.lang.Object
wtf.choco.veinminer.data.PersistentDataStorageSQL
- All Implemented Interfaces:
PersistentDataStorage
- Direct Known Subclasses:
PersistentDataStorageMySQL
,PersistentDataStorageSQLite
A general abstract implementation of SQL-based
PersistentDataStorage
.-
Nested Class Summary
Nested classes/interfaces inherited from interface wtf.choco.veinminer.data.PersistentDataStorage
PersistentDataStorage.Type
-
Constructor Summary
ConstructorDescriptionPersistentDataStorageSQL
(@NotNull VeinMinerServer veinMiner) Construct a newPersistentDataStorageSQL
. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract @NotNull String
Get the statement used to create the players table.protected abstract @NotNull String
Get the statement used to insert a player's data into the players table.protected abstract @NotNull String
getSelectAllPlayerDataBatchQuery
(int count) Get the statement used to select multiple players' data from the players table.protected abstract @NotNull String
Get the statement used to select all of a player's data from the players table.@NotNull CompletableFuture<Integer>
importLegacyData
(@NotNull List<LegacyPlayerData> data) Import legacy data into the SQL database.final @NotNull CompletableFuture<Void>
init()
Initialize this persistent storage.protected abstract void
Initialize the SQL driver required for this implementation.@NotNull CompletableFuture<List<VeinMinerPlayer>>
load
(@NotNull Collection<? extends VeinMinerPlayer> players) Load the data of the given list ofVeinMinerPlayers
from disk.final @NotNull CompletableFuture<VeinMinerPlayer>
load
(@NotNull VeinMinerPlayer player) Load the data of the givenVeinMinerPlayer
from disk.protected abstract @NotNull Connection
Open a newConnection
to the database.@NotNull CompletableFuture<List<VeinMinerPlayer>>
save
(@NotNull Collection<? extends VeinMinerPlayer> players) Save the data of the given list ofVeinMinerPlayers
to disk.final @NotNull CompletableFuture<VeinMinerPlayer>
save
(@NotNull VeinMinerPlayer player) Save the data of the givenVeinMinerPlayer
to disk.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface wtf.choco.veinminer.data.PersistentDataStorage
getType
-
Constructor Details
-
PersistentDataStorageSQL
Construct a newPersistentDataStorageSQL
.- Parameters:
veinMiner
- the vein miner server
-
-
Method Details
-
init
Description copied from interface:PersistentDataStorage
Initialize this persistent storage.- Specified by:
init
in interfacePersistentDataStorage
- Returns:
- a
CompletableFuture
completed when the initialization has finished
-
save
@NotNull public final @NotNull CompletableFuture<VeinMinerPlayer> save(@NotNull @NotNull VeinMinerPlayer player) Description copied from interface:PersistentDataStorage
Save the data of the givenVeinMinerPlayer
to disk.If the VeinMinerPlayer is not dirty (according to
VeinMinerPlayer.isDirty()
), this method will complete immediately and not perform a save.- Specified by:
save
in interfacePersistentDataStorage
- Parameters:
player
- the player to save- Returns:
- a
CompletableFuture
completed when saving has finished
-
save
@NotNull public @NotNull CompletableFuture<List<VeinMinerPlayer>> save(@NotNull @NotNull Collection<? extends VeinMinerPlayer> players) Description copied from interface:PersistentDataStorage
Save the data of the given list ofVeinMinerPlayers
to disk.- Specified by:
save
in interfacePersistentDataStorage
- Parameters:
players
- the players to save- Returns:
- a
CompletableFuture
completed when saving has finished
-
load
@NotNull public final @NotNull CompletableFuture<VeinMinerPlayer> load(@NotNull @NotNull VeinMinerPlayer player) Description copied from interface:PersistentDataStorage
Load the data of the givenVeinMinerPlayer
from disk.- Specified by:
load
in interfacePersistentDataStorage
- Parameters:
player
- the player whose data to load- Returns:
- a
CompletableFuture
completed when loading has finished
-
load
@NotNull public @NotNull CompletableFuture<List<VeinMinerPlayer>> load(@NotNull @NotNull Collection<? extends VeinMinerPlayer> players) Description copied from interface:PersistentDataStorage
Load the data of the given list ofVeinMinerPlayers
from disk.- Specified by:
load
in interfacePersistentDataStorage
- Parameters:
players
- the players whose data to load- Returns:
- a
CompletableFuture
completed when loading has finished
-
importLegacyData
@NotNull public @NotNull CompletableFuture<Integer> importLegacyData(@NotNull @NotNull List<LegacyPlayerData> data) Import legacy data into the SQL database. This makes no attempt at preserving existing entries in the database.- Parameters:
data
- the data to import- Returns:
- a completable future, completed when the import has finished
-
initDriver
Initialize the SQL driver required for this implementation.- Throws:
ClassNotFoundException
- if the driver class could not be found- Implementation Specification:
- this should load and initialize the driver with a class load if necessary
-
openConnection
Open a newConnection
to the database.- Returns:
- a new connection
- Throws:
SQLException
- if an SQL exception occurred while opening the connection
-
getCreatePlayersTableStatement
Get the statement used to create the players table.- Returns:
- the create table statement
-
getInsertPlayerDataStatement
Get the statement used to insert a player's data into the players table.- Returns:
- the insert player data statement
-
getSelectAllPlayerDataQuery
Get the statement used to select all of a player's data from the players table.- Returns:
- the select player data statement
-
getSelectAllPlayerDataBatchQuery
Get the statement used to select multiple players' data from the players table.- Parameters:
count
- the amount of players that need selecting- Returns:
- the select player data statement
-