Package org.opencastproject.db
Interface DBSession
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
DBSessionImpl
DBSession implements common DB query execution handlers.
-
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.
-
Method Details
-
exec
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 EExecute 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
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, throws EE> fn) 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
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 EExecute 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
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 EExecute 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
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, throws EE> fn) 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
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, throws EE> fn) 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:
closein interfaceAutoCloseable
-