Klasse Database

java.lang.Object
de.delinkedde.mobarenareborn.persistence.Database

public final class Database extends Object
Owns the SQLite connection and applies the schema.

A single connection is kept open for the lifetime of the plugin. The driver is bundled and relocated, so no external dependency is required at runtime; it is resolved through the JDBC service loader by the jdbc:sqlite: URL.

The schema is created on connect() if absent. Statements are executed synchronously; callers that run on the main server thread should keep queries small or defer them to an asynchronous task.

  • Konstruktordetails

    • Database

      public Database(@NotNull @NotNull String jdbcUrl)
      Parameter:
      jdbcUrl - the JDBC URL, for example jdbc:sqlite:/path/playerdata.db or jdbc:sqlite::memory:
  • Methodendetails

    • forDataFolder

      @NotNull public static @NotNull Database forDataFolder(@NotNull @NotNull File dataFolder)
      Creates a database backed by playerdata.db inside the given data folder.
      Parameter:
      dataFolder - the plugin data folder
      Gibt zurück:
      a new, unconnected database
    • connect

      public void connect() throws SQLException
      Opens the connection and ensures the schema exists.
      Löst aus:
      SQLException - if the connection cannot be opened or the schema cannot be applied
    • close

      public void close()
      Closes the connection if open. Safe to call more than once.
    • connection

      @NotNull public @NotNull Connection connection()
      Gibt zurück:
      the open connection
      Löst aus:
      IllegalStateException - if connect() has not been called