Class Database
java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractDatabase
com.github.darksoulq.abyssallib.common.database.relational.h2.Database
An H2 database implementation managing local file-based storage.
This class handles connection lifecycles for H2, automatically managing directory creation and filename sanitization for the MVStore format.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Establishes a connection to the H2 database.voidCloses the database connection and shuts down the asynchronous pool.executor()Retrieves the current connection, attempting to reconnect if it has been closed.voidtransaction(Consumer<QueryExecutor> action) Executes logic within a transaction.<T> TtransactionResult(Function<QueryExecutor, T> action) Executes logic within a transaction and returns a result.Methods inherited from class AbstractDatabase
executeTransaction, executeTransactionResult, getAsyncPool
-
Constructor Details
-
Database
-
-
Method Details
-
connect
Establishes a connection to the H2 database.Automatically creates parent directories and strips the ".mv.db" suffix from the path if present to satisfy JDBC URL requirements. Configured with
MODE=MySQLfor compatibility andAUTO_SERVER=TRUEfor multi-connection support.- Throws:
Exception- If connection or directory creation fails.
-
disconnect
-
getConnection
Retrieves the current connection, attempting to reconnect if it has been closed.- Specified by:
getConnectionin classAbstractDatabase- Returns:
- A valid
Connection. - Throws:
SQLException- If reconnection is unsuccessful.
-
executor
- Returns:
- A new
QueryExecutorlinked to this database.
-
transaction
Executes logic within a transaction.- Parameters:
action- AConsumerreceiving a transactionalQueryExecutor.
-
transactionResult
Executes logic within a transaction and returns a result.- Type Parameters:
T- The result type.- Parameters:
action- AFunctionreceiving a transactionalQueryExecutor.- Returns:
- The result of the transaction.
-