org.eclipse.persistence.internal.identitymaps.IdentityMap Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*
* Copyright (c) 1998, 2019 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:
// Gordon Yorke - Part of the Cache Interceptor feature. (ER 219683)
// 12/14/2017-3.0 Tomas Kraus
// - 522635: ConcurrentModificationException when triggering lazy load from conforming query
package org.eclipse.persistence.internal.identitymaps;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.QueryException;
import org.eclipse.persistence.indirection.ValueHolderInterface;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
/**
* Purpose: Provides the interface for IdentityMap interaction.
*
Responsibilities:
* Provides access to all of the public interface for the EclipseLink IdentityMaps.
* This interface can be used if implementing custom identity maps that are radically
* different than the stock IdentityMaps otherwise simply extending the appropriate
* IdentityMap implementation is the best approach.
*
* @see CacheKey
* @since EclipseLink 1.0M7
*/
public interface IdentityMap extends Cloneable{
/**
* Acquire a deferred lock on the object.
* This is used while reading if the object has relationships without indirection.
* This first thread will get an active lock.
* Other threads will get deferred locks, all threads will wait until all other threads are complete before releasing their locks.
*/
CacheKey acquireDeferredLock(Object primaryKey, boolean isCacheCheckComplete);
/**
* Acquire an active lock on the object.
* This is used by reading (when using indirection or no relationships) and by merge.
*/
CacheKey acquireLock(Object primaryKey, boolean forMerge, boolean isCacheCheckComplete);
/**
* Acquire an active lock on the object, if not already locked.
* This is used by merge for missing existing objects.
*/
CacheKey acquireLockNoWait(Object primaryKey, boolean forMerge);
/**
* Acquire an active lock on the object, if not already locked.
* This is used by merge for missing existing objects.
*/
CacheKey acquireLockWithWait(Object primaryKey, boolean forMerge, int wait);
/**
* Acquire a read lock on the object.
* This is used by UnitOfWork cloning.
* This will allow multiple users to read the same object but prevent writes to the object while the read lock is held.
*/
CacheKey acquireReadLockOnCacheKey(Object primaryKey);
/**
* Acquire a read lock on the object, if not already locked.
* This is used by UnitOfWork cloning.
* This will allow multiple users to read the same object but prevent writes to the object while the read lock is held.
*/
CacheKey acquireReadLockOnCacheKeyNoWait(Object primaryKey);
/**
* Clone the map and all of the CacheKeys.
* This is used by UnitOfWork commitAndResumeOnFailure to avoid corrupting the cache during a failed commit.
*/
Object clone();
/**
* Add all locked CacheKeys to the map grouped by thread.
* Used to print all the locks in the identity map.
*/
void collectLocks(HashMap threadList);
/**
* Return true if an CacheKey with the primary key is in the map.
* User API.
* @param primaryKey is the primary key for the object to search for.
*/
boolean containsKey(Object primaryKey);
/**
* Allow for the cache to be iterated on.
*/
Enumeration elements();
/**
* Return the object cached in the identity map or null if it could not be found.
* User API.
*/
Object get(Object primaryKey);
/**
* 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
* @throws QueryException
*/
Map