Package org.opencastproject.db
Class DBSessionImpl
java.lang.Object
org.opencastproject.db.DBSessionImpl
- All Implemented Interfaces:
AutoCloseable,DBSession
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this DBSession and cleans up related objects.voidExecute given function without opening a new transaction.<T> TExecute given function without opening a new transaction.<E extends Throwable>
voidexecChecked(ThrowingConsumer<javax.persistence.EntityManager, E> fn) Execute given function that can throw a checked exception without opening a new transaction.<T,E extends Throwable>
TexecChecked(ThrowingFunction<javax.persistence.EntityManager, T, E> fn) Execute given function that can throw a checked exception without opening a new transaction.voidExecute given function within a transaction.<T> TExecute given function within a transaction.voidExecute given function within a transaction.<T> TExecute given function within a transaction.<E extends Throwable>
voidexecTxChecked(int maxTransactionRetries, ThrowingConsumer<javax.persistence.EntityManager, E> fn) Execute given function that can throw a checked exception within a transaction.<T,E extends Throwable>
TexecTxChecked(int maxTransactionRetries, ThrowingFunction<javax.persistence.EntityManager, T, E> fn) Execute given function that can throw a checked exception within a transaction.<E extends Throwable>
voidexecTxChecked(ThrowingConsumer<javax.persistence.EntityManager, E> fn) Execute given function that can throw a checked exception within a transaction.<T,E extends Throwable>
TexecTxChecked(ThrowingFunction<javax.persistence.EntityManager, T, E> fn) Execute given function that can throw a checked exception within a transaction.javax.persistence.EntityManagerFactoryintvoidsetEntityManagerFactory(javax.persistence.EntityManagerFactory emf) voidsetMaxTransactionRetries(int maxTransactionRetries)
-
Constructor Details
-
DBSessionImpl
public DBSessionImpl(javax.persistence.EntityManagerFactory emf)
-
-
Method Details
-
exec
Description copied from interface:DBSessionExecute given function without opening a new transaction. It should be assumed that the EntityManager was newly created. -
execChecked
public <E extends Throwable> void execChecked(ThrowingConsumer<javax.persistence.EntityManager, E> fn) throws EDescription copied from interface:DBSessionExecute 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:
execCheckedin interfaceDBSession- Type Parameters:
E- Exception type that could be thrown by fn.- Parameters:
fn- Function to execute.- Throws:
E- Exception thrown by fn.
-
exec
Description copied from interface:DBSessionExecute 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. -
execChecked
public <T,E extends Throwable> T execChecked(ThrowingFunction<javax.persistence.EntityManager, T, throws EE> fn) Description copied from interface:DBSessionExecute 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:
execCheckedin interfaceDBSession- 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
Description copied from interface:DBSessionExecute 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. -
execTxChecked
public <E extends Throwable> void execTxChecked(ThrowingConsumer<javax.persistence.EntityManager, E> fn) throws EDescription copied from interface:DBSessionExecute 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:
execTxCheckedin interfaceDBSession- Type Parameters:
E- Exception type that could be thrown by fn.- Parameters:
fn- Function to execute.- Throws:
E- Exception thrown by fn.
-
execTx
Description copied from interface:DBSessionExecute 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. -
execTxChecked
public <E extends Throwable> void execTxChecked(int maxTransactionRetries, ThrowingConsumer<javax.persistence.EntityManager, E> fn) throws EDescription copied from interface:DBSessionExecute 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:
execTxCheckedin interfaceDBSession- 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
Description copied from interface:DBSessionExecute 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. -
execTxChecked
public <T,E extends Throwable> T execTxChecked(ThrowingFunction<javax.persistence.EntityManager, T, throws EE> fn) Description copied from interface:DBSessionExecute 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:
execTxCheckedin interfaceDBSession- 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
Description copied from interface:DBSessionExecute 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. -
execTxChecked
public <T,E extends Throwable> T execTxChecked(int maxTransactionRetries, ThrowingFunction<javax.persistence.EntityManager, T, throws EE> fn) Description copied from interface:DBSessionExecute 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:
execTxCheckedin interfaceDBSession- 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:DBSessionCloses this DBSession and cleans up related objects.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDBSession
-
getEntityManagerFactory
public javax.persistence.EntityManagerFactory getEntityManagerFactory() -
setEntityManagerFactory
public void setEntityManagerFactory(javax.persistence.EntityManagerFactory emf) -
getMaxTransactionRetries
public int getMaxTransactionRetries() -
setMaxTransactionRetries
public void setMaxTransactionRetries(int maxTransactionRetries)
-