Methods Summary |
---|
protected java.lang.Object | checkForTransaction(boolean validateExistence)
return transaction.checkForTransaction(validateExistence);
|
public void | clear()Clear the persistence context, causing all managed
entities to become detached. Changes made to entities that
have not been flushed to the database will not be
persisted.
try {
verifyOpen();
if (this.isExtended()){
if(this.extendedPersistenceContext != null){
if (checkForTransaction(false) == null){
// clear all change sets and cache
this.extendedPersistenceContext.clearForClose(true);
this.extendedPersistenceContext = null;
} else {
// clear all change sets created after the last flush and cache
this.extendedPersistenceContext.clear(true);
}
}
} else {
transaction.clear();
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public void | close()Closes this EntityManager.
After invoking this method, all methods on the instance will throw an
{@link IllegalStateException} except for {@link #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.
try {
verifyOpen();
isOpen = false;
factory = null;
serverSession = null;
if(extendedPersistenceContext != null) {
if (checkForTransaction(false) == null){
// clear change sets but keep the cache
extendedPersistenceContext.clearForClose(false);
} else {
// when commit will be called, all change sets will be cleared, but the cache will be kept
extendedPersistenceContext.setShouldClearForCloseInsteadOfResume(true);
}
extendedPersistenceContext = null;
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public boolean | contains(java.lang.Object entity)Check if the instance belongs to the current persistence
context.
try {
verifyOpen();
if (entity == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_an_entity", new Object[] {entity}));
}
ClassDescriptor descriptor = (ClassDescriptor)getServerSession().getDescriptors().get(entity.getClass());
if (descriptor == null || descriptor.isAggregateDescriptor() || descriptor.isAggregateCollectionDescriptor()){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_an_entity", new Object[]{entity}));
}
if( (!hasActivePersistenceContext())) {
return false;
}
return contains(entity,getActivePersistenceContext(checkForTransaction(false)));
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
protected boolean | contains(java.lang.Object entity, oracle.toplink.essentials.sessions.UnitOfWork uow)Check if the instance belongs to the current persistence
context.
return ((oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl)uow).isObjectRegistered(entity) &&
!((oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl)uow).isObjectDeleted(entity);
|
protected oracle.toplink.essentials.queryframework.DatabaseQuery | createNativeQueryInternal(java.lang.String sqlString, java.lang.Class resultType)This method is used to create a query using SQL. The class, must be the expected
return type.
ReadAllQuery query = new ReadAllQuery(resultType);
query.setSQLString(sqlString);
query.setIsUserDefined(true);
return query;
|
protected oracle.toplink.essentials.queryframework.DatabaseQuery | createQueryInternal(oracle.toplink.essentials.expressions.Expression expression, java.lang.Class resultType)This method is used to create a query using a Toplink Expression and the return type.
ReadAllQuery query = new ReadAllQuery(resultType);
query.setSelectionCriteria(expression);
return query;
|
protected void | detectTransactionWrapper()
if (this.serverSession.hasExternalTransactionController()){
setJTATransactionWrapper();
} else {
setEntityTransactionWrapper();
}
|
public java.lang.Object | find(java.lang.String entityName, java.lang.Object primaryKey)Find by primary key.
try {
verifyOpen();
Session session = getActiveSession();
ClassDescriptor descriptor = session.getDescriptorForAlias(entityName);
if (descriptor == null || descriptor.isAggregateDescriptor() || descriptor.isAggregateCollectionDescriptor()){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_entitybean_name", new Object[] {entityName}));
}
if (primaryKey == null){ //gf721 - check for null PK
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("null_pk"));
}
if ( ((CMP3Policy)descriptor.getCMPPolicy()).getPKClass() != null && !((CMP3Policy)descriptor.getCMPPolicy()).getPKClass().isAssignableFrom(primaryKey.getClass())){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] {((CMP3Policy)descriptor.getCMPPolicy()).getPKClass(), primaryKey.getClass()}));
}
return findInternal(descriptor, session, primaryKey);
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
protected java.lang.Object | findInternal(java.lang.Class entityClass, java.lang.Object primaryKey)Find by primary key.
Session session = getActiveSession();
ClassDescriptor descriptor = session.getDescriptor(entityClass);
if (descriptor == null || descriptor.isAggregateDescriptor() || descriptor.isAggregateCollectionDescriptor()){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("unknown_bean_class", new Object[]{ entityClass}));
}
if (primaryKey == null){ //gf721 - check for null PK
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("null_pk"));
}
if ( ((CMP3Policy)descriptor.getCMPPolicy()).getPKClass() != null && !((CMP3Policy)descriptor.getCMPPolicy()).getPKClass().isAssignableFrom(primaryKey.getClass())){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("invalid_pk_class", new Object[] {((CMP3Policy)descriptor.getCMPPolicy()).getPKClass(), primaryKey.getClass()}));
}
return findInternal(descriptor, session, primaryKey);
|
protected static java.lang.Object | findInternal(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor, oracle.toplink.essentials.sessions.Session session, java.lang.Object primaryKey)Find by primary key.
Vector pk;
if(primaryKey instanceof Vector) {
pk = (Vector)primaryKey;
} else {
pk = ((CMP3Policy) descriptor.getCMPPolicy()).createPkVectorFromKey(primaryKey, (oracle.toplink.essentials.internal.sessions.AbstractSession)session);
}
ReadObjectQuery query = new ReadObjectQuery(descriptor.getJavaClass());
query.setSelectionKey(pk);
query.conformResultsInUnitOfWork();
return session.executeQuery(query);
|
public void | flush()Synchronize the persistence context with the
underlying database.
try {
verifyOpen();
try {
getActivePersistenceContext(checkForTransaction(true)).writeChanges();
}catch (RuntimeException e) {
if (TopLinkException.class.isAssignableFrom(e.getClass())){
throw new PersistenceException(e);
}
throw e;
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork | getActivePersistenceContext(java.lang.Object txn)
if (this.isExtended()){
// use local uow as it will be local to this EM and not on the txn
if (this.extendedPersistenceContext == null || !this.extendedPersistenceContext.isActive()){
this.extendedPersistenceContext = new RepeatableWriteUnitOfWork(this.serverSession.acquireClientSession());
this.extendedPersistenceContext.setResumeUnitOfWorkOnTransactionCompletion(true);
this.extendedPersistenceContext.setShouldCascadeCloneToJoinedRelationship(true);
if (txn != null) {
// if there is an active txn we must register with it on creation of PC
transaction.registerUnitOfWorkWithTxn(this.extendedPersistenceContext);
}
}
return this.extendedPersistenceContext;
}else{
return getTransactionalUnitOfWork_new(txn);
}
|
public oracle.toplink.essentials.sessions.Session | getActiveSession()This method returns the current session to the requestor. The current session
will be a the active UnitOfWork within a transaction and will be a 'scrap'
UnitOfWork outside of a transaction. The caller is conserned about the results
then the getSession() or getUnitOfWork() API should be called.
Object txn = checkForTransaction(false);
if ( txn == null && ! this.isExtended() ){
return this.serverSession.acquireNonSynchronizedUnitOfWork();
}else{
return getActivePersistenceContext(txn);
}
|
public java.lang.Object | getDelegate()Return the underlying provider object for the EntityManager,
if available. The result of this method is implementation
specific.
try {
verifyOpen();
return this;
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public oracle.toplink.essentials.threetier.ServerSession | getServerSession()Return the underlying server session
return this.serverSession;
|
public oracle.toplink.essentials.sessions.Session | getSession()This method will return a Session outside of a transaction and null within a transaction.
if (checkForTransaction(false) == null){
return this.serverSession.acquireNonSynchronizedUnitOfWork();
}
return null;
|
protected oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork | getTransactionalUnitOfWork_new(java.lang.Object tnx)
return transaction.getTransactionalUnitOfWork(tnx);
|
public oracle.toplink.essentials.sessions.UnitOfWork | getUnitOfWork()This method will return the active UnitOfWork
return getActivePersistenceContext(checkForTransaction(false));
|
private boolean | hasActivePersistenceContext()
if (isExtended() && (this.extendedPersistenceContext == null || !this.extendedPersistenceContext.isActive()))
return false;
else
return true;
|
public boolean | isExtended()Indicates if this EntityManager is an extended Persistence Context
return this.extended;
|
public abstract boolean | isFlushModeAUTO()Internal method. Indicates whether flushMode is AUTO.
|
public boolean | isOpen()Indicates whether or not this entity manager is open. Returns true until
a call to {@link #close} is made.
return isOpen && factory.isOpen();
|
public void | joinTransaction()Indicate to the EntityManager that a JTA transaction is
active. This method should be called on a JTA application
managed EntityManager that was created outside the scope
of the active transaction to associate it with the current
JTA transaction.
try {
verifyOpen();
transaction.registerUnitOfWorkWithTxn(getActivePersistenceContext(checkForTransaction(true)));
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public void | lock(java.lang.Object entity, javax.persistence.LockModeType lockMode)Set the lock mode for an entity object contained in the persistence context.
try {
verifyOpen();
RepeatableWriteUnitOfWork context = getActivePersistenceContext(checkForTransaction(!isExtended()));
ClassDescriptor descriptor = context.getDescriptor(entity);
OptimisticLockingPolicy lockingPolicy = descriptor.getOptimisticLockingPolicy();
if ((lockingPolicy == null) || !(lockingPolicy instanceof VersionLockingPolicy)){
throw new PersistenceException(ExceptionLocalization.buildMessage("ejb30-wrong-lock_called_without_version_locking-index", null));
}
context.forceUpdateToVersionField(entity, (lockMode == LockModeType.WRITE));
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
protected java.lang.Object | mergeInternal(java.lang.Object entity)Merge the state of the given entity into the
current persistence context, using the unqualified
class name as the entity name.
if (entity == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_an_entity", new Object[] {entity}));
}
//gf830 - merging a removed entity should throw exception
if (getActivePersistenceContext(checkForTransaction(!isExtended())).getDeletedObjects().contains(entity)){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("cannot_merge_removed_entity", new Object[]{entity}));
}
try {
return getActivePersistenceContext(checkForTransaction(!isExtended())).mergeCloneWithReferences(entity, MergeManager.CASCADE_BY_MAPPING, true);
} catch (oracle.toplink.essentials.exceptions.OptimisticLockException ole) {
throw new javax.persistence.OptimisticLockException(ole);
}
|
public void | persist(java.lang.Object entity)If in a transaction this method will check for existence and register the object if
it is new. The instance of the entity provided will become managed.
try {
verifyOpen();
if (entity == null){
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_an_entity", new Object[] {entity}));
}
try {
getActivePersistenceContext(checkForTransaction(!isExtended())).registerNewObjectForPersist(entity, new IdentityHashtable());
} catch (RuntimeException e) {
if (ValidationException.class.isAssignableFrom(e.getClass())){
throw new EntityExistsException(e.getLocalizedMessage() , e);
}
throw e;
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public void | refresh(java.lang.Object entity)Refresh the state of the instance from the
database.
try {
verifyOpen();
UnitOfWork uow = getActivePersistenceContext(checkForTransaction(!isExtended()));
if(!contains(entity, uow)) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("cant_refresh_not_managed_object", new Object[]{entity}));
}
ReadObjectQuery query = new ReadObjectQuery();
query.setSelectionObject(entity);
query.refreshIdentityMapResult();
query.cascadeByMapping();
query.setLockMode(ObjectBuildingQuery.NO_LOCK);
Object refreshedEntity = null;
refreshedEntity = uow.executeQuery(query);
if(refreshedEntity == null) {
//bug3323, should also invalidate the shared cached object if object not exists in DB.
uow.getParent().getIdentityMapAccessor().invalidateObject(entity);
throw new EntityNotFoundException(ExceptionLocalization.buildMessage("entity_no_longer_exists_in_db", new Object[]{entity}));
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public void | remove(java.lang.Object entity)Remove the instance.
try {
verifyOpen();
if (entity == null){ //gf732 - check for null
throw new IllegalArgumentException(ExceptionLocalization.buildMessage("not_an_entity", new Object[] {entity}));
}
try{
getActivePersistenceContext(checkForTransaction(!isExtended())).performRemove(entity, new IdentityHashtable());
}catch (RuntimeException e){
throw e;
}
} catch (RuntimeException e) {
this.setRollbackOnly();
throw e;
}
|
public void | removeExtendedPersistenceContext()Internal method called by EntityTransactionImpl class in case of transaction rollback.
The caller is responsible for releasing extendedPersistenceContext and it's parent.
this.extendedPersistenceContext = null;
|
protected abstract void | setEntityTransactionWrapper()
|
protected abstract void | setJTATransactionWrapper()
|
protected void | setRollbackOnly()Internal method. Sets transaction to rollback only.
this.transaction.setRollbackOnlyInternal();
|
public boolean | shouldFlushBeforeQuery()
Object foundTransaction = checkForTransaction(false);
if ((foundTransaction!=null) && transaction.shouldFlushBeforeQuery(getActivePersistenceContext(foundTransaction))){
return true;
}
return false;
|
public boolean | shouldPropagatePersistenceContext()
return this.propagatePersistenceContext;
|
public void | verifyOpen()
if (!isOpen()){
throw new IllegalStateException(ExceptionLocalization.buildMessage("operation_on_closed_entity_manager"));
}
|