Class Database

java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractDatabase
com.github.darksoulq.abyssallib.common.database.relational.sql.Database

public class Database extends AbstractDatabase
A SQLite database implementation that manages the file lifecycle and connection state. It uses a cached thread pool for asynchronous operations and enforces foreign key constraints by default.
  • Constructor Details

    • Database

      public Database(File file)
      Constructs a new Database instance and initializes a cached thread pool for async tasks.
      Parameters:
      file - The File representing the SQLite database storage.
  • Method Details

    • connect

      public void connect() throws Exception
      Establishes a connection to the SQLite database. Creates parent directories if they do not exist and enables foreign key support.
      Throws:
      Exception - If a directory creation or database connection error occurs.
    • disconnect

      public void disconnect() throws Exception
      Closes the database connection and shuts down the asynchronous thread pool.
      Throws:
      Exception - If a database access error occurs during closure.
    • getConnection

      public Connection getConnection()
      Retrieves the currently active SQLite connection.
      Specified by:
      getConnection in class AbstractDatabase
      Returns:
      The Connection instance.
    • executor

      public QueryExecutor executor()
      Creates a new QueryExecutor instance tied to this database's connection and thread pool.
      Returns:
      A new QueryExecutor for performing database operations.
    • transaction

      public void transaction(Consumer<QueryExecutor> action)
      Executes a set of operations within a SQL transaction. The operations are performed via a QueryExecutor.
      Parameters:
      action - A Consumer providing a QueryExecutor within the transaction scope.
    • transactionResult

      public <T> T transactionResult(Function<QueryExecutor, T> action)
      Executes a set of operations within a SQL transaction and returns a result.
      Type Parameters:
      T - The type of the result.
      Parameters:
      action - A Function providing a QueryExecutor and returning a value of type T.
      Returns:
      The result of the transaction.