Class FHIRTestTransactionAdapter
- java.lang.Object
-
- org.linuxforhealth.fhir.persistence.jdbc.connection.FHIRTestTransactionAdapter
-
- All Implemented Interfaces:
FHIRPersistenceTransaction
public class FHIRTestTransactionAdapter extends java.lang.Object implements FHIRPersistenceTransaction
Hides the logic behind obtaining a JDBCConnection
from the DAO code. Use by unit tests or other scenarios where connections are obtained using an IConnectionProvider implementation, outside the scope of a JEE container. Transactions are managed with the help of the SimpleTransactionProvider and wrapped by this class, meaning we have a uniform interface for handling transactions across JEE and unit-test scenarios.
-
-
Constructor Summary
Constructors Constructor Description FHIRTestTransactionAdapter(IConnectionProvider cp, IFHIRTransactionAdapterCallback beforeCommitCallback)
Public constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin()
Begin a new transaction on the current thread if a transaction is not started yet.void
end()
End the current thread's transaction.boolean
hasBegun()
Determine if the transaction status is currently activevoid
setRollbackOnly()
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.linuxforhealth.fhir.persistence.FHIRPersistenceTransaction
isTransactional
-
-
-
-
Constructor Detail
-
FHIRTestTransactionAdapter
public FHIRTestTransactionAdapter(IConnectionProvider cp, IFHIRTransactionAdapterCallback beforeCommitCallback)
Public constructor- Parameters:
cp
-beforeCommit
- callback before transaction commit, can be null
-
-
Method Detail
-
begin
public void begin() throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceTransaction
Begin a new transaction on the current thread if a transaction is not started yet.- Specified by:
begin
in interfaceFHIRPersistenceTransaction
- Throws:
FHIRPersistenceException
-
end
public void end() throws FHIRPersistenceException
Description copied from interface:FHIRPersistenceTransaction
End the current thread's transaction. If setRollbackOnly has been called, then roll back the transaction instead. This call only affects the current transaction if this object actually started the transaction (i.e. is the outermost instance of a transaction).- 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
-
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
-
-