Module org.eclipse.persistence.core
Class MapContainerPolicy
java.lang.Object
org.eclipse.persistence.internal.queries.ContainerPolicy
org.eclipse.persistence.internal.queries.InterfaceContainerPolicy
org.eclipse.persistence.internal.queries.MapContainerPolicy
- All Implemented Interfaces:
Serializable
,Cloneable
,CoreContainerPolicy<AbstractSession>
- Direct Known Subclasses:
MappedKeyMapContainerPolicy
Purpose: A MapContainerPolicy is ContainerPolicy whose container class implements the Map interface.
Responsibilities: Provide the functionality to operate on an instance of a Map.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
INTERNAL: This inner class is used to iterate through the Map.Entry s of a Map. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Class
<?> protected String
protected Field
protected Method
protected String
The Method which is called on each value added to the Map and whose result is used as key to the value.Fields inherited from class org.eclipse.persistence.internal.queries.InterfaceContainerPolicy
cloneMethod, containerClass, containerClassName
Fields inherited from class org.eclipse.persistence.internal.queries.ContainerPolicy
constructor, defaultContainerClass, elementDescriptor
-
Constructor Summary
ConstructorsConstructorDescriptionINTERNAL: Construct a new policy.MapContainerPolicy
(Class<?> containerClass) INTERNAL: Construct a new policy for the specified class.MapContainerPolicy
(String containerClassName) INTERNAL: Construct a new policy for the specified class name. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addInto
(Object key, Object element, Object container, AbstractSession session) INTERNAL: Add element into container which implements the Map interface.boolean
addInto
(Object element, Object container, AbstractSession session) INTERNAL: Add element to container.void
addNextValueFromIteratorInto
(Object valuesIterator, Object parent, CacheKey parentCacheKey, Object toCollection, CollectionMapping mapping, Integer refreshCascade, AbstractSession cloningSession, boolean isExisting, boolean isFromSharedCache) INTERNAL: This method is used to add the next value from an iterator built using ContainerPolicy's iteratorFor() method into the toCollection.void
buildChangeSetForNewObjectInCollection
(Object object, ClassDescriptor referenceDescriptor, UnitOfWorkChangeSet uowChangeSet, AbstractSession session) INTERNAL: Ensure the new key is set for the change set for a new map objectprotected Object
buildCloneForValue
(Object value, Object parent, CacheKey parentCacheKey, CollectionMapping mapping, Integer refreshCascade, AbstractSession cloningSession, boolean isExisting, boolean isFromSharedCache) Build a clone for the value in a mapping.buildCollectionEntry
(Object objectAdded, ObjectChangeSet changeSet) INTERNAL: Return an object representing an entry in the collection represented by this container policy This method will returns an Association containing the key and the value for a MapObject[]
buildReferencesPKList
(Object container, AbstractSession session) INTERNAL: This method will access the target relationship and create a list of information to rebuild the collection.void
INTERNAL: Remove all the elements from container.INTERNAL: Return a clone of the specified container.boolean
compareKeys
(Object sourceValue, AbstractSession session) INTERNAL: Return true if keys are the same in the source as the backup.concatenateContainers
(Object firstContainer, Object secondContainer, AbstractSession session) INTERNAL: Build a new container, add the contents of each of the specified containers to it, and return it.protected boolean
INTERNAL: Return the true if element exists in container.void
convertClassNamesToClasses
(ClassLoader classLoader) INTERNAL: Convert all the class-name-based settings in this ContainerPolicy to actual class-based settings.createChangeEvent
(Object collectionOwner, String propertyName, Object collectionChanged, Object elementChanged, int changeType, Integer index, boolean isChangeApplied) INTERNAL: Creates a CollectionChangeEvent for the containerINTERNAL: Create a query key that links to the map key.createWrappedObjectFromExistingWrappedObject
(Object wrappedObject, Object parent, ClassDescriptor referenceDescriptor, MergeManager mergeManager, AbstractSession targetSession) INTERNAL: This method will actually potentially wrap an object in two ways.getDirectKeyField
(CollectionMapping baseMapping) INTERNAL: Return the DatabaseField that represents the key in a DirectMapMapping.Class
<?> INTERNAL: Returns the element class which defines the map key.INTERNAL: Returns the element class name which defines the map key.Class
<?> INTERNAL:INTERNAL: Returns the key name which will return the value of the key to be used in the container.INTERNAL: Return the type of the map key, this will be overridden by container policies that allow maps.boolean
INTERNAL: Return whether the iterator has more objects.protected void
INTERNAL: Set the keyMethod or keyField based on the keyName.protected boolean
MapContainerPolicy is for mappings where the key is stored in actual element.boolean
INTERNAL: Return whether a map key this container policy represents is an attribute.boolean
INTERNAL Yes this is a MapPolicyboolean
isValidContainer
(Object container) INTERNAL: Validate the container type.iteratorFor
(Object container) INTERNAL: Return an Iterator for the given container.keyFrom
(Object element, AbstractSession session) INTERNAL: Return the key for the specified element.keyFromEntry
(Object entry) Get the key from the passed in Map.Entry.keyFromIterator
(Object iterator) protected Object
INTERNAL: Return the next object on the queue.INTERNAL: Return the next object on the queue.nextEntry
(Object iterator, AbstractSession session) INTERNAL: Return the next object on the queue.void
prepare
(DatabaseQuery query, AbstractSession session) Prepare and validate.void
recordUpdateToCollectionInChangeRecord
(CollectionChangeEvent event, ObjectChangeSet changeSet, CollectionChangeRecord collectionChangeRecord) This method is used to bridge the behavior between Attribute Change Tracking and deferred change tracking with respect to adding the same instance multiple times.boolean
removeFrom
(Object key, Object element, Object container, AbstractSession session) INTERNAL: Remove element from container which implements the Map interface.void
setElementClass
(Class<?> elementClass) INTERNAL: Sets the element class which defines the method.void
setKeyMethod
(String keyMethodName, Class<?> elementClass) INTERNAL: Sets the Method to be used to generate the key in a Map type container class.void
setKeyMethod
(String keyMethodName, String elementClassName) INTERNAL: Sets the Method to be used to generate the key in a Map type container class.void
setKeyMethodName
(String keyMethodName) INTERNAL: Sets the Method to be used to generate the key in a Map type container class.void
setKeyName
(String keyName) INTERNAL: Sets the key name to be used to generate the key in a Map type container class.void
setKeyName
(String keyName, Class<?> elementClass) INTERNAL: Sets the key name to be used to generate the key in a Map type container class.void
setKeyName
(String keyName, String elementClassName) INTERNAL: Sets the key name to be used to generate the key in a Map type container class.int
INTERNAL: Return the size of container.unwrapElement
(Object object) INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map.unwrapIteratorResult
(Object object) INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map.unwrapKey
(Object key, AbstractSession session) INTERNAL: Allow the key to be unwrapped.valueFromPKList
(Object[] pks, AbstractRecord foreignKeys, ForeignReferenceMapping mapping, AbstractSession session) INTERNAL: This method is used to load a relationship from a list of PKs.Methods inherited from class org.eclipse.persistence.internal.queries.InterfaceContainerPolicy
buildContainerFromVector, equals, getCloneMethod, getCloneMethod, getContainerClass, getContainerClassName, hashCode, invokeCloneMethodOn, isValidContainerType, setCloneMethod, setContainerClass, setContainerClassName, toStringInfo
Methods inherited from class org.eclipse.persistence.internal.queries.ContainerPolicy
addAdditionalFieldsToQuery, addAll, addAll, addFieldsForMapKey, addInto, addInto, addNestedJoinsQueriesForMapKey, buildCloneForKey, buildDefaultPolicy, buildKey, buildKeyFromJoinedRow, buildPolicyFor, buildPolicyFor, buildSelectionQueryForDirectCollectionMapping, cascadeDiscoverAndPersistUnregisteredNewObjects, cascadePerformRemoveIfRequired, cascadeRegisterNewIfRequired, clone, clone, collectObjectForNewCollection, compareCollectionsForChange, containerInstance, containerInstance, contains, copyMapDataToRow, createChangeSetForKeys, deleteWrappedObject, execute, getAdditionalFieldsForJoin, getAdditionalTablesForJoinQuery, getChangeValuesFrom, getCloneDataFromChangeSet, getConstructor, getDefaultContainerClass, getDescriptorForMapKey, getElementDescriptor, getIdentityFieldsForMapKey, getKeyMappingDataForWriteQuery, getKeySelectionCriteria, hasElementDescriptor, hasOrder, initialize, initializeConstructor, isCollectionPolicy, isCursoredStreamPolicy, isCursorPolicy, isDirectMapPolicy, isEmpty, isListPolicy, isMapKeyObject, isMappedKeyMapPolicy, isOrderedListPolicy, isScrollableCursorPolicy, iterateOnMapKey, mergeCascadeParts, mergeChanges, mergeChanges, next, overridesRead, postCalculateChanges, postCalculateChanges, postInitialize, prepareForExecution, processAdditionalWritableMapKeyFields, propagatesEventsToCollection, propogatePostDelete, propogatePostInsert, propogatePostUpdate, propogatePreDelete, propogatePreInsert, propogatePreUpdate, recordAddToCollectionInChangeRecord, recordPrivateOwnedRemovals, recordRemoveFromCollectionInChangeRecord, remoteExecute, removeFrom, removeFrom, requiresDataModificationEvents, setConstructor, setDefaultContainerClass, setElementDescriptor, shouldAddAll, shouldIncludeKeyInDeleteEvent, shouldUpdateForeignKeysPostInsert, toString, updateChangeRecordForSelfMerge, updateJoinedMappingIndexesForMapKey, vectorFor
-
Field Details
-
keyName
The Method which is called on each value added to the Map and whose result is used as key to the value. -
elementClassName
-
elementClass
-
keyField
-
keyMethod
-
-
Constructor Details
-
MapContainerPolicy
public MapContainerPolicy()INTERNAL: Construct a new policy. -
MapContainerPolicy
INTERNAL: Construct a new policy for the specified class. -
MapContainerPolicy
INTERNAL: Construct a new policy for the specified class name.
-
-
Method Details
-
prepare
Prepare and validate. Set the element class.- Overrides:
prepare
in classContainerPolicy
- Throws:
QueryException
-
addInto
INTERNAL: Add element to container. This is used to add to a collection independent of the collection type. The session may be required to wrap for the wrapper policy. Return whether the container changed.- Specified by:
addInto
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
addInto
in classContainerPolicy
-
addInto
INTERNAL: Add element into container which implements the Map interface.- Specified by:
addInto
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
addInto
in classContainerPolicy
-
addNextValueFromIteratorInto
public void addNextValueFromIteratorInto(Object valuesIterator, Object parent, CacheKey parentCacheKey, Object toCollection, CollectionMapping mapping, Integer refreshCascade, AbstractSession cloningSession, boolean isExisting, boolean isFromSharedCache) INTERNAL: This method is used to add the next value from an iterator built using ContainerPolicy's iteratorFor() method into the toCollection. Since this ContainerPolicy represents a Map, the key and the value are extracted and added.- Overrides:
addNextValueFromIteratorInto
in classContainerPolicy
- See Also:
-
buildCollectionEntry
INTERNAL: Return an object representing an entry in the collection represented by this container policy This method will returns an Association containing the key and the value for a Map- Overrides:
buildCollectionEntry
in classContainerPolicy
- See Also:
-
buildReferencesPKList
INTERNAL: This method will access the target relationship and create a list of information to rebuild the collection. For the MapContainerPolicy this return will consist of an array with serial Map entry key and value elements.- Overrides:
buildReferencesPKList
in classContainerPolicy
- See Also:
-
buildChangeSetForNewObjectInCollection
public void buildChangeSetForNewObjectInCollection(Object object, ClassDescriptor referenceDescriptor, UnitOfWorkChangeSet uowChangeSet, AbstractSession session) INTERNAL: Ensure the new key is set for the change set for a new map object- Overrides:
buildChangeSetForNewObjectInCollection
in classContainerPolicy
-
buildCloneForValue
protected Object buildCloneForValue(Object value, Object parent, CacheKey parentCacheKey, CollectionMapping mapping, Integer refreshCascade, AbstractSession cloningSession, boolean isExisting, boolean isFromSharedCache) Build a clone for the value in a mapping. -
clear
INTERNAL: Remove all the elements from container.- Specified by:
clear
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
clear
in classContainerPolicy
-
cloneFor
INTERNAL: Return a clone of the specified container.- Overrides:
cloneFor
in classInterfaceContainerPolicy
-
compareKeys
INTERNAL: Return true if keys are the same in the source as the backup. False otherwise in the case of read-only compare against the original- Overrides:
compareKeys
in classContainerPolicy
-
concatenateContainers
public Object concatenateContainers(Object firstContainer, Object secondContainer, AbstractSession session) INTERNAL: Build a new container, add the contents of each of the specified containers to it, and return it. Both of the containers must use the same container policy (namely, this one).- Overrides:
concatenateContainers
in classContainerPolicy
-
contains
INTERNAL: Return the true if element exists in container.- Overrides:
contains
in classContainerPolicy
- Returns:
- boolean true if container 'contains' element
-
convertClassNamesToClasses
INTERNAL: Convert all the class-name-based settings in this ContainerPolicy to actual class-based settings. This method is used when converting a project that has been built with class names to a project with classes.- Overrides:
convertClassNamesToClasses
in classInterfaceContainerPolicy
-
createChangeEvent
public CollectionChangeEvent createChangeEvent(Object collectionOwner, String propertyName, Object collectionChanged, Object elementChanged, int changeType, Integer index, boolean isChangeApplied) INTERNAL: Creates a CollectionChangeEvent for the container- Overrides:
createChangeEvent
in classInterfaceContainerPolicy
-
createQueryKeyForMapKey
INTERNAL: Create a query key that links to the map key. MapContainerPolicy does not have a specific mapping for the key, so return null.- Overrides:
createQueryKeyForMapKey
in classInterfaceContainerPolicy
-
createWrappedObjectFromExistingWrappedObject
public Object createWrappedObjectFromExistingWrappedObject(Object wrappedObject, Object parent, ClassDescriptor referenceDescriptor, MergeManager mergeManager, AbstractSession targetSession) INTERNAL: This method will actually potentially wrap an object in two ways. It will first wrap the object based on the referenceDescriptor's wrapper policy. It will also potentially do some wrapping based on what is required by the container policy.- Overrides:
createWrappedObjectFromExistingWrappedObject
in classContainerPolicy
- Parameters:
parent
- if this is an aggregate, the owner of the aggregate- See Also:
-
getDirectKeyField
INTERNAL: Return the DatabaseField that represents the key in a DirectMapMapping. MapContainerPolicy gets it fields from the reference descriptor of the provided mappings. It uses its keyName to lookup the appropriate mapping and returns the field from that mapping.- Overrides:
getDirectKeyField
in classInterfaceContainerPolicy
-
getElementClass
INTERNAL: Returns the element class which defines the map key. -
getElementClassName
INTERNAL: Returns the element class name which defines the map key. -
getInterfaceType
INTERNAL:- Specified by:
getInterfaceType
in classInterfaceContainerPolicy
-
getKeyName
INTERNAL: Returns the key name which will return the value of the key to be used in the container. -
getKeyType
INTERNAL: Return the type of the map key, this will be overridden by container policies that allow maps.- Overrides:
getKeyType
in classContainerPolicy
-
isMapPolicy
public boolean isMapPolicy()INTERNAL Yes this is a MapPolicy- Overrides:
isMapPolicy
in classContainerPolicy
-
isKeyAvailableFromElement
protected boolean isKeyAvailableFromElement()MapContainerPolicy is for mappings where the key is stored in actual element. -
isMapKeyAttribute
public boolean isMapKeyAttribute()INTERNAL: Return whether a map key this container policy represents is an attribute.- Overrides:
isMapKeyAttribute
in classInterfaceContainerPolicy
-
hasNext
INTERNAL: Return whether the iterator has more objects. The iterator is the one returned from #iteratorFor().- Specified by:
hasNext
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
hasNext
in classInterfaceContainerPolicy
- See Also:
-
initializeKey
protected void initializeKey()INTERNAL: Set the keyMethod or keyField based on the keyName. -
iteratorFor
INTERNAL: Return an Iterator for the given container.- Specified by:
iteratorFor
in interfaceCoreContainerPolicy<AbstractSession>
- Specified by:
iteratorFor
in classContainerPolicy
- See Also:
-
keyFrom
INTERNAL: Return the key for the specified element.- Overrides:
keyFrom
in classContainerPolicy
-
keyFromEntry
Get the key from the passed in Map.Entry.- Overrides:
keyFromEntry
in classContainerPolicy
-
keyFromIterator
- Overrides:
keyFromIterator
in classContainerPolicy
-
next
INTERNAL: Return the next object on the queue. The iterator is the one returned from #iteratorFor().- Overrides:
next
in classInterfaceContainerPolicy
- See Also:
-
nextEntry
INTERNAL: Return the next object on the queue. The iterator is the one returned from #iteratorFor(). This will return a MapEntry to allow use of the key- Specified by:
nextEntry
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
nextEntry
in classContainerPolicy
- See Also:
-
nextEntry
INTERNAL: Return the next object on the queue. The iterator is the one returned from #iteratorFor(). This will return a MapEntry to allow use of the key- Specified by:
nextEntry
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
nextEntry
in classContainerPolicy
- See Also:
-
unwrapElement
INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map. This method returns the object from the iterator- Overrides:
unwrapElement
in classContainerPolicy
- See Also:
-
unwrapIteratorResult
INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map. This method returns the object from the iterator- Overrides:
unwrapIteratorResult
in classContainerPolicy
- See Also:
-
unwrapKey
INTERNAL: Allow the key to be unwrapped. This will be overridden by container policies that allow keys that are entities. -
recordUpdateToCollectionInChangeRecord
public void recordUpdateToCollectionInChangeRecord(CollectionChangeEvent event, ObjectChangeSet changeSet, CollectionChangeRecord collectionChangeRecord) This method is used to bridge the behavior between Attribute Change Tracking and deferred change tracking with respect to adding the same instance multiple times. Each ContainerPolicy type will implement specific behavior for the collection type it is wrapping. These methods are only valid for collections containing object references- Overrides:
recordUpdateToCollectionInChangeRecord
in classContainerPolicy
-
removeFrom
INTERNAL: Remove element from container which implements the Map interface.- Overrides:
removeFrom
in classContainerPolicy
-
setElementClass
INTERNAL: Sets the element class which defines the method. -
isValidContainer
INTERNAL: Validate the container type.- Overrides:
isValidContainer
in classContainerPolicy
- See Also:
-
setKeyName
INTERNAL: Sets the key name to be used to generate the key in a Map type container class. The key name, may be the name of a field or method.- Overrides:
setKeyName
in classContainerPolicy
- See Also:
-
setKeyName
INTERNAL: Sets the key name to be used to generate the key in a Map type container class. The key name, may be the name of a field or method. An instance of the class is provided in the case when the descriptor is being built in code.- Overrides:
setKeyName
in classContainerPolicy
-
setKeyName
INTERNAL: Sets the key name to be used to generate the key in a Map type container class. The key name, maybe the name of a field or method. -
setKeyMethod
INTERNAL: Sets the Method to be used to generate the key in a Map type container class. -
setKeyMethod
INTERNAL: Sets the Method to be used to generate the key in a Map type container class. -
setKeyMethodName
INTERNAL: Sets the Method to be used to generate the key in a Map type container class. -
sizeFor
INTERNAL: Return the size of container.- Specified by:
sizeFor
in interfaceCoreContainerPolicy<AbstractSession>
- Overrides:
sizeFor
in classContainerPolicy
-
valueFromPKList
public Object valueFromPKList(Object[] pks, AbstractRecord foreignKeys, ForeignReferenceMapping mapping, AbstractSession session) INTERNAL: This method is used to load a relationship from a list of PKs. This list may be available if the relationship has been cached.- Overrides:
valueFromPKList
in classContainerPolicy
-