Package xyz.srnyx.annoyingapi.storage
Class DataManager
- java.lang.Object
-
- xyz.srnyx.annoyingapi.storage.DataManager
-
public class DataManager extends java.lang.ObjectThe data manager for the plugin, used to manage the connection and data storage
-
-
Field Summary
Fields Modifier and Type Field Description @Nullable org.bukkit.scheduler.BukkitTaskcacheSavingTaskThe task that saves the cache on an interval@NotNull DialectdialectThedialectfor the database@NotNull AnnoyingPluginpluginThepluginto use for the data manager@NotNull StorageConfigstorageConfigThestorage.yml configfor the plugin@NotNull java.lang.StringtablePrefixThe table prefix for the database (only for remote connections)
-
Constructor Summary
Constructors Constructor Description DataManager(@NotNull StorageConfig config)Connect to the configured database and create the pre-defined tables/columns
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull DataManagerattemptDatabaseMigration()Attempts to migrate data fromstorage.ymltostorage-new.yml@NotNull java.lang.StringgetTableName(@NotNull java.lang.String tableName)Get the full name of a table with theprefix
This just returns the table name if it's a local database or there isn't prefixvoidtoggleIntervalCacheSaving()If saving the cache on an interval is enabled, this will start the asynchronous task to do that
If the feature is disabled, this will cancel the task if it exists
-
-
-
Field Detail
-
plugin
@NotNull public final @NotNull AnnoyingPlugin plugin
Thepluginto use for the data manager
-
storageConfig
@NotNull public final @NotNull StorageConfig storageConfig
Thestorage.yml configfor the plugin
-
tablePrefix
@NotNull public final @NotNull java.lang.String tablePrefix
The table prefix for the database (only for remote connections)
-
cacheSavingTask
@Nullable public @Nullable org.bukkit.scheduler.BukkitTask cacheSavingTask
The task that saves the cache on an interval- See Also:
toggleIntervalCacheSaving()
-
-
Constructor Detail
-
DataManager
public DataManager(@NotNull @NotNull StorageConfig config) throws ConnectionExceptionConnect to the configured database and create the pre-defined tables/columns- Parameters:
config- thestorage.yml configto use for the data manager- Throws:
ConnectionException- if the connection to the database fails for any reason
-
-
Method Detail
-
getTableName
@NotNull public @NotNull java.lang.String getTableName(@NotNull @NotNull java.lang.String tableName)Get the full name of a table with theprefix
This just returns the table name if it's a local database or there isn't prefix- Parameters:
tableName- the name of the table to get- Returns:
- the full name of the table
-
toggleIntervalCacheSaving
public void toggleIntervalCacheSaving()
If saving the cache on an interval is enabled, this will start the asynchronous task to do that
If the feature is disabled, this will cancel the task if it exists
-
attemptDatabaseMigration
@NotNull public @NotNull DataManager attemptDatabaseMigration()
Attempts to migrate data fromstorage.ymltostorage-new.yml- Returns:
- the new data manager
-
-