private static class ExtendedEntityManagerCreator.ExtendedEntityManagerSynchronization extends ResourceHolderSynchronization<EntityManagerHolder,EntityManager> implements Ordered
Modifier and Type | Field and Description |
---|---|
boolean |
closeOnCompletion |
private EntityManager |
entityManager |
private PersistenceExceptionTranslator |
exceptionTranslator |
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
STATUS_COMMITTED, STATUS_ROLLED_BACK, STATUS_UNKNOWN
Constructor and Description |
---|
ExtendedEntityManagerSynchronization(EntityManager em,
PersistenceExceptionTranslator exceptionTranslator) |
Modifier and Type | Method and Description |
---|---|
void |
afterCommit()
Invoked after transaction commit.
|
void |
afterCompletion(int status)
Invoked after transaction commit/rollback.
|
private java.lang.RuntimeException |
convertException(java.lang.RuntimeException ex) |
protected void |
flushResource(EntityManagerHolder resourceHolder)
Flush callback for the given resource holder.
|
int |
getOrder()
Get the order value of this object.
|
protected boolean |
shouldReleaseBeforeCompletion()
Return whether this holder's resource should be released before
transaction completion (
true ) or rather after
transaction completion (false ). |
beforeCommit, beforeCompletion, cleanupResource, flush, processResourceAfterCommit, releaseResource, resume, shouldReleaseAfterCompletion, shouldUnbindAtCompletion, suspend
private final EntityManager entityManager
@Nullable private final PersistenceExceptionTranslator exceptionTranslator
public volatile boolean closeOnCompletion
public ExtendedEntityManagerSynchronization(EntityManager em, @Nullable PersistenceExceptionTranslator exceptionTranslator)
public int getOrder()
Ordered
Higher values are interpreted as lower priority. As a consequence,
the object with the lowest value has the highest priority (somewhat
analogous to Servlet load-on-startup
values).
Same order values will result in arbitrary sort positions for the affected objects.
getOrder
in interface Ordered
Ordered.HIGHEST_PRECEDENCE
,
Ordered.LOWEST_PRECEDENCE
protected void flushResource(EntityManagerHolder resourceHolder)
ResourceHolderSynchronization
flushResource
in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
resourceHolder
- the resource holder to flushprotected boolean shouldReleaseBeforeCompletion()
ResourceHolderSynchronization
true
) or rather after
transaction completion (false
).
Note that resources will only be released when they are
unbound from the thread (ResourceHolderSynchronization.shouldUnbindAtCompletion()
).
The default implementation returns true
.
shouldReleaseBeforeCompletion
in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
ResourceHolderSynchronization.releaseResource(H, K)
public void afterCommit()
TransactionSynchronization
Can e.g. commit further operations that are supposed to follow on a successful commit of the main transaction, like confirmation messages or emails.
NOTE: The transaction will have been committed already, but the
transactional resources might still be active and accessible. As a consequence,
any data access code triggered at this point will still "participate" in the
original transaction, allowing to perform some cleanup (with no commit following
anymore!), unless it explicitly declares that it needs to run in a separate
transaction. Hence: Use PROPAGATION_REQUIRES_NEW
for any
transactional operation that is called from here.
afterCommit
in interface TransactionSynchronization
afterCommit
in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
public void afterCompletion(int status)
TransactionSynchronization
NOTE: The transaction will have been committed or rolled back already,
but the transactional resources might still be active and accessible. As a
consequence, any data access code triggered at this point will still "participate"
in the original transaction, allowing to perform some cleanup (with no commit
following anymore!), unless it explicitly declares that it needs to run in a
separate transaction. Hence: Use PROPAGATION_REQUIRES_NEW
for any transactional operation that is called from here.
afterCompletion
in interface TransactionSynchronization
afterCompletion
in class ResourceHolderSynchronization<EntityManagerHolder,EntityManager>
status
- completion status according to the STATUS_*
constantsTransactionSynchronization.STATUS_COMMITTED
,
TransactionSynchronization.STATUS_ROLLED_BACK
,
TransactionSynchronization.STATUS_UNKNOWN
,
TransactionSynchronization.beforeCompletion()
private java.lang.RuntimeException convertException(java.lang.RuntimeException ex)