public abstract class EntityManagerImpl extends Object
Purpose: Contains the implementation of the EntityManager.
Description: This class provides the implementation for the combined TopLink and EJB3.0 EntityManager class.
Responsibilities:It is responcible for tracking transaction state and the objects within that transaction.
EntityManager
,
EntityManager
Modifier and Type | Field and Description |
---|---|
protected boolean |
extended |
protected RepeatableWriteUnitOfWork |
extendedPersistenceContext |
protected EntityManagerFactoryImpl |
factory |
protected boolean |
isOpen |
protected boolean |
propagatePersistenceContext |
protected ServerSession |
serverSession |
protected TransactionWrapperImpl |
transaction |
Constructor and Description |
---|
EntityManagerImpl(EntityManagerFactoryImpl factory,
Map properties,
boolean propagatePersistenceContext,
boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager
|
EntityManagerImpl(ServerSession serverSession,
boolean propagatePersistenceContext,
boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager
|
EntityManagerImpl(ServerSession serverSession,
Map properties,
boolean propagatePersistenceContext,
boolean extended)
Constructor called from the EntityManagerFactory to create an EntityManager
|
EntityManagerImpl(String sessionName,
boolean propagatePersistenceContext,
boolean extended)
Constructor returns an EntityManager assigned to the a particular ServerSession.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
checkForTransaction(boolean validateExistence) |
void |
clear()
Clear the persistence context, causing all managed
entities to become detached.
|
void |
close()
Closes this EntityManager.
|
boolean |
contains(Object entity)
Check if the instance belongs to the current persistence
context.
|
protected boolean |
contains(Object entity,
UnitOfWork uow)
Check if the instance belongs to the current persistence
context.
|
protected DatabaseQuery |
createNativeQueryInternal(String sqlString,
Class resultType)
This method is used to create a query using SQL.
|
protected DatabaseQuery |
createQueryInternal(Expression expression,
Class resultType)
This method is used to create a query using a Toplink Expression and the return type.
|
protected void |
detectTransactionWrapper() |
Object |
find(String entityName,
Object primaryKey)
Find by primary key.
|
protected static Object |
findInternal(ClassDescriptor descriptor,
Session session,
Object primaryKey)
Find by primary key.
|
protected Object |
findInternal(Class entityClass,
Object primaryKey)
Find by primary key.
|
void |
flush()
Synchronize the persistence context with the
underlying database.
|
RepeatableWriteUnitOfWork |
getActivePersistenceContext(Object txn) |
Session |
getActiveSession()
This method returns the current session to the requestor.
|
Object |
getDelegate()
Return the underlying provider object for the EntityManager,
if available.
|
ServerSession |
getServerSession()
Return the underlying server session
|
Session |
getSession()
This method will return a Session outside of a transaction and null within a transaction.
|
protected RepeatableWriteUnitOfWork |
getTransactionalUnitOfWork_new(Object tnx) |
UnitOfWork |
getUnitOfWork()
This method will return the active UnitOfWork
|
boolean |
isExtended()
Indicates if this EntityManager is an extended Persistence Context
|
abstract boolean |
isFlushModeAUTO()
Internal method.
|
boolean |
isOpen()
Indicates whether or not this entity manager is open.
|
void |
joinTransaction()
Indicate to the EntityManager that a JTA transaction is
active.
|
void |
lock(Object entity,
LockModeType lockMode)
Set the lock mode for an entity object contained in the persistence context.
|
protected Object |
mergeInternal(Object entity)
Merge the state of the given entity into the
current persistence context, using the unqualified
class name as the entity name.
|
void |
persist(Object entity)
If in a transaction this method will check for existence and register the object if
it is new.
|
void |
refresh(Object entity)
Refresh the state of the instance from the
database.
|
void |
remove(Object entity)
Remove the instance.
|
void |
removeExtendedPersistenceContext()
Internal method called by EntityTransactionImpl class in case of transaction rollback.
|
protected abstract void |
setEntityTransactionWrapper() |
protected abstract void |
setJTATransactionWrapper() |
protected void |
setRollbackOnly()
Internal method.
|
boolean |
shouldFlushBeforeQuery() |
boolean |
shouldPropagatePersistenceContext() |
void |
verifyOpen() |
protected TransactionWrapperImpl transaction
protected boolean isOpen
protected RepeatableWriteUnitOfWork extendedPersistenceContext
protected ServerSession serverSession
protected EntityManagerFactoryImpl factory
protected boolean extended
protected boolean propagatePersistenceContext
public EntityManagerImpl(String sessionName, boolean propagatePersistenceContext, boolean extended)
sessionName
- the ServerSession name that should be used.
This constructor can potentially throw TopLink exceptions regarding the existence, or
errors with the specified session.public EntityManagerImpl(ServerSession serverSession, boolean propagatePersistenceContext, boolean extended)
serverSession
- the serverSession assigned to this deployment.public EntityManagerImpl(ServerSession serverSession, Map properties, boolean propagatePersistenceContext, boolean extended)
serverSession
- the serverSession assigned to this deployment.
Note: The properties argument is provided to allow properties to be passed into this EntityManager,
but there are currently no such properties implementedpublic EntityManagerImpl(EntityManagerFactoryImpl factory, Map properties, boolean propagatePersistenceContext, boolean extended)
factory
- the EntityMangerFactoryImpl that created this entity manager.
Note: The properties argument is provided to allow properties to be passed into this EntityManager,
but there are currently no such properties implementedprotected abstract void setJTATransactionWrapper()
protected abstract void setEntityTransactionWrapper()
public abstract boolean isFlushModeAUTO()
public void clear()
public void removeExtendedPersistenceContext()
public void persist(Object entity)
entity
- IllegalArgumentException
- if the given Object is not an entityprotected Object mergeInternal(Object entity)
entity
- IllegalArgumentException
- if given Object is not an entity or is a removed entitypublic void remove(Object entity)
entity
- IllegalArgumentException
- if Object passed in is not an entitypublic Object find(String entityName, Object primaryKey)
entityName
- primaryKey
- IllegalArgumentException
- if the first argument does not indicate an entity or if the
second argument is not a valid type for that entity's primaryKeyprotected Object findInternal(Class entityClass, Object primaryKey)
entityClass
- primaryKey
- IllegalArgumentException
- if the first argument does
not denote an entity type or the second argument is not a valid type for that
entity's primary keyprotected static Object findInternal(ClassDescriptor descriptor, Session session, Object primaryKey)
descriptor
- session
- primaryKey
- IllegalArgumentException
- if the first argument does
not denote an entity type or the second argument is not a valid type for that
entity's primary keypublic void flush()
protected void detectTransactionWrapper()
public void refresh(Object entity)
entity
- public boolean contains(Object entity)
entity
- IllegalArgumentException
- if given Object is not an entityprotected boolean contains(Object entity, UnitOfWork uow)
entity
- uow
- public Session getActiveSession()
public Object getDelegate()
public UnitOfWork getUnitOfWork()
public Session getSession()
public ServerSession getServerSession()
protected DatabaseQuery createNativeQueryInternal(String sqlString, Class resultType)
protected DatabaseQuery createQueryInternal(Expression expression, Class resultType)
public void close()
Closes this EntityManager.
After invoking this method, all methods on the instance will throw an
IllegalStateException
except for isOpen
, which will return
false
.
This should be called when a method is finished with the EntityManager in a bean-managed transaction environment or when executed outside a container. Closing of the EntityManager is handled by the container when using container-managed transactions.
public boolean isExtended()
public boolean isOpen()
true
until
a call to close()
is made.public void lock(Object entity, LockModeType lockMode)
entity
- lockMode
- PersistenceException
- if an unsupported lock call is madeIllegalArgumentException
- if the instance is not an entity or is a detached entityTransactionRequiredException
- if there is no transactionpublic void verifyOpen()
public RepeatableWriteUnitOfWork getActivePersistenceContext(Object txn)
protected RepeatableWriteUnitOfWork getTransactionalUnitOfWork_new(Object tnx)
protected Object checkForTransaction(boolean validateExistence)
public boolean shouldFlushBeforeQuery()
public boolean shouldPropagatePersistenceContext()
public void joinTransaction()
TransactionRequiredException
- if there is
no transaction.protected void setRollbackOnly()
Copyright © 2021. All rights reserved.