Interface DBSession

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
DBSessionImpl

public interface DBSession extends AutoCloseable
DBSession implements common DB query execution handlers.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes this DBSession and cleans up related objects.
    void
    exec(Consumer<javax.persistence.EntityManager> fn)
    Execute given function without opening a new transaction.
    <T> T
    exec(Function<javax.persistence.EntityManager,T> fn)
    Execute given function without opening a new transaction.
    <E extends Throwable>
    void
    execChecked(ThrowingConsumer<javax.persistence.EntityManager,E> fn)
    Execute given function that can throw a checked exception without opening a new transaction.
    <T, E extends Throwable>
    T
    execChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn)
    Execute given function that can throw a checked exception without opening a new transaction.
    void
    execTx(int maxTransactionRetries, Consumer<javax.persistence.EntityManager> fn)
    Execute given function within a transaction.
    <T> T
    execTx(int maxTransactionRetries, Function<javax.persistence.EntityManager,T> fn)
    Execute given function within a transaction.
    void
    execTx(Consumer<javax.persistence.EntityManager> fn)
    Execute given function within a transaction.
    <T> T
    execTx(Function<javax.persistence.EntityManager,T> fn)
    Execute given function within a transaction.
    <E extends Throwable>
    void
    execTxChecked(int maxTransactionRetries, ThrowingConsumer<javax.persistence.EntityManager,E> fn)
    Execute given function that can throw a checked exception within a transaction.
    <T, E extends Throwable>
    T
    execTxChecked(int maxTransactionRetries, ThrowingFunction<javax.persistence.EntityManager,T,E> fn)
    Execute given function that can throw a checked exception within a transaction.
    <E extends Throwable>
    void
    execTxChecked(ThrowingConsumer<javax.persistence.EntityManager,E> fn)
    Execute given function that can throw a checked exception within a transaction.
    <T, E extends Throwable>
    T
    execTxChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn)
    Execute given function that can throw a checked exception within a transaction.
  • Method Details

    • exec

      void exec(Consumer<javax.persistence.EntityManager> fn)
      Execute given function without opening a new transaction. It should be assumed that the EntityManager was newly created.
      Parameters:
      fn - Function to execute.
    • execChecked

      <E extends Throwable> void execChecked(ThrowingConsumer<javax.persistence.EntityManager,E> fn) throws E
      Execute given function that can throw a checked exception without opening a new transaction. It should be assumed that the EntityManager was newly created.
      Type Parameters:
      E - Exception type that could be thrown by fn.
      Parameters:
      fn - Function to execute.
      Throws:
      E - Exception thrown by fn.
    • exec

      <T> T exec(Function<javax.persistence.EntityManager,T> fn)
      Execute given function without opening a new transaction. It should be assumed that the EntityManager was newly created. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
    • execChecked

      <T, E extends Throwable> T execChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Execute given function that can throw a checked exception without opening a new transaction. It should be assumed that the EntityManager was newly created. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      E - Exception type that could be thrown by fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
      Throws:
      E - Exception thrown by fn.
    • execTx

      void execTx(Consumer<javax.persistence.EntityManager> fn)
      Execute given function within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried.
      Parameters:
      fn - Function to execute.
    • execTxChecked

      <E extends Throwable> void execTxChecked(ThrowingConsumer<javax.persistence.EntityManager,E> fn) throws E
      Execute given function that can throw a checked exception within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried.
      Type Parameters:
      E - Exception type that could be thrown by fn.
      Parameters:
      fn - Function to execute.
      Throws:
      E - Exception thrown by fn.
    • execTx

      void execTx(int maxTransactionRetries, Consumer<javax.persistence.EntityManager> fn)
      Execute given function within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried.
      Parameters:
      maxTransactionRetries - Maximal number of times fn can be executed again in case of transaction errors.
      fn - Function to execute.
    • execTxChecked

      <E extends Throwable> void execTxChecked(int maxTransactionRetries, ThrowingConsumer<javax.persistence.EntityManager,E> fn) throws E
      Execute given function that can throw a checked exception within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried.
      Type Parameters:
      E - Exception type that could be thrown by fn.
      Parameters:
      maxTransactionRetries - Maximal number of times fn can be executed again in case of transaction errors.
      fn - Function to execute.
      Throws:
      E - Exception thrown by fn.
    • execTx

      <T> T execTx(Function<javax.persistence.EntityManager,T> fn)
      Execute given function within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
    • execTxChecked

      <T, E extends Throwable> T execTxChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Execute given function that can throw a checked exception within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      E - Exception type that could be thrown by fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
      Throws:
      E - Exception thrown by fn.
    • execTx

      <T> T execTx(int maxTransactionRetries, Function<javax.persistence.EntityManager,T> fn)
      Execute given function within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      Parameters:
      maxTransactionRetries - Maximal number of times fn can be executed again in case of transaction errors.
      fn - Function to execute.
      Returns:
      Object fn has returned.
    • execTxChecked

      <T, E extends Throwable> T execTxChecked(int maxTransactionRetries, ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Execute given function that can throw a checked exception within a transaction. There can only be a single transaction per DBSession object. It should be assumed that the EntityManager and transaction are reused if this method is executed again. Further, should be assumed that fn could be executed multiple times if the transaction fails and should be retried. The return value of given function is returned.
      Type Parameters:
      T - Return type of fn.
      E - Exception type that could be thrown by fn.
      Parameters:
      maxTransactionRetries - Maximal number of times fn can be executed again in case of transaction errors.
      fn - Function to execute.
      Returns:
      Object fn has returned.
      Throws:
      E - Exception thrown by fn.
    • close

      void close()
      Closes this DBSession and cleans up related objects.
      Specified by:
      close in interface AutoCloseable