java.lang.Object
net.foxgenesis.watame.sql.DataManager
- All Implemented Interfaces:
AutoCloseable,IDatabaseManager
Class to connect and retrieve data from a database
- Author:
- Ashley
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance using the default database folder of "./repo/".DataManager(File folder) Create a new instance using the specified folder as the repository folder. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddGuild(net.dv8tion.jda.api.entities.Guild guild) Register a guild to be loaded during data retrieval.voidclose()voidconnect()Attempt to connect to the database.getDataForGuild(net.dv8tion.jda.api.entities.Guild guild) NEED_JAVADOCbooleanCheck if the database is connected and is ready for operations.booleanisReady()Check if all guild data has been processed and is ready for use.voidremoveGuild(net.dv8tion.jda.api.entities.Guild guild) Remove a guild from the data manager.voidretrieveDatabaseData(net.dv8tion.jda.api.JDA jda) Retrieve all data needed from the database.
-
Constructor Details
-
DataManager
public DataManager()Create a new instance using the default database folder of "./repo/".This method is effectively equivalent to:
new DataManager(new File("repo"))- Throws:
IllegalArgumentException- if folder exists and is not a directory- See Also:
-
DataManager
Create a new instance using the specified folder as the repository folder.- Parameters:
folder- -Filethat will be used as the repository folder- Throws:
IllegalArgumentException- iffolderexists and is not a directoryNullPointerException- iffolderis null- See Also:
-
-
Method Details
-
connect
Attempt to connect to the database.- Throws:
SQLException- if a database access error occursIOException- thrown if an error occurs while reading the InputStream of the resourceUnsupportedOperationException- if connection to the database failed
-
addGuild
public void addGuild(@Nonnull net.dv8tion.jda.api.entities.Guild guild) Register a guild to be loaded during data retrieval.- Parameters:
guild- -Guildto be loaded- Throws:
NullPointerException- ifguildisnull- See Also:
-
removeGuild
public void removeGuild(@Nonnull net.dv8tion.jda.api.entities.Guild guild) Remove a guild from the data manager.- Parameters:
guild- -Guildto be removed- Throws:
NullPointerException- ifguildisnull- See Also:
-
retrieveDatabaseData
public void retrieveDatabaseData(@Nonnull net.dv8tion.jda.api.JDA jda) Retrieve all data needed from the database.This will fire a
DataManager.DatabaseLoadedEventon the passedjdainstance on completion.- Parameters:
jda- -JDAinstance to use
-
getDataForGuild
Description copied from interface:IDatabaseManagerNEED_JAVADOC- Specified by:
getDataForGuildin interfaceIDatabaseManager- Returns:
-
isReady
public boolean isReady()Description copied from interface:IDatabaseManagerCheck if all guild data has been processed and is ready for use.- Specified by:
isReadyin interfaceIDatabaseManager- Returns:
- Returns
truewhen all data has been loaded from the database - See Also:
-
isConnectionValid
public boolean isConnectionValid()Description copied from interface:IDatabaseManagerCheck if the database is connected and is ready for operations.- Specified by:
isConnectionValidin interfaceIDatabaseManager- Returns:
- Returns
trueif is connected and ready
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-