- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.database.Database
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configureJdbi(Consumer<org.jdbi.v3.core.Jdbi> jdbiConsumer)
Allows to access the backingJdbi
instance to enrich its configuration, such as registering mappers.static Database
create(org.jdbi.v3.core.Jdbi jdbi)
Creates a new database backed by the givenJdbi
instance.<T> reactor.core.publisher.Mono<T>
inTransaction(org.jdbi.v3.core.HandleCallback<T,?> txCallback)
Performs a database transaction.<E> reactor.core.publisher.Mono<Void>
useExtension(Class<E> extensionType, org.jdbi.v3.core.extension.ExtensionConsumer<E,?> extensionConsumer)
Uses a JDBI Extension.reactor.core.publisher.Mono<Void>
useHandle(org.jdbi.v3.core.HandleConsumer<?> handleConsumer)
Acquires aHandle
to perform actions on the database.reactor.core.publisher.Mono<Void>
useTransaction(org.jdbi.v3.core.HandleConsumer<?> txConsumer)
Performs a database transaction.<T,E>
reactor.core.publisher.Mono<T>withExtension(Class<E> extensionType, org.jdbi.v3.core.extension.ExtensionCallback<T,E,?> extensionCallback)
Uses a JDBI Extension.<T> reactor.core.publisher.Mono<T>
withHandle(org.jdbi.v3.core.HandleCallback<T,?> handleCallback)
Acquires aHandle
to perform actions on the database.
-
-
-
Method Detail
-
create
public static Database create(org.jdbi.v3.core.Jdbi jdbi)
Creates a new database backed by the givenJdbi
instance.The given JDBI instance will be enriched as follows:
SqlObjectPlugin
will be installed- Column and argument mappers will ba added for the
Snowflake
type SerializableTransactionRunner
will be set as transaction handler
It will automatically install the
SqlObjectPlugin
, and register column mappers and arguments for theSnowflake
type. It will also enable support automatic retrying of failed serializable transactions.- Parameters:
jdbi
- theJdbi
instance backing the database- Returns:
- a new
Database
-
configureJdbi
public void configureJdbi(Consumer<org.jdbi.v3.core.Jdbi> jdbiConsumer)
Allows to access the backingJdbi
instance to enrich its configuration, such as registering mappers. Note thatSqlObjectPlugin
is already installed by default.This method MUST NOT attempt to open any connection to the database. Database operations should be made using the other methods of this
Database
class.- Parameters:
jdbiConsumer
- the consumer that mutates the backingJdbi
instance
-
useHandle
public reactor.core.publisher.Mono<Void> useHandle(org.jdbi.v3.core.HandleConsumer<?> handleConsumer)
Acquires aHandle
to perform actions on the database. When the consumer returns, the handle is closed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the database operations don't need to return a result. If you need to return a result, use
withHandle(HandleCallback)
instead.- Parameters:
handleConsumer
- aConsumer
using the handle- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
withHandle
public <T> reactor.core.publisher.Mono<T> withHandle(org.jdbi.v3.core.HandleCallback<T,?> handleCallback)
Acquires aHandle
to perform actions on the database. When the callback returns, the handle is closed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the database operations need to return a result. If you don't need to return a result, use
useHandle(HandleConsumer)
instead.- Type Parameters:
T
- the type of the desired return value- Parameters:
handleCallback
- aConsumer
using the handle- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
useTransaction
public reactor.core.publisher.Mono<Void> useTransaction(org.jdbi.v3.core.HandleConsumer<?> txConsumer)
Performs a database transaction. When the consumer returns, the trasnaction is committed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the database operations don't need to return a result. If you need to return a result, use
withHandle(HandleCallback)
instead.- Parameters:
txConsumer
- aConsumer
using the transaction- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
inTransaction
public <T> reactor.core.publisher.Mono<T> inTransaction(org.jdbi.v3.core.HandleCallback<T,?> txCallback)
Performs a database transaction. When the callback returns, the transaction is committed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the database operations need to return a result. If you don't need to return a result, use
useHandle(HandleConsumer)
instead.- Type Parameters:
T
- the type of the desired return value- Parameters:
txCallback
- aConsumer
using the transaction- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
useExtension
public <E> reactor.core.publisher.Mono<Void> useExtension(Class<E> extensionType, org.jdbi.v3.core.extension.ExtensionConsumer<E,?> extensionConsumer)
Uses a JDBI Extension. When the consumer returns, any acquired connections are closed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the use of the extension doesn't need to return a result. If you need to return a result, use
withExtension(Class, ExtensionCallback)
instead.- Type Parameters:
E
- the extension type- Parameters:
extensionType
- the type of extension to useextensionConsumer
- the consumer that uses the extension- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
withExtension
public <T,E> reactor.core.publisher.Mono<T> withExtension(Class<E> extensionType, org.jdbi.v3.core.extension.ExtensionCallback<T,E,?> extensionCallback)
Uses a JDBI Extension. When the callback returns, any acquired connections are closed and the returnedMono
completes. The task is executed onSchedulers.boundedElastic()
as database interactions are likely to perform blocking I/O operations.This is suited for when the use of the extension needs to return a result. If you don't need to return a result, use
useExtension(Class, ExtensionConsumer)
instead.- Type Parameters:
T
- the return value typeE
- the extension type- Parameters:
extensionType
- the type of extension to useextensionCallback
- the callback that uses the extension- Returns:
- a Mono that completes when the callback returns. If an error is
received, the
Mono
will emitDatabaseException
with the underlying JDBI exception as the cause
-
-