Class Database
java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractDatabase
com.github.darksoulq.abyssallib.common.database.relational.sql.Database
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Establishes a connection to the SQLite database.voidCloses the database connection and shuts down the asynchronous thread pool.executor()Creates a new QueryExecutor instance tied to this database's connection and thread pool.Retrieves the currently active SQLite connection.voidtransaction(Consumer<QueryExecutor> action) Executes a set of operations within a SQL transaction.<T> TtransactionResult(Function<QueryExecutor, T> action) Executes a set of operations within a SQL transaction and returns a result.Methods inherited from class com.github.darksoulq.abyssallib.common.database.relational.AbstractDatabase
executeTransaction, executeTransactionResult, getAsyncPool
-
Constructor Details
-
Database
Constructs a new Database instance and initializes a cached thread pool for async tasks.- Parameters:
file- TheFilerepresenting the SQLite database storage.
-
-
Method Details
-
connect
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
Closes the database connection and shuts down the asynchronous thread pool.- Throws:
Exception- If a database access error occurs during closure.
-
getConnection
Retrieves the currently active SQLite connection.- Specified by:
getConnectionin classAbstractDatabase- Returns:
- The
Connectioninstance.
-
executor
Creates a new QueryExecutor instance tied to this database's connection and thread pool.- Returns:
- A new
QueryExecutorfor performing database operations.
-
transaction
Executes a set of operations within a SQL transaction. The operations are performed via aQueryExecutor.- Parameters:
action- AConsumerproviding aQueryExecutorwithin the transaction scope.
-
transactionResult
Executes a set of operations within a SQL transaction and returns a result.- Type Parameters:
T- The type of the result.- Parameters:
action- AFunctionproviding aQueryExecutorand returning a value of typeT.- Returns:
- The result of the transaction.
-