Package org.datanucleus.api.jakarta
Class JakartaEntityTransaction
- java.lang.Object
-
- org.datanucleus.api.jakarta.JakartaEntityTransaction
-
- All Implemented Interfaces:
jakarta.persistence.EntityTransaction
public class JakartaEntityTransaction extends Object implements jakarta.persistence.EntityTransaction
EntityTransaction implementation for Jakarta Persistence for ResourceLocal transaction. Utilises the underlying ExecutionContext and its real transaction, providing a Jakarta Persistence layer on top.
-
-
Constructor Summary
Constructors Constructor Description JakartaEntityTransaction(org.datanucleus.ExecutionContext ec)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertActive()Convenience method to throw an exception if the transaction is not active.protected voidassertNotActive()Convenience method to throw an exception if the transaction is active.voidbegin()Start a resource transaction.voidcommit()Commit the current transaction, writing any unflushed changes to the database.voidderegisterEventListener(org.datanucleus.transaction.TransactionEventListener listener)Method to deregister a listener for transaction events.booleangetRollbackOnly()Determine whether the current transaction has been marked for rollback.booleanisActive()Indicate whether a transaction is in progress.voidregisterEventListener(org.datanucleus.transaction.TransactionEventListener listener)Method to register a listener for transaction events.voidreleaseSavepoint(String name)Method to mark the current point as a savepoint with the provided name.voidrollback()Roll back the current transaction.voidrollbackToSavepoint(String name)Method to mark the current point as a savepoint with the provided name.voidsetOption(String option, boolean value)Convenience accessor for setting a transaction option.voidsetOption(String option, int value)Convenience accessor for setting a transaction option.voidsetOption(String option, String value)Convenience accessor for setting a transaction option.voidsetRollbackOnly()Mark the current transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.voidsetSavepoint(String name)Method to mark the current point as a savepoint with the provided name.
-
-
-
Method Detail
-
isActive
public boolean isActive()
Indicate whether a transaction is in progress.- Specified by:
isActivein interfacejakarta.persistence.EntityTransaction- Throws:
jakarta.persistence.PersistenceException- if an unexpected error condition is encountered.
-
begin
public void begin()
Start a resource transaction.- Specified by:
beginin interfacejakarta.persistence.EntityTransaction- Throws:
IllegalStateException- if the transaction is active
-
commit
public void commit()
Commit the current transaction, writing any unflushed changes to the database.- Specified by:
commitin interfacejakarta.persistence.EntityTransaction- Throws:
IllegalStateException- if isActive() is false.jakarta.persistence.RollbackException- if the commit fails.
-
rollback
public void rollback()
Roll back the current transaction.- Specified by:
rollbackin interfacejakarta.persistence.EntityTransaction- Throws:
IllegalStateException- if isActive() is false.jakarta.persistence.PersistenceException- if an unexpected error condition is encountered.
-
getRollbackOnly
public boolean getRollbackOnly()
Determine whether the current transaction has been marked for rollback.- Specified by:
getRollbackOnlyin interfacejakarta.persistence.EntityTransaction- Throws:
IllegalStateException- if isActive() is false.
-
setRollbackOnly
public void setRollbackOnly()
Mark the current transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.- Specified by:
setRollbackOnlyin interfacejakarta.persistence.EntityTransaction- Throws:
IllegalStateException- Thrown if the transaction is not active
-
setOption
public void setOption(String option, int value)
Convenience accessor for setting a transaction option.- Parameters:
option- option namevalue- The value
-
setOption
public void setOption(String option, boolean value)
Convenience accessor for setting a transaction option.- Parameters:
option- option namevalue- The value
-
setOption
public void setOption(String option, String value)
Convenience accessor for setting a transaction option.- Parameters:
option- option namevalue- The value
-
setSavepoint
public void setSavepoint(String name)
Method to mark the current point as a savepoint with the provided name.- Parameters:
name- Name of the savepoint.- Throws:
UnsupportedOperationException- if the underlying datastore doesn't support savepointsIllegalStateException- if no name is provided
-
releaseSavepoint
public void releaseSavepoint(String name)
Method to mark the current point as a savepoint with the provided name.- Parameters:
name- Name of the savepoint.- Throws:
UnsupportedOperationException- if the underlying datastore doesn't support savepointsIllegalStateException- if no name is provided, or the name doesn't correspond to a known savepoint
-
rollbackToSavepoint
public void rollbackToSavepoint(String name)
Method to mark the current point as a savepoint with the provided name.- Parameters:
name- Name of the savepoint.- Throws:
UnsupportedOperationException- if the underlying datastore doesn't support savepointsIllegalStateException- if no name is provided, or the name doesn't correspond to a known savepoint
-
assertActive
protected void assertActive()
Convenience method to throw an exception if the transaction is not active.- Throws:
IllegalStateException- Thrown if the transaction is not active.
-
assertNotActive
protected void assertNotActive()
Convenience method to throw an exception if the transaction is active.- Throws:
IllegalStateException- Thrown if the transaction is active.
-
registerEventListener
public void registerEventListener(org.datanucleus.transaction.TransactionEventListener listener)
Method to register a listener for transaction events.- Parameters:
listener- The listener
-
deregisterEventListener
public void deregisterEventListener(org.datanucleus.transaction.TransactionEventListener listener)
Method to deregister a listener for transaction events.- Parameters:
listener- The listener to remove
-
-