- 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 voidconfigureJdbi(Consumer<org.jdbi.v3.core.Jdbi> jdbiConsumer)Allows to access the backingJdbiinstance to enrich its configuration, such as registering mappers.static Databasecreate(org.jdbi.v3.core.Jdbi jdbi)Creates a new database backed by the givenJdbiinstance.<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 aHandleto 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 aHandleto 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 givenJdbiinstance.The given JDBI instance will be enriched as follows:
SqlObjectPluginwill be installed- Column and argument mappers will ba added for the
Snowflaketype SerializableTransactionRunnerwill be set as transaction handler
It will automatically install the
SqlObjectPlugin, and register column mappers and arguments for theSnowflaketype. It will also enable support automatic retrying of failed serializable transactions.- Parameters:
jdbi- theJdbiinstance backing the database- Returns:
- a new
Database
-
configureJdbi
public void configureJdbi(Consumer<org.jdbi.v3.core.Jdbi> jdbiConsumer)
Allows to access the backingJdbiinstance to enrich its configuration, such as registering mappers. Note thatSqlObjectPluginis 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
Databaseclass.- Parameters:
jdbiConsumer- the consumer that mutates the backingJdbiinstance
-
useHandle
public reactor.core.publisher.Mono<Void> useHandle(org.jdbi.v3.core.HandleConsumer<?> handleConsumer)
Acquires aHandleto perform actions on the database. When the consumer returns, the handle is closed and the returnedMonocompletes. 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- aConsumerusing the handle- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Monowill emitDatabaseExceptionwith the underlying JDBI exception as the cause
-
withHandle
public <T> reactor.core.publisher.Mono<T> withHandle(org.jdbi.v3.core.HandleCallback<T,?> handleCallback)
Acquires aHandleto perform actions on the database. When the callback returns, the handle is closed and the returnedMonocompletes. 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- aConsumerusing the handle- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Monowill emitDatabaseExceptionwith 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 returnedMonocompletes. 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- aConsumerusing the transaction- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Monowill emitDatabaseExceptionwith 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 returnedMonocompletes. 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- aConsumerusing the transaction- Returns:
- a Mono that completes when the consumer returns. If an error is
received, the
Monowill emitDatabaseExceptionwith 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 returnedMonocompletes. 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
Monowill emitDatabaseExceptionwith 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 returnedMonocompletes. 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
Monowill emitDatabaseExceptionwith the underlying JDBI exception as the cause
-
-