Class Database

java.lang.Object
com.github.alex1304.ultimategdbot.api.Database

public class Database
extends java.lang.Object
Manages interactions with the database.
  • Constructor Summary

    Constructors 
    Constructor Description
    Database()  
  • Method Summary

    Modifier and Type Method Description
    void configure()
    Initializes the database.
    reactor.core.publisher.Mono<java.lang.Void> delete​(java.lang.Object obj)
    Deletes an object from database
    <T,​ K extends java.io.Serializable>
    reactor.core.publisher.Mono<T>
    findByID​(java.lang.Class<T> entityClass, K key)
    Allows to find a database entity by its ID.
    reactor.core.publisher.Mono<java.lang.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.
    <V> reactor.core.publisher.Flux<V> performTransactionWhen​(java.util.function.Function<org.hibernate.Session,​org.reactivestreams.Publisher<V>> txAsyncFunction)
    Allows to manipulate a Session in an asynchronous context.
    <T> reactor.core.publisher.Flux<T> query​(java.lang.Class<T> entityClass, java.lang.String query, java.lang.Object... params)
    Makes a simple query to the database.
    reactor.core.publisher.Mono<java.lang.Void> save​(java.lang.Object obj)
    Saves an object in database

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • configure

      public void configure()
      Initializes the database.
    • findByID

      public <T,​ K extends java.io.Serializable> reactor.core.publisher.Mono<T> findByID​(java.lang.Class<T> entityClass, K key)
      Allows to find a database entity by its ID.
      Type Parameters:
      T - The entity type
      K - the ID type
      Parameters:
      entityClass - class of the entity
      key - the ID
      Returns:
      a Mono emitting the entity, if found
    • query

      public <T> reactor.core.publisher.Flux<T> query​(java.lang.Class<T> entityClass, java.lang.String query, java.lang.Object... params)
      Makes a simple query to the database.
      Type Parameters:
      T - the entity type
      Parameters:
      entityClass - the entity type to fetch
      query - the HQL query
      params - the query params
      Returns:
      a Flux emitting the results of the query
    • save

      public reactor.core.publisher.Mono<java.lang.Void> save​(java.lang.Object obj)
      Saves an object in database
      Parameters:
      obj - the object to save
      Returns:
      a Mono that completes when it has saved
    • delete

      public reactor.core.publisher.Mono<java.lang.Void> delete​(java.lang.Object obj)
      Deletes an object from database
      Parameters:
      obj - the object to save
      Returns:
      a Mono that completes when it has deleted
    • performEmptyTransaction

      public reactor.core.publisher.Mono<java.lang.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 variant performTransaction(Function) is preferred.
      Parameters:
      txConsumer - the transaction consuming a Session object
      Returns:
      a Mono completing when the transaction terminates successfully
    • performTransaction

      public <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 variant performEmptyTransaction(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.
    • performTransactionWhen

      public <V> reactor.core.publisher.Flux<V> performTransactionWhen​(java.util.function.Function<org.hibernate.Session,​org.reactivestreams.Publisher<V>> txAsyncFunction)
      Allows to manipulate a Session in an asynchronous context. The session provides a Publisher which completion indicates that the transaction can be committed and the session closed.
      Type Parameters:
      V - the type of value that the transaction may produce
      Parameters:
      txAsyncFunction - a function that manipulates a Session and returns a Publisher completing when the transaction is ready to be committed
      Returns:
      a Flux completing when the transaction terminates successfully and may emit values that constitute the result of the transaction