Class DBSessionImpl

java.lang.Object
org.opencastproject.db.DBSessionImpl
All Implemented Interfaces:
AutoCloseable, DBSession

public class DBSessionImpl extends Object implements DBSession
  • Constructor Summary

    Constructors
    Constructor
    Description
    DBSessionImpl(javax.persistence.EntityManagerFactory emf)
     
  • 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.
    javax.persistence.EntityManagerFactory
     
    int
     
    void
    setEntityManagerFactory(javax.persistence.EntityManagerFactory emf)
     
    void
    setMaxTransactionRetries(int maxTransactionRetries)
     

    Methods inherited from class java.lang.Object

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

    • DBSessionImpl

      public DBSessionImpl(javax.persistence.EntityManagerFactory emf)
  • Method Details

    • exec

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

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

      public <T> T exec(Function<javax.persistence.EntityManager,T> fn)
      Description copied from interface: DBSession
      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.
      Specified by:
      exec in interface DBSession
      Type Parameters:
      T - Return type of fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
    • execChecked

      public <T, E extends Throwable> T execChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Description copied from interface: DBSession
      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.
      Specified by:
      execChecked in interface DBSession
      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

      public void execTx(Consumer<javax.persistence.EntityManager> fn)
      Description copied from interface: DBSession
      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.
      Specified by:
      execTx in interface DBSession
      Parameters:
      fn - Function to execute.
    • execTxChecked

      public <E extends Throwable> void execTxChecked(ThrowingConsumer<javax.persistence.EntityManager,E> fn) throws E
      Description copied from interface: DBSession
      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.
      Specified by:
      execTxChecked in interface DBSession
      Type Parameters:
      E - Exception type that could be thrown by fn.
      Parameters:
      fn - Function to execute.
      Throws:
      E - Exception thrown by fn.
    • execTx

      public void execTx(int maxTransactionRetries, Consumer<javax.persistence.EntityManager> fn)
      Description copied from interface: DBSession
      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.
      Specified by:
      execTx in interface DBSession
      Parameters:
      maxTransactionRetries - Maximal number of times fn can be executed again in case of transaction errors.
      fn - Function to execute.
    • execTxChecked

      public <E extends Throwable> void execTxChecked(int maxTransactionRetries, ThrowingConsumer<javax.persistence.EntityManager,E> fn) throws E
      Description copied from interface: DBSession
      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.
      Specified by:
      execTxChecked in interface DBSession
      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

      public <T> T execTx(Function<javax.persistence.EntityManager,T> fn)
      Description copied from interface: DBSession
      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.
      Specified by:
      execTx in interface DBSession
      Type Parameters:
      T - Return type of fn.
      Parameters:
      fn - Function to execute.
      Returns:
      Object fn has returned.
    • execTxChecked

      public <T, E extends Throwable> T execTxChecked(ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Description copied from interface: DBSession
      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.
      Specified by:
      execTxChecked in interface DBSession
      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

      public <T> T execTx(int maxTransactionRetries, Function<javax.persistence.EntityManager,T> fn)
      Description copied from interface: DBSession
      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.
      Specified by:
      execTx in interface DBSession
      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

      public <T, E extends Throwable> T execTxChecked(int maxTransactionRetries, ThrowingFunction<javax.persistence.EntityManager,T,E> fn) throws E
      Description copied from interface: DBSession
      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.
      Specified by:
      execTxChecked in interface DBSession
      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

      public void close()
      Description copied from interface: DBSession
      Closes this DBSession and cleans up related objects.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface DBSession
    • getEntityManagerFactory

      public javax.persistence.EntityManagerFactory getEntityManagerFactory()
    • setEntityManagerFactory

      public void setEntityManagerFactory(javax.persistence.EntityManagerFactory emf)
    • getMaxTransactionRetries

      public int getMaxTransactionRetries()
    • setMaxTransactionRetries

      public void setMaxTransactionRetries(int maxTransactionRetries)