Package ch.njol.skript.variables
Class SQLStorage
java.lang.Object
ch.njol.skript.variables.VariablesStorage
ch.njol.skript.variables.SQLStorage
- All Implemented Interfaces:
Closeable
- Direct Known Subclasses:
MySQLStorage
,SQLiteStorage
TODO create a metadata table to store some properties (e.g. Skript version, Yggdrasil version) -- but what if some variables cannot be converted? move them to a different table?
TODO create my own database connector or find a better one
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
Fields inherited from class ch.njol.skript.variables.VariablesStorage
backupTask, closed, connectionLock, databaseName, file
-
Constructor Summary
ConstructorDescriptionSQLStorage
(String name, String createTableQuery) Creates a SQLStorage with a create table query. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called after all storages have been loaded, and variables have been redistributed if settings have changed.protected void
void
close()
Called when Skript gets disabled.protected boolean
connect()
(Re)connects to the database.protected void
Disconnects from the database.protected File
Gets the file needed for this variable storage from the given file name.@Nullable String
Retrieve the create query with the tableName in itabstract @Nullable lib.PatPeter.SQLibrary.Database
initialize
(SectionNode config) Initializes an SQL database with the user provided configuration section for loading the database.protected boolean
Doesn't lock the database for reading (it's not used anywhere else, and locking while loading will interfere with loaded variables being deleted byVariables.variableLoaded(String, Object, VariablesStorage)
).protected boolean
Saves a variable.void
setTableName
(String tableName) Methods inherited from class ch.njol.skript.variables.VariablesStorage
clearChangesQueue, getValue, getValue, load, requiresFile, startBackupTask
-
Field Details
-
MAX_VARIABLE_NAME_LENGTH
public static final int MAX_VARIABLE_NAME_LENGTH- See Also:
-
MAX_CLASS_CODENAME_LENGTH
public static final int MAX_CLASS_CODENAME_LENGTH- See Also:
-
MAX_VALUE_SIZE
public static final int MAX_VALUE_SIZE- See Also:
-
-
Constructor Details
-
SQLStorage
Creates a SQLStorage with a create table query.- Parameters:
name
- The name to be sent through this constructor when newInstance creates this class.createTableQuery
- The create table query to send to the SQL engine.
-
-
Method Details
-
getTableName
-
setTableName
-
initialize
Initializes an SQL database with the user provided configuration section for loading the database.- Parameters:
config
- The configuration from the config.sk that defines this database.- Returns:
- A Database implementation from SQLibrary.
-
getFormattedCreateQuery
Retrieve the create query with the tableName in it- Returns:
- the create query with the tableName in it (%s -> tableName)
-
load_i
Doesn't lock the database for reading (it's not used anywhere else, and locking while loading will interfere with loaded variables being deleted byVariables.variableLoaded(String, Object, VariablesStorage)
).- Specified by:
load_i
in classVariablesStorage
- Returns:
- Whether the database could be loaded successfully, i.e. whether the config is correct and all variables could be loaded.
-
allLoaded
protected void allLoaded()Description copied from class:VariablesStorage
Called after all storages have been loaded, and variables have been redistributed if settings have changed. This should commit the first transaction (which is not empty if variables have been moved from another database to this one or vice versa), and start repeating transactions if applicable.- Specified by:
allLoaded
in classVariablesStorage
-
getFile
Description copied from class:VariablesStorage
Gets the file needed for this variable storage from the given file name.Will only be called if
VariablesStorage.requiresFile()
istrue
.- Specified by:
getFile
in classVariablesStorage
- Parameters:
file
- the given file name.- Returns:
- the
File
object.
-
connect
protected boolean connect()Description copied from class:VariablesStorage
(Re)connects to the database.Not called on the first connect: do this in
VariablesStorage.load_i(SectionNode)
. An error should be printed by this method prior to returningfalse
.- Specified by:
connect
in classVariablesStorage
- Returns:
- whether the connection could be re-established.
-
disconnect
protected void disconnect()Description copied from class:VariablesStorage
Disconnects from the database.- Specified by:
disconnect
in classVariablesStorage
-
save
protected boolean save(String name, @Nullable @Nullable String type, @Nullable @org.jetbrains.annotations.Nullable byte[] value) Description copied from class:VariablesStorage
Saves a variable.This is called from the main thread while variables are transferred between databases, and from the
VariablesStorage.writeThread
afterwards.type
andvalue
are bothnull
iff this call is to delete the variable.- Specified by:
save
in classVariablesStorage
- Parameters:
name
- the name of the variable.type
- the type of the variable.value
- the serialized value of the variable.- Returns:
- Whether the variable was saved.
-
close
public void close()Description copied from class:VariablesStorage
Called when Skript gets disabled.The default implementation will wait for all variables to be saved before setting
VariablesStorage.closed
totrue
and stopping thewrite thread
.Therefore, make sure to call
super.close()
if this method is overridden.- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classVariablesStorage
-
checkDatabase
protected void checkDatabase()
-