Interface Database
-
public interface Database
Manages interactions with the database.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
configure()
Initializes the database.reactor.core.publisher.Mono<Void>
delete(Object obj)
Deletes an object from database<T,K extends Serializable>
reactor.core.publisher.Mono<T>findByID(Class<T> entityClass, K key)
Allows to find a database entity by its ID.<T,K extends Serializable>
reactor.core.publisher.Mono<T>findByIDOrCreate(Class<T> entityClass, K key, java.util.function.BiConsumer<? super T,K> keySetter)
Allows to find a database entity by its ID.reactor.core.publisher.Mono<Void>
performEmptyTransaction(java.util.function.Consumer<org.hibernate.Session> txConsumer)
Allows to perform more complex actions with the database, by having full control on the current transaction.<V> reactor.core.publisher.Mono<V>
performTransaction(java.util.function.Function<org.hibernate.Session,V> txFunction)
Allows to perform more complex actions with the database, by having full control on the current transaction.<T> reactor.core.publisher.Flux<T>
query(Class<T> entityClass, String query, Object... params)
Makes a simple query to the database.reactor.core.publisher.Mono<Void>
save(Object obj)
Saves an object in database
-
-
-
Method Detail
-
configure
void configure()
Initializes the database.
-
findByID
<T,K extends Serializable> reactor.core.publisher.Mono<T> findByID(Class<T> entityClass, K key)
Allows to find a database entity by its ID.- Type Parameters:
T
- The entity typeK
- the ID type- Parameters:
entityClass
- class of the entitykey
- the ID- Returns:
- a Mono emitting the entity, if found
-
findByIDOrCreate
<T,K extends Serializable> reactor.core.publisher.Mono<T> findByIDOrCreate(Class<T> entityClass, K key, java.util.function.BiConsumer<? super T,K> keySetter)
Allows to find a database entity by its ID. If not found, a new entity is created- Type Parameters:
T
- The entity typeK
- the ID type- Parameters:
entityClass
- class of the entitykey
- the IDkeySetter
- the biconsumer that assigns the ID to the newly created entity- Returns:
- a Mono emitting the entity, if found
-
query
<T> reactor.core.publisher.Flux<T> query(Class<T> entityClass, String query, Object... params)
Makes a simple query to the database.- Type Parameters:
T
- the entity type- Parameters:
entityClass
- the entity type to fetchquery
- the HQL queryparams
- the query params- Returns:
- a Flux emitting the results of the query
-
save
reactor.core.publisher.Mono<Void> save(Object obj)
Saves an object in database- Parameters:
obj
- the object to save- Returns:
- a Mono that completes when it has saved
-
delete
reactor.core.publisher.Mono<Void> delete(Object obj)
Deletes an object from database- Parameters:
obj
- the object to save- Returns:
- a Mono that completes when it has deleted
-
performEmptyTransaction
reactor.core.publisher.Mono<Void> performEmptyTransaction(java.util.function.Consumer<org.hibernate.Session> txConsumer)
Allows to perform more complex actions with the database, by having full control on the current transaction. This method does not return a value. If you need to perform a transaction that returns a value upon completion, the variantperformTransaction(Function)
is preferred.- Parameters:
txConsumer
- the transaction consuming a Session object- Returns:
- a Mono completing when the transaction terminates successfully
-
performTransaction
<V> reactor.core.publisher.Mono<V> performTransaction(java.util.function.Function<org.hibernate.Session,V> txFunction)
Allows to perform more complex actions with the database, by having full control on the current transaction. This method can return a value upon completion. If you don't need a return value for the transaction, the variantperformEmptyTransaction(Consumer)
is preferred.- Type Parameters:
V
- the type of the returned value- Parameters:
txFunction
- the transaction accepting a Session object and returning a value- Returns:
- a Mono completing when the transaction terminates successfully and emitting a value.
-
-