public class DataManager
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
@NotNull java.sql.Connection |
connection
The
connection to the database |
@NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>> |
dataCache
Cached data from
StringData
Key: table name
Value:
Key: target
Value:
Key: data key
Value: data value
|
@NotNull SQLDialect |
dialect
The
SQL dialect for the database |
@NotNull StorageConfig |
storageConfig
The
storage.yml config for the plugin |
@NotNull java.lang.String |
tablePrefix
The table prefix for the database (only for remote connections)
|
| Constructor and Description |
|---|
DataManager(@NotNull AnnoyingFile<?> file)
Connect to the configured database and create the pre-defined tables/columns
|
| Modifier and Type | Method and Description |
|---|---|
void |
createTablesColumns(@NotNull java.util.Map<java.lang.String,java.util.Set<java.lang.String>> tablesColumns)
Create the given tables and columns in the database
|
@NotNull java.sql.ResultSet |
executeQuery(@NotNull java.lang.String query)
Execute a query on the database
|
void |
executeUpdate(@NotNull java.lang.String query,
@Nullable java.lang.String errorMessage)
Execute an update on the database
|
@NotNull java.lang.String |
getTableName(@NotNull java.lang.String tableName)
Get the full name of a table with the
prefix
This just returns the table name if it's a local database or there isn't prefix |
void |
saveCache()
Saves the data from the cache to the database
|
void |
startCacheSavingOnInterval(@NotNull AnnoyingPlugin plugin,
long interval)
Starts the asynchronous task to save the cache on an interval
|
@NotNull public final @NotNull StorageConfig storageConfig
storage.yml config for the plugin@NotNull public final @NotNull java.sql.Connection connection
connection to the database@NotNull public final @NotNull SQLDialect dialect
SQL dialect for the database@NotNull public final @NotNull java.lang.String tablePrefix
@NotNull public final @NotNull java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>> dataCache
StringData
public DataManager(@NotNull
@NotNull AnnoyingFile<?> file)
throws ConnectionException
file - the file to get the connection information fromConnectionException - if the connection to the database fails for any reasonpublic void createTablesColumns(@NotNull
@NotNull java.util.Map<java.lang.String,java.util.Set<java.lang.String>> tablesColumns)
tablesColumns - the tables and columns to create@NotNull
public @NotNull java.lang.String getTableName(@NotNull
@NotNull java.lang.String tableName)
prefix
tableName - the name of the table to get@NotNull
public @NotNull java.sql.ResultSet executeQuery(@NotNull
@NotNull java.lang.String query)
throws java.sql.SQLException
query - the query to execute (careful of SQL injection!)result of the queryjava.sql.SQLException - if the query fails for any reasonpublic void executeUpdate(@NotNull
@NotNull java.lang.String query,
@Nullable
@Nullable java.lang.String errorMessage)
query - the query to execute (careful of SQL injection!)errorMessage - the error message to print if the query failspublic void startCacheSavingOnInterval(@NotNull
@NotNull AnnoyingPlugin plugin,
long interval)
plugin - the plugin to run the task oninterval - the interval in ticks to save the cachepublic void saveCache()