Class Database

java.lang.Object
me.deecaad.core.database.Database
Direct Known Subclasses:
HikariBased

public abstract class Database extends Object
  • Constructor Details

  • Method Details

    • getType

      public DatabaseType 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 used
      statement - the statement used
      resultSet - the result set used
    • executeUpdate

      public void executeUpdate(boolean forceSync, String... sql)
      Runs given SQL statement in async. Used to e.g. INSERT, UPDATE or DELETE.
      Parameters:
      forceSync - should only be true on reload and disable
      sql - the sql statement to run
    • executeQuery

      public void executeQuery(String sql, Consumer<ResultSet> consumer)
      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 run
      consumer - the consumer for result set of query
    • printResultSet

      public void printResultSet(ResultSet rs)
      Simple method to print the result set to console.
      Parameters:
      rs - the query result
    • getConnection

      public abstract Connection getConnection() throws SQLException
      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

      public abstract void close() throws SQLException
      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