Package org.jboss.as.jpa.container
Class ExtendedEntityManager
- java.lang.Object
-
- org.jboss.as.jpa.container.AbstractEntityManager
-
- org.jboss.as.jpa.container.ExtendedEntityManager
-
- All Implemented Interfaces:
jakarta.persistence.EntityManager,Serializable,AutoCloseable,SynchronizationTypeAccess
public class ExtendedEntityManager extends AbstractEntityManager implements Serializable, SynchronizationTypeAccess
Represents the Extended persistence context injected into a stateful bean. At bean invocation time, will join the active Jakarta Transactions transaction if one is present. If no active Jakarta Transactions transaction is present, created/deleted/updated/loaded entities will remain associated with the entity manager until it is joined with a transaction (commit will save the changes, rollback will lose them). At injection time, an instance of this class is associated with the SFSB. During a SFSB1 invocation, if a new SFSB2 is created with an XPC referencing the same persistence unit, the new SFSB2 will inherit the same persistence context from SFSB1. Both SFSB1 + SFSB2 will maintain a reference to the underlying persistence context, such that the underlying persistence context will be kept around until both SFSB1 + SFSB2 are destroyed. At cluster replication time or passivation, both SFSB1 + SFSB2 will be serialized consecutively and this instance will only be serialized once. Note: Unlike TransactionScopedEntityManager, ExtendedEntityManager will directly be shared instead of the underlying EntityManager. During serialization, A NotSerializableException will be thrown if the following conditions are not met: - The underlying persistence provider (entity manager) must be Serializable. - The entity classes in the extended persistence context must also be Serializable.- Author:
- Scott Marlow
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.jboss.as.jpa.container.AbstractEntityManager
NONE_LOCK_MODE, NULL_LOCK_MODE, OPTIMISTIC_FORCE_INCREMENT_LOCK_MODE, OPTIMISTIC_LOCK_MODE, PESSIMISTIC_FORCE_INCREMENT_LOCK_MODE, PESSIMISTIC_READ_LOCK_MODE, PESSIMISTIC_WRITE_LOCK_MODE, READ_LOCK_MODE, WRITE_LOCK_MODE
-
-
Constructor Summary
Constructors Constructor Description ExtendedEntityManager(String puScopedName, jakarta.persistence.EntityManager underlyingEntityManager, jakarta.persistence.SynchronizationType synchronizationType, jakarta.transaction.TransactionSynchronizationRegistry transactionSynchronizationRegistry, jakarta.transaction.TransactionManager transactionManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Catch the application trying to close the container managed entity manager and throw an IllegalStateExceptionprotected booleandeferEntityDetachUntilClose()booleanequals(Object otherObject)Check if this object's UUID is equal to the otherObject's UUIDprotected jakarta.persistence.EntityManagergetEntityManager()The Jakarta Persistence SFSB interceptor will track the stack of SFSB invocations.intgetReferenceCount()StringgetScopedPuName()Get the fully application scoped persistence unit name Private apijakarta.persistence.SynchronizationTypegetSynchronizationType()inthashCode()voidincreaseReferenceCount()Start of reference count handling.voidinternalAssociateWithJtaTx()Associate the extended persistence context with the current Jakarta Transactions transaction (if one is found) this method is private to the Jakarta Persistence subsystemprotected booleanisExtendedPersistenceContext()protected booleanisInTx()voidrefCountedClose()protected booleanskipQueryDetach()StringtoString()End of reference count handling-
Methods inherited from class org.jboss.as.jpa.container.AbstractEntityManager
clear, contains, createEntityGraph, createEntityGraph, createNamedQuery, createNamedQuery, createNamedStoredProcedureQuery, createNativeQuery, createNativeQuery, createNativeQuery, createQuery, createQuery, createQuery, createQuery, createQuery, createStoredProcedureQuery, createStoredProcedureQuery, createStoredProcedureQuery, detach, detachNonTxInvocation, detachQueryNonTxInvocation, detachTypedQueryNonTxInvocation, find, find, find, find, flush, getCriteriaBuilder, getDelegate, getEntityGraph, getEntityGraphs, getEntityManagerFactory, getFlushMode, getLockMode, getMetamodel, getProperties, getReference, getTransaction, isJoinedToTransaction, isOpen, joinTransaction, lock, lock, merge, persist, refresh, refresh, refresh, refresh, remove, setFlushMode, setProperty, unwrap
-
-
-
-
Constructor Detail
-
ExtendedEntityManager
public ExtendedEntityManager(String puScopedName, jakarta.persistence.EntityManager underlyingEntityManager, jakarta.persistence.SynchronizationType synchronizationType, jakarta.transaction.TransactionSynchronizationRegistry transactionSynchronizationRegistry, jakarta.transaction.TransactionManager transactionManager)
-
-
Method Detail
-
getEntityManager
protected jakarta.persistence.EntityManager getEntityManager()
The Jakarta Persistence SFSB interceptor will track the stack of SFSB invocations. The underlying EM will be obtained from the current SFSB being invoked (via our Jakarta Persistence SFSB interceptor). Every entity manager call (to AbstractEntityManager) will call this method to get the underlying entity manager (e.g. the Hibernate persistence provider). See org.jboss.ejb3.stateful.EJB3XPCResolver.getExtendedPersistenceContext() to see the as6 implementation of this.- Specified by:
getEntityManagerin classAbstractEntityManager- Returns:
- EntityManager
-
internalAssociateWithJtaTx
public void internalAssociateWithJtaTx()
Associate the extended persistence context with the current Jakarta Transactions transaction (if one is found) this method is private to the Jakarta Persistence subsystem
-
isExtendedPersistenceContext
protected boolean isExtendedPersistenceContext()
- Specified by:
isExtendedPersistenceContextin classAbstractEntityManager- Returns:
- true if an extended persistence context is in use Precondition: getEntityManager() must be called previous to calling isExtendedPersistenceContext
-
isInTx
protected boolean isInTx()
- Specified by:
isInTxin classAbstractEntityManager- Returns:
- true if a Jakarta Transactions transaction active Precondition: getEntityManager() must be called previous to calling isInTx
-
close
public void close()
Catch the application trying to close the container managed entity manager and throw an IllegalStateException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.persistence.EntityManager- Overrides:
closein classAbstractEntityManager
-
increaseReferenceCount
public void increaseReferenceCount()
Start of reference count handling. synchronize on *this* to protect access to the referenceCount (should be mostly uncontended locks).
-
getReferenceCount
public int getReferenceCount()
-
refCountedClose
public void refCountedClose()
-
toString
public String toString()
End of reference count handling
-
getScopedPuName
public String getScopedPuName()
Get the fully application scoped persistence unit name Private api- Returns:
- scoped pu name
-
equals
public boolean equals(Object otherObject)
Check if this object's UUID is equal to the otherObject's UUID
-
getSynchronizationType
public jakarta.persistence.SynchronizationType getSynchronizationType()
- Specified by:
getSynchronizationTypein interfaceSynchronizationTypeAccess- Specified by:
getSynchronizationTypein classAbstractEntityManager
-
deferEntityDetachUntilClose
protected boolean deferEntityDetachUntilClose()
- Specified by:
deferEntityDetachUntilClosein classAbstractEntityManager
-
skipQueryDetach
protected boolean skipQueryDetach()
- Specified by:
skipQueryDetachin classAbstractEntityManager
-
-