Class Database
java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractDatabase
com.github.darksoulq.abyssallib.common.database.relational.postgres.Database
A PostgreSQL database implementation that manages remote connections.
This class handles persistent connections to a PostgreSQL server, featuring an automated keep-alive scheduler to prevent connection timeouts and thread-safe connection retrieval.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect()Establishes a connection to the PostgreSQL database and starts the keep-alive task.voidShuts down the keep-alive scheduler, the async pool, and closes the JDBC connection.executor()Creates a new QueryExecutor instance for this database.Retrieves the active connection, automatically reconnecting if it has been closed or invalidated.voidtransaction(Consumer<QueryExecutor> action) Executes an operation within a SQL transaction using a QueryExecutor.<T> TtransactionResult(Function<QueryExecutor, T> action) Executes an operation within a SQL transaction and returns a computed result.Methods inherited from class AbstractDatabase
executeTransaction, executeTransactionResult, getAsyncPool
-
Constructor Details
-
Database
-
-
Method Details
-
connect
-
disconnect
-
getConnection
Retrieves the active connection, automatically reconnecting if it has been closed or invalidated.- Specified by:
getConnectionin classAbstractDatabase- Returns:
- The active
Connection. - Throws:
SQLException- If reconnection fails.
-
executor
Creates a new QueryExecutor instance for this database.- Returns:
- A new
QueryExecutor.
-
transaction
Executes an operation within a SQL transaction using a QueryExecutor.- Parameters:
action- AConsumerthat performs the transaction logic.
-
transactionResult
Executes an operation within a SQL transaction and returns a computed result.- Type Parameters:
T- The return type.- Parameters:
action- AFunctionthat performs the transaction logic and returns a result.- Returns:
- The result of the transaction.
-