Class FHIRUserTransactionAdapter
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.jdbc.connection.FHIRUserTransactionAdapter
-
- All Implemented Interfaces:
FHIRPersistenceTransaction
public class FHIRUserTransactionAdapter extends java.lang.Object implements FHIRPersistenceTransaction
Adapter to simplify transaction handling. This object is returned by FHIRPersistenceJDBCImpl and can be used instead of the old FHIRTransactionHelper
-
-
Constructor Summary
Constructors Constructor Description FHIRUserTransactionAdapter(javax.transaction.UserTransaction tx, javax.transaction.TransactionSynchronizationRegistry syncRegistry, FHIRPersistenceJDBCCache cache, java.lang.String transactionDataKey, java.util.function.Consumer<java.lang.Boolean> afterTransactionHandler)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin()
If a transaction has not yet been started on this thread, then start one.void
end()
If we previously started a transaction on this thread using this helper instance, then commit it now.(package private) <T> T
func(java.util.function.Supplier<T> s)
Call the supplier function within a begin/endprotected int
getStatus()
Get theStatus
of the global transactionboolean
hasBegun()
Determine if the transaction status is currently activeprotected boolean
isActive(int status)
Is there a transaction currently on this thread?protected boolean
isMarkedForRollback(int status)
Has this transaction been marked for rollback?protected boolean
isNoTransaction(int status)
Are we in the NO TRANSACTION state?boolean
isTransactional()
Does the underlying implementation actually support transactions? A persistence layer must always return a FHIRPersistenceTransaction even if it doesn't support transactions.void
setRollbackOnly()
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.
-
-
-
Constructor Detail
-
FHIRUserTransactionAdapter
public FHIRUserTransactionAdapter(javax.transaction.UserTransaction tx, javax.transaction.TransactionSynchronizationRegistry syncRegistry, FHIRPersistenceJDBCCache cache, java.lang.String transactionDataKey, java.util.function.Consumer<java.lang.Boolean> afterTransactionHandler)
Public constructor- Parameters:
tx
-syncRegistry
-cache
-transactionDataKey
-afterTransactionHandler
-
-
-
Method Detail
-
begin
public void begin() throws FHIRPersistenceException
If a transaction has not yet been started on this thread, then start one.- Specified by:
begin
in interfaceFHIRPersistenceTransaction
- Throws:
FHIRPersistenceException
-
end
public void end() throws FHIRPersistenceException
If we previously started a transaction on this thread using this helper instance, then commit it now.- Specified by:
end
in interfaceFHIRPersistenceTransaction
- Throws:
FHIRPersistenceException
-
setRollbackOnly
public void setRollbackOnly() throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceTransaction
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.- Specified by:
setRollbackOnly
in interfaceFHIRPersistenceTransaction
- Throws:
FHIRPersistenceException
-
isTransactional
public boolean isTransactional()
Description copied from interface:FHIRPersistenceTransaction
Does the underlying implementation actually support transactions? A persistence layer must always return a FHIRPersistenceTransaction even if it doesn't support transactions. This reduces boilerplate code by avoiding the need to check for null every time.- Specified by:
isTransactional
in interfaceFHIRPersistenceTransaction
- Returns:
-
isActive
protected boolean isActive(int status)
Is there a transaction currently on this thread?- Returns:
- true if a global transaction is active on the current thread
-
isMarkedForRollback
protected boolean isMarkedForRollback(int status)
Has this transaction been marked for rollback?- Returns:
-
isNoTransaction
protected boolean isNoTransaction(int status)
Are we in the NO TRANSACTION state?- Parameters:
status
-- Returns:
-
getStatus
protected int getStatus() throws FHIRPersistenceDataAccessException
Get theStatus
of the global transaction- Returns:
- Throws:
FHIRPersistenceDataAccessException
-
func
<T> T func(java.util.function.Supplier<T> s) throws FHIRPersistenceException
Call the supplier function within a begin/end- Type Parameters:
T
-- Parameters:
s
-- Returns:
- Throws:
FHIRPersistenceException
-
hasBegun
public boolean hasBegun() throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceTransaction
Determine if the transaction status is currently active- Specified by:
hasBegun
in interfaceFHIRPersistenceTransaction
- Returns:
- true if transaction begin has been called
- Throws:
FHIRPersistenceException
-
-