Klasse Database

java.lang.Object
de.delinkedde.areashopreborn.persistence.Database
Alle implementierten Schnittstellen:
AutoCloseable

public final class Database extends Object implements AutoCloseable
Owns the SQLite connection configuration and single-threaded database executor.
  • Konstruktordetails

    • Database

      public Database(org.bukkit.plugin.java.JavaPlugin plugin, String fileName) throws IOException, SQLException
      Opens or creates the configured SQLite database and applies migrations.
      Parameter:
      plugin - owning plugin
      fileName - database file relative to the plugin data directory
      Löst aus:
      IOException - when the data directory or migration resource cannot be read
      SQLException - when SQLite initialization fails
  • Methodendetails

    • openConnection

      public Connection openConnection() throws SQLException
      Opens a configured SQLite connection with foreign keys, WAL, and a busy timeout enabled.
      Gibt zurück:
      new caller-owned connection
      Löst aus:
      SQLException - when a connection cannot be established
    • inspect

      public DatabaseStatus inspect() throws SQLException
      Runs SQLite integrity, migration, and journal-mode checks on a caller-selected thread.
      Gibt zurück:
      immutable database status
      Löst aus:
      SQLException - when SQLite cannot perform the inspection
    • backupTo

      public int backupTo(Path target) throws IOException, SQLException
      Creates a transactionally consistent standalone SQLite snapshot.

      This method must run on the database executor. SQLite VACUUM INTO includes committed WAL content without copying live -wal or -shm files.

      Parameter:
      target - new snapshot file
      Gibt zurück:
      highest schema migration stored in the verified snapshot
      Löst aus:
      IOException - when the target directory cannot be prepared
      SQLException - when snapshot creation or integrity verification fails
    • estimatedBackupSizeBytes

      public long estimatedBackupSizeBytes() throws SQLException
      Estimates the largest normal SQLite snapshot from the current page count.

      The estimate is deliberately conservative because VACUUM INTO can compact unused pages. It allows callers to reject snapshots that exceed their disk budget before SQLite starts writing the target file.

      Gibt zurück:
      current database page count multiplied by its page size
      Löst aus:
      SQLException - when SQLite metadata cannot be read
    • inspectBackup

      public static Database.BackupStatus inspectBackup(Path backup) throws IOException, SQLException
      Inspects an existing standalone SQLite backup without modifying journal mode.
      Parameter:
      backup - snapshot file to inspect
      Gibt zurück:
      integrity and schema status
      Löst aus:
      IOException - when the path is not a regular file
      SQLException - when SQLite cannot inspect the snapshot
    • supplyAsync

      public <T> CompletableFuture<T> supplyAsync(Database.SqlSupplier<T> supplier)
      Runs a value-producing database operation on the dedicated database thread.
      Typparameter:
      T - result type
      Parameter:
      supplier - operation to execute
      Gibt zurück:
      future completed with the operation result
    • runAsync

      public CompletableFuture<Void> runAsync(Database.SqlRunnable runnable)
      Runs a database operation on the dedicated database thread.
      Parameter:
      runnable - operation to execute
      Gibt zurück:
      completion future
    • close

      public void close()
      Stops accepting database work and waits briefly for queued operations.
      Angegeben von:
      close in Schnittstelle AutoCloseable