Package me.deecaad.core.database
Class Database
java.lang.Object
me.deecaad.core.database.Database
- Direct Known Subclasses:
HikariBased
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Has to be called on when server disables or plugin is reloadedvoidclose(@Nullable Connection connection, @Nullable Statement statement, @Nullable ResultSet resultSet) Closes all given variables.voidexecuteQuery(String sql, Consumer<ResultSet> consumer) Runs given SQL query in async.voidexecuteUpdate(boolean forceSync, String... sql) Runs given SQL statement in async.abstract ConnectionAllows getting connections to the database.getType()abstract booleanisClosed()voidSimple method to print the result set to console.
-
Constructor Details
-
Database
-
-
Method Details
-
getType
- Returns:
- the type of this database
-
close
public void close(@Nullable @Nullable Connection connection, @Nullable @Nullable Statement statement, @Nullable @Nullable ResultSet resultSet) Closes all given variables. This has to be called after every query.- Parameters:
connection- the connection usedstatement- the statement usedresultSet- the result set used
-
executeUpdate
Runs given SQL statement in async. Used to e.g. INSERT, UPDATE or DELETE.- Parameters:
forceSync- should only be true on reload and disablesql- the sql statement to run
-
executeQuery
Runs given SQL query in async. Used to SELECT.Keep in mind that the consumer is still ran in async. You should wrap the data first and then do what you wish with it using sync task.
- Parameters:
sql- the sql query to runconsumer- the consumer for result set of query
-
printResultSet
Simple method to print the result set to console.- Parameters:
rs- the query result
-
getConnection
Allows getting connections to the database. When using MySQL this fetches one connection from the pool. When using SQLite this creates new connection in most cases.- Returns:
- one connection to the database
- Throws:
SQLException
-
close
Has to be called on when server disables or plugin is reloaded- Throws:
SQLException
-
isClosed
public abstract boolean isClosed()- Returns:
- whether this database is closed
-