Class MapContainerPolicy

    • Field Detail

      • keyName

        protected java.lang.String keyName
        The Method which is called on each value added to the Map and whose result is used as key to the value.
      • elementClassName

        protected java.lang.String elementClassName
      • elementClass

        protected java.lang.Class elementClass
      • keyField

        protected transient java.lang.reflect.Field keyField
      • keyMethod

        protected transient java.lang.reflect.Method keyMethod
    • Constructor Detail

      • MapContainerPolicy

        public MapContainerPolicy()
        INTERNAL: Construct a new policy.
      • MapContainerPolicy

        public MapContainerPolicy​(java.lang.Class containerClass)
        INTERNAL: Construct a new policy for the specified class.
      • MapContainerPolicy

        public MapContainerPolicy​(java.lang.String containerClassName)
        INTERNAL: Construct a new policy for the specified class name.
    • Method Detail

      • addInto

        public boolean addInto​(java.lang.Object element,
                               java.lang.Object container,
                               AbstractSession session)
        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 interface CoreContainerPolicy<AbstractSession>
        Overrides:
        addInto in class ContainerPolicy
      • addNextValueFromIteratorInto

        public void addNextValueFromIteratorInto​(java.lang.Object valuesIterator,
                                                 java.lang.Object parent,
                                                 CacheKey parentCacheKey,
                                                 java.lang.Object toCollection,
                                                 CollectionMapping mapping,
                                                 java.lang.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 class ContainerPolicy
        See Also:
        MappedKeyMapContainerPolicy
      • buildCollectionEntry

        public java.lang.Object buildCollectionEntry​(java.lang.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 Map
        Overrides:
        buildCollectionEntry in class ContainerPolicy
        Returns:
        See Also:
        MappedKeyMapContainerPolicy
      • buildReferencesPKList

        public java.lang.Object[] buildReferencesPKList​(java.lang.Object container,
                                                        AbstractSession session)
        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 class ContainerPolicy
        See Also:
        ObjectReferenceMapping.buildReferencesPKList, ContainerPolicy.buildReferencesPKList
      • buildCloneForValue

        protected java.lang.Object buildCloneForValue​(java.lang.Object value,
                                                      java.lang.Object parent,
                                                      CacheKey parentCacheKey,
                                                      CollectionMapping mapping,
                                                      java.lang.Integer refreshCascade,
                                                      AbstractSession cloningSession,
                                                      boolean isExisting,
                                                      boolean isFromSharedCache)
        Build a clone for the value in a mapping.
      • cloneFor

        public java.lang.Object cloneFor​(java.lang.Object container)
        INTERNAL: Return a clone of the specified container.
        Overrides:
        cloneFor in class InterfaceContainerPolicy
      • compareKeys

        public boolean compareKeys​(java.lang.Object sourceValue,
                                   AbstractSession session)
        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 class ContainerPolicy
      • concatenateContainers

        public java.lang.Object concatenateContainers​(java.lang.Object firstContainer,
                                                      java.lang.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 class ContainerPolicy
      • contains

        protected boolean contains​(java.lang.Object element,
                                   java.lang.Object container)
        INTERNAL: Return the true if element exists in container.
        Overrides:
        contains in class ContainerPolicy
        Returns:
        boolean true if container 'contains' element
      • convertClassNamesToClasses

        public void convertClassNamesToClasses​(java.lang.ClassLoader classLoader)
        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 class InterfaceContainerPolicy
        Parameters:
        classLoader -
      • createChangeEvent

        public CollectionChangeEvent createChangeEvent​(java.lang.Object collectionOwner,
                                                       java.lang.String propertyName,
                                                       java.lang.Object collectionChanged,
                                                       java.lang.Object elementChanged,
                                                       int changeType,
                                                       java.lang.Integer index,
                                                       boolean isChangeApplied)
        INTERNAL: Creates a CollectionChangeEvent for the container
        Overrides:
        createChangeEvent in class InterfaceContainerPolicy
      • createQueryKeyForMapKey

        public QueryKey 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 class InterfaceContainerPolicy
      • createWrappedObjectFromExistingWrappedObject

        public java.lang.Object createWrappedObjectFromExistingWrappedObject​(java.lang.Object wrappedObject,
                                                                             java.lang.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 class ContainerPolicy
        parent - if this is an aggregate, the owner of the aggregate
        Returns:
        See Also:
        MappedKeyMapContainerPolicy
      • getDirectKeyField

        public DatabaseField getDirectKeyField​(CollectionMapping baseMapping)
        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 class InterfaceContainerPolicy
      • getElementClass

        public java.lang.Class getElementClass()
        INTERNAL: Returns the element class which defines the map key.
      • getElementClassName

        public java.lang.String getElementClassName()
        INTERNAL: Returns the element class name which defines the map key.
      • getKeyName

        public java.lang.String getKeyName()
        INTERNAL: Returns the key name which will return the value of the key to be used in the container.
      • getKeyType

        public java.lang.Object getKeyType()
        INTERNAL: Return the type of the map key, this will be overridden by container policies that allow maps.
        Overrides:
        getKeyType in class ContainerPolicy
      • 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 class InterfaceContainerPolicy
      • initializeKey

        protected void initializeKey()
        INTERNAL: Set the keyMethod or keyField based on the keyName.
      • keyFrom

        public java.lang.Object keyFrom​(java.lang.Object element,
                                        AbstractSession session)
        INTERNAL: Return the key for the specified element.
        Overrides:
        keyFrom in class ContainerPolicy
      • keyFromEntry

        public java.lang.Object keyFromEntry​(java.lang.Object entry)
        Get the key from the passed in Map.Entry.
        Overrides:
        keyFromEntry in class ContainerPolicy
      • nextEntry

        public java.lang.Object nextEntry​(java.lang.Object iterator,
                                          AbstractSession session)
        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 interface CoreContainerPolicy<AbstractSession>
        Overrides:
        nextEntry in class ContainerPolicy
        See Also:
        ContainerPolicy#iteratorFor(Object iterator, AbstractSession session)
      • unwrapElement

        public java.lang.Object unwrapElement​(java.lang.Object object)
        INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map. This method returns the object from the iterator
        Overrides:
        unwrapElement in class ContainerPolicy
      • unwrapIteratorResult

        public java.lang.Object unwrapIteratorResult​(java.lang.Object object)
        INTERNAL: MapContainerPolicy's iterator iterates on the Entries of a Map. This method returns the object from the iterator
        Overrides:
        unwrapIteratorResult in class ContainerPolicy
      • unwrapKey

        public java.lang.Object unwrapKey​(java.lang.Object key,
                                          AbstractSession session)
        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 class ContainerPolicy
      • removeFrom

        public boolean removeFrom​(java.lang.Object key,
                                  java.lang.Object element,
                                  java.lang.Object container,
                                  AbstractSession session)
        INTERNAL: Remove element from container which implements the Map interface.
        Overrides:
        removeFrom in class ContainerPolicy
      • setElementClass

        public void setElementClass​(java.lang.Class elementClass)
        INTERNAL: Sets the element class which defines the method.
      • setKeyName

        public void setKeyName​(java.lang.String keyName,
                               java.lang.String elementClassName)
        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 class ContainerPolicy
        See Also:
        MapContainerPolicy
      • setKeyName

        public void setKeyName​(java.lang.String keyName,
                               java.lang.Class elementClass)
        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 class ContainerPolicy
      • setKeyName

        public void setKeyName​(java.lang.String keyName)
        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

        public void setKeyMethod​(java.lang.String keyMethodName,
                                 java.lang.Class elementClass)
        INTERNAL: Sets the Method to be used to generate the key in a Map type container class.
      • setKeyMethod

        public void setKeyMethod​(java.lang.String keyMethodName,
                                 java.lang.String elementClassName)
        INTERNAL: Sets the Method to be used to generate the key in a Map type container class.
      • setKeyMethodName

        public void setKeyMethodName​(java.lang.String keyMethodName)
        INTERNAL: Sets the Method to be used to generate the key in a Map type container class.