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 void
assertActive()
Convenience method to throw an exception if the transaction is not active.protected void
assertNotActive()
Convenience method to throw an exception if the transaction is active.void
begin()
Start a resource transaction.void
commit()
Commit the current transaction, writing any unflushed changes to the database.void
deregisterEventListener(org.datanucleus.transaction.TransactionEventListener listener)
Method to deregister a listener for transaction events.boolean
getRollbackOnly()
Determine whether the current transaction has been marked for rollback.boolean
isActive()
Indicate whether a transaction is in progress.void
registerEventListener(org.datanucleus.transaction.TransactionEventListener listener)
Method to register a listener for transaction events.void
releaseSavepoint(String name)
Method to mark the current point as a savepoint with the provided name.void
rollback()
Roll back the current transaction.void
rollbackToSavepoint(String name)
Method to mark the current point as a savepoint with the provided name.void
setOption(String option, boolean value)
Convenience accessor for setting a transaction option.void
setOption(String option, int value)
Convenience accessor for setting a transaction option.void
setOption(String option, String value)
Convenience accessor for setting a transaction option.void
setRollbackOnly()
Mark the current transaction so that the only possible outcome of the transaction is for the transaction to be rolled back.void
setSavepoint(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:
isActive
in interfacejakarta.persistence.EntityTransaction
- Throws:
jakarta.persistence.PersistenceException
- if an unexpected error condition is encountered.
-
begin
public void begin()
Start a resource transaction.- Specified by:
begin
in 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:
commit
in 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:
rollback
in 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:
getRollbackOnly
in 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:
setRollbackOnly
in 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
-
-