Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
// 31/05/2010-2.1 Michael O'Brien
// - 312503: invalidateClass(Class, recurseFlag) - when recurseFlag=false
// (non-default) will now invalidate the implementing subtree
// from [Class] down. Previously only the single Class inside the tree was invalidated.
package org.eclipse.persistence.internal.sessions;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.eclipse.persistence.descriptors.CacheIndex;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.QueryException;
import org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.expressions.Expression;
import org.eclipse.persistence.internal.descriptors.DescriptorIterator;
import org.eclipse.persistence.internal.helper.WriteLockManager;
import org.eclipse.persistence.internal.identitymaps.CacheId;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.identitymaps.IdentityMap;
import org.eclipse.persistence.internal.identitymaps.IdentityMapManager;
import org.eclipse.persistence.logging.SessionLog;
import org.eclipse.persistence.queries.InMemoryQueryIndirectionPolicy;
import org.eclipse.persistence.queries.ReadQuery;
import org.eclipse.persistence.sessions.DataRecord;
import org.eclipse.persistence.sessions.DatabaseRecord;
import org.eclipse.persistence.sessions.coordination.CommandManager;
import org.eclipse.persistence.sessions.coordination.MergeChangeSetCommand;
/**
* INTERNAL:
* Internal subclass that provides access to identity maps through the session.
* Implements the IdentityMapAccessor interface which provides all publicly available
* identity map functionality to users.
* This is the main class that should be used to access identity maps. In general, any
* function that accesses the identity map manager should go through this class
* Any session specific functionality appears in subclasses
*/
public class IdentityMapAccessor implements org.eclipse.persistence.sessions.IdentityMapAccessor, java.io.Serializable {
/** This is the identity map manager for this accessor. It should only be accessed through the getter **/
protected IdentityMapManager identityMapManager = null;
protected AbstractSession session = null;
/**
* INTERNAL:
*/
public IdentityMapAccessor() {
}
/**
* INTERNAL:
* An IdentityMapAccessor sits between the session and the identityMapManager
* It needs references in both directions.
*/
public IdentityMapAccessor(AbstractSession session) {
this.session = session;
}
/**
* INTERNAL:
* An IdentityMapAccessor sits between the session and the identityMapManager
* It needs references in both directions.
*/
public IdentityMapAccessor(AbstractSession session, IdentityMapManager identityMapManager) {
this.session = session;
this.identityMapManager = identityMapManager;
}
/**
* INTERNAL:
* Deferred lock the identity map for the object, this is used for avoiding deadlock
* The return cacheKey should be used to release the deferred lock.
*/
public CacheKey acquireDeferredLock(Object primarKey, Class> javaClass, ClassDescriptor descriptor, boolean isCacheCheckComplete) {
return getIdentityMapManager().acquireDeferredLock(primarKey, javaClass, descriptor, isCacheCheckComplete);
}
/**
* INTERNAL:
* Lock the identity map for the object, this must be done when building objects.
* The return cacheKey should be used to release the lock.
*/
public CacheKey acquireLock(Object primarKey, Class> javaClass, ClassDescriptor descriptor, boolean isCacheCheckComplete) {
return acquireLock(primarKey, javaClass, false, descriptor, isCacheCheckComplete);
}
/**
* INTERNAL:
* Provides access for setting a concurrency lock on an object in the IdentityMap.
* Called with true from the merge process, if true then the refresh will not refresh the object.
*/
public CacheKey acquireLock(Object primaryKey, Class> domainClass, boolean forMerge, ClassDescriptor descriptor, boolean isCacheCheckComplete) {
return getIdentityMapManager().acquireLock(primaryKey, domainClass, forMerge, descriptor, isCacheCheckComplete);
}
/**
* INTERNAL:
* Provides access for setting a concurrency lock on an object in the IdentityMap.
* Called with true from the merge process, if true then the refresh will not refresh the object.
*/
public CacheKey acquireLockNoWait(Object primaryKey, Class> domainClass, boolean forMerge, ClassDescriptor descriptor) {
return getIdentityMapManager().acquireLockNoWait(primaryKey, domainClass, forMerge, descriptor);
}
/**
* INTERNAL:
* Provides access for setting a concurrency lock on an object in the IdentityMap.
* Called with true from the merge process, if true then the refresh will not refresh the object.
*/
public CacheKey acquireLockWithWait(Object primaryKey, Class> domainClass, boolean forMerge, ClassDescriptor descriptor, int wait) {
return getIdentityMapManager().acquireLockWithWait(primaryKey, domainClass, forMerge, descriptor, wait);
}
/**
* INTERNAL:
* Find the cachekey for the provided primary key and place a readlock on it.
* This will allow multiple users to read the same object but prevent writes to
* the object while the read lock is held.
*/
public CacheKey acquireReadLockOnCacheKey(Object primaryKey, Class> domainClass, ClassDescriptor descriptor) {
return getIdentityMapManager().acquireReadLockOnCacheKey(primaryKey, domainClass, descriptor);
}
/**
* INTERNAL:
* Find the cachekey for the provided primary key and place a readlock on it.
* This will allow multiple users to read the same object but prevent writes to
* the object while the read lock is held.
* If no readlock can be acquired then do not wait but return null.
*/
public CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey, Class> domainClass, ClassDescriptor descriptor) {
return getIdentityMapManager().acquireReadLockOnCacheKeyNoWait(primaryKey, domainClass, descriptor);
}
/**
* INTERNAL:
* Lock the entire cache if the cache isolation requires.
* By default concurrent reads and writes are allowed.
* By write, unit of work merge is meant.
*/
public boolean acquireWriteLock() {
return getIdentityMapManager().acquireWriteLock();
}
/**
* ADVANCED:
* Clear all the query caches
*/
@Override
public void clearQueryCache() {
getIdentityMapManager().clearQueryCache();
}
/**
* ADVANCED:
* Clear the query class associated with the passed-in read query
*/
@Override
public void clearQueryCache(ReadQuery query) {
getIdentityMapManager().clearQueryCache(query);
}
/**
* ADVANCED:
* Clear the query cache associated with the named query on the session
*/
@Override
public void clearQueryCache(String sessionQueryName) {
getIdentityMapManager().clearQueryCache((ReadQuery)session.getQuery(sessionQueryName));
}
/**
* ADVANCED:
* Clear the query cache associated with the named query on the descriptor for the given class
*/
@Override
public void clearQueryCache(String descriptorQueryName, Class> queryClass) {
getIdentityMapManager().clearQueryCache((ReadQuery)session.getDescriptor(queryClass).getQueryManager().getQuery(descriptorQueryName));
}
/**
* ADVANCED:
* Return if their is an object for the primary key.
*/
@Override
public boolean containsObjectInIdentityMap(Object object) {
return containsObjectInIdentityMap(getSession().getId(object), object.getClass());
}
/**
* ADVANCED:
* Return if their is an object for the primary key.
*/
@Override
public boolean containsObjectInIdentityMap(Object primaryKey, Class> theClass) {
ClassDescriptor descriptor = getSession().getDescriptor(theClass);
return containsObjectInIdentityMap(primaryKey, theClass, descriptor);
}
/**
* INTERNAL:
* Return if their is an object for the primary key.
*/
public boolean containsObjectInIdentityMap(Object primaryKey, Class> theClass, ClassDescriptor descriptor) {
return getIdentityMapManager().containsKey(primaryKey, theClass, descriptor);
}
/**
* ADVANCED:
* Return if their is an object for the row containing primary key and the class.
*/
@Override
public boolean containsObjectInIdentityMap(DataRecord rowContainingPrimaryKey, Class> theClass) {
return containsObjectInIdentityMap(extractPrimaryKeyFromRow(rowContainingPrimaryKey, theClass), theClass);
}
/**
* INTERNAL:
* Extract primary key from a row.
*/
protected Object extractPrimaryKeyFromRow(DataRecord rowContainingPrimaryKey, Class> theClass) {
return this.session.getDescriptor(theClass).getObjectBuilder().extractPrimaryKeyFromRow((AbstractRecord)rowContainingPrimaryKey, this.session);
}
/**
* INTERNAL:
* Retrieve the cache key for the given object from the identity maps.
* @param object the object to get the cache key for.
*/
public CacheKey getCacheKeyForObject(Object object, ClassDescriptor descriptor) {
return getCacheKeyForObject(getSession().keyFromObject(object, descriptor), object.getClass(), descriptor, false);
}
/**
* INTERNAL:
* This method is used to get a list of those classes with IdentityMaps in the Session.
*/
public Vector getClassesRegistered() {
return getIdentityMapManager().getClassesRegistered();
}
/**
* ADVANCED:
* Query the cache in-memory.
* If the expression is too complex an exception will be thrown.
*/
public Vector getAllFromIdentityMap(Expression selectionCriteria, Class> theClass, DataRecord translationRow) throws QueryException {
return getAllFromIdentityMap(selectionCriteria, theClass, translationRow, InMemoryQueryIndirectionPolicy.SHOULD_THROW_INDIRECTION_EXCEPTION, true);
}
/**
* ADVANCED:
* Query the cache in-memory.
* If the expression is too complex an exception will be thrown.
*/
@Override
public Vector getAllFromIdentityMap(Expression selectionCriteria, Class> theClass, DataRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy) throws QueryException {
return getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, true);
}
/**
* ADVANCED:
* Query the cache in-memory.
* If the expression is too complex an exception will be thrown.
*/
@Override
public Vector getAllFromIdentityMap(Expression selectionCriteria, Class> theClass, DataRecord translationRow, int valueHolderPolicy) throws QueryException {
return getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, true);
}
/**
* ADVANCED:
* Query the cache in-memory.
* If the expression is too complex an exception will be thrown.
* Only return objects that are invalid in the cache if specified.
*/
@Override
public Vector getAllFromIdentityMap(Expression selectionCriteria, Class> theClass, DataRecord translationRow, InMemoryQueryIndirectionPolicy valueHolderPolicy, boolean shouldReturnInvalidatedObjects) throws QueryException {
int policy = 0;
if (valueHolderPolicy != null) {
policy = valueHolderPolicy.getPolicy();
}
return getAllFromIdentityMap(selectionCriteria, theClass, translationRow, policy, shouldReturnInvalidatedObjects);
}
/**
* ADVANCED:
* Query the cache in-memory.
* If the expression is too complex an exception will be thrown.
* Only return objects that are invalid in the cache if specified.
*/
@Override
public Vector getAllFromIdentityMap(Expression selectionCriteria, Class> theClass, DataRecord translationRow, int valueHolderPolicy, boolean shouldReturnInvalidatedObjects) throws QueryException {
return getIdentityMapManager().getAllFromIdentityMap(selectionCriteria, theClass, translationRow, valueHolderPolicy, shouldReturnInvalidatedObjects);
}
/**
* ADVANCED:
* Using a list of Entity PK this method will attempt to bulk load the entire list from the cache.
* In certain circumstances this can have large performance improvements over loading each item individually.
* @param pkList List of Entity PKs to extract from the cache
* @param descriptor Descriptor type to be retrieved.
* @return Map of Entity PKs associated to the Entities that were retrieved
*/
public Map