Class MappedKeyMapContainerPolicy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, CoreContainerPolicy<AbstractSession>, CoreMappedKeyMapContainerPolicy<AbstractSession>

    public class MappedKeyMapContainerPolicy
    extends MapContainerPolicy
    implements CoreMappedKeyMapContainerPolicy<AbstractSession>
    A MappedKeyMapContainerPolicy should be used for mappings to implementers of Map. It differs from MapContainerPolicy by allowing the MapKey to be an otherwise unmapped column in a table rather than a mapped element of the value in the map. This container policy holds a reference to a KeyMapping that will be used to construct the key from the database and a reference to its owner which creates the value for the map. The key of the map can be any implementer of MapKeyMapping and the data representing the key can either be stored in the target table of the value mapping, or in a collection table that associates the source to the target. The data can either be everything necessary to compose the key, or foreign keys that allow the key to be retrieved
    Author:
    tware
    See Also:
    MapContainerPolicy, MapKeyMapping, MapComponentMapping, Serialized Form
    • Constructor Detail

      • MappedKeyMapContainerPolicy

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

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

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

      • addAdditionalFieldsToQuery

        public void addAdditionalFieldsToQuery​(ReadQuery selectionQuery,
                                               Expression baseExpression)
        INTERNAL: Called when the selection query is being initialize to add the fields for the key to the query
        Overrides:
        addAdditionalFieldsToQuery in class ContainerPolicy
        See Also:
        MappedKeyMapContinerPolicy
      • getKeyMappingDataForWriteQuery

        public java.util.Map getKeyMappingDataForWriteQuery​(java.lang.Object object,
                                                            AbstractSession session)
        INTERNAL: Add any non-Foreign-key data from an Object describe by a MapKeyMapping to a database row This is typically used in write queries to ensure all the data stored in the collection table is included in the query.
        Overrides:
        getKeyMappingDataForWriteQuery in class ContainerPolicy
      • 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 MapContainerPolicy
      • addInto

        public boolean addInto​(java.lang.Object element,
                               java.lang.Object container,
                               AbstractSession session,
                               AbstractRecord row,
                               DataReadQuery query,
                               CacheKey parentCacheKey,
                               boolean isTargetProtected)
        INTERNAL: This is used for ordered List containers to add all of the elements to the collection in the order of the index field in the row. This is currently only used by OrderListContainerPolicy, so this is just a stub. The passing of the query is to allow future compatibility with Maps (ordered Map).
        Overrides:
        addInto in class ContainerPolicy
      • buildCloneForKey

        public java.lang.Object buildCloneForKey​(java.lang.Object key,
                                                 java.lang.Object parent,
                                                 CacheKey parentCacheKey,
                                                 java.lang.Integer refreshCascade,
                                                 AbstractSession cloningSession,
                                                 boolean isExisting,
                                                 boolean isCacheCheckComplete)
        Build a clone for the key of a Map represented by this container policy.
        Overrides:
        buildCloneForKey in class ContainerPolicy
        Returns:
      • 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 MapContainerPolicy
        See Also:
        ObjectReferenceMapping.buildReferencesPKList, ContainerPolicy.buildReferencesPKList
      • cascadeDiscoverAndPersistUnregisteredNewObjects

        public void cascadeDiscoverAndPersistUnregisteredNewObjects​(java.lang.Object object,
                                                                    java.util.Map newObjects,
                                                                    java.util.Map unregisteredExistingObjects,
                                                                    java.util.Map visitedObjects,
                                                                    UnitOfWorkImpl uow,
                                                                    java.util.Set cascadeErrors)
        INTERNAL: Cascade discover and persist new objects during commit to the map key
        Overrides:
        cascadeDiscoverAndPersistUnregisteredNewObjects in class ContainerPolicy
      • cascadePerformRemoveIfRequired

        public void cascadePerformRemoveIfRequired​(java.lang.Object object,
                                                   UnitOfWorkImpl uow,
                                                   java.util.Map visitedObjects)
        INTERNAL: Cascade registerNew to any mappings managed by the container policy. This will cascade the register to the key mapping.
        Overrides:
        cascadePerformRemoveIfRequired in class ContainerPolicy
      • cascadeRegisterNewIfRequired

        public void cascadeRegisterNewIfRequired​(java.lang.Object object,
                                                 UnitOfWorkImpl uow,
                                                 java.util.Map visitedObjects)
        INTERNAL: Cascade registerNew to any mappings managed by the container policy. This will cascade the register to the key mapping.
        Overrides:
        cascadeRegisterNewIfRequired in class ContainerPolicy
      • clone

        public java.lang.Object clone()
        INTERNAL: The mapping clones itself to create deep copy.
        Overrides:
        clone in class ContainerPolicy
      • compareContainers

        public boolean compareContainers​(java.lang.Object firstObjectMap,
                                         java.lang.Object secondObjectMap)
        INTERNAL: Return true if keys are the same. False otherwise
      • 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 MapContainerPolicy
      • 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 MapContainerPolicy
        parent - if this is an aggregate, the owner of the aggregate
        Returns:
        See Also:
        MappedKeyMapContainerPolicy
      • convertClassNamesToClasses

        public void convertClassNamesToClasses​(java.lang.ClassLoader classLoader)
        INTERNAL: Convert all the class-name-based settings in this ContainerPolicy to actual class-based settings
        Overrides:
        convertClassNamesToClasses in class MapContainerPolicy
        Parameters:
        classLoader -
      • getForeignKeyFieldsForMapKey

        public java.util.Map<DatabaseField,​DatabaseField> getForeignKeyFieldsForMapKey()
        INTERNAL: Return a Map of any foreign keys defined within the the MapKey.
      • getCloneDataFromChangeSet

        public java.lang.Object getCloneDataFromChangeSet​(ObjectChangeSet changeSet)
        INTERNAL: Used when objects are added or removed during an update. This method returns either the clone from the ChangeSet or a packaged version of it that contains things like map keys.
        Overrides:
        getCloneDataFromChangeSet in class ContainerPolicy
      • getIdentityFieldsForMapKey

        public java.util.List<DatabaseField> getIdentityFieldsForMapKey()
        INTERNAL: Return the fields that make up the identity of the mapped object. For mappings with a primary key, it will be the set of fields in the primary key. For mappings without a primary key it will likely be all the fields.
        Overrides:
        getIdentityFieldsForMapKey in class ContainerPolicy
      • getKeyConverter

        public Converter getKeyConverter()
        INTERNAL: Get the Converter for the key of this mapping if one exists.
      • getKeyQuery

        public DatabaseQuery getKeyQuery()
        INTERNAL: Some map keys must be obtained from the database. This query is used to obtain the key.
      • isKeyAvailableFromElement

        protected boolean isKeyAvailableFromElement()
        CollectionTableMapContainerPolicy is for mappings where the key is stored in a table separately from the map element.
        Overrides:
        isKeyAvailableFromElement in class MapContainerPolicy
      • isMapKeyAttribute

        public boolean isMapKeyAttribute()
        INTERNAL: Return whether a map key this container policy represents is an attribute By default this method will return false since only subclasses actually represent maps.
        Overrides:
        isMapKeyAttribute in class MapContainerPolicy
      • isMapKeyObject

        public boolean isMapKeyObject()
        INTERNAL: Return if the map key this container policy represents is a OneToOne.
        Overrides:
        isMapKeyObject in class ContainerPolicy
      • postCalculateChanges

        public void postCalculateChanges​(java.lang.Object key,
                                         java.lang.Object value,
                                         ClassDescriptor referenceDescriptor,
                                         DatabaseMapping mapping,
                                         UnitOfWorkImpl uow)
        INTERNAL: Add the provided object to the deleted objects list on the commit manager. This may be overridden by subclasses to process a composite object.
        Overrides:
        postCalculateChanges in class ContainerPolicy
      • processAdditionalWritableMapKeyFields

        public void processAdditionalWritableMapKeyFields​(AbstractSession session)
        INTERNAL: This method is used to check the key mapping to ensure that it does not write to a field that is written by another mapping. There are two possibilities: 1. The conflicting mapping has already been processed. In that case, we add MultipleWritableMappings exception to the integrity checker right away 2. There are no conflicting mappings. In that case, we store the list of fields that this mapping has processed on the descriptor for the target so they can be checked as the descriptor initializes.
        Overrides:
        processAdditionalWritableMapKeyFields in class ContainerPolicy
      • requiresDataModificationEvents

        public boolean requiresDataModificationEvents()
        INTERNAL: Returns whether this ContainerPolicy requires data modification events when objects are added or deleted during update.
        Overrides:
        requiresDataModificationEvents in class ContainerPolicy
        Returns:
      • keyFrom

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

        public void propogatePostDelete​(DeleteObjectQuery query,
                                        java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePostDelete in class ContainerPolicy
      • propogatePostInsert

        public void propogatePostInsert​(WriteObjectQuery query,
                                        java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePostInsert in class ContainerPolicy
      • propogatePostUpdate

        public void propogatePostUpdate​(WriteObjectQuery query,
                                        java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePostUpdate in class ContainerPolicy
      • propogatePreDelete

        public void propogatePreDelete​(DeleteObjectQuery query,
                                       java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePreDelete in class ContainerPolicy
      • propogatePreInsert

        public void propogatePreInsert​(WriteObjectQuery query,
                                       java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePreInsert in class ContainerPolicy
      • propogatePreUpdate

        public void propogatePreUpdate​(WriteObjectQuery query,
                                       java.lang.Object object)
        INTERNAL: Propagate the postDeleteEvent to any additional objects the query is aware of
        Overrides:
        propogatePreUpdate in class ContainerPolicy
      • propagatesEventsToCollection

        public boolean propagatesEventsToCollection()
        INTERNAL: Returns true if the key mapping is an AggregateObjectMapping. Aggregates need events propagated to them because they are not explicitly deleted, updated or inserted
        Overrides:
        propagatesEventsToCollection in class ContainerPolicy
      • setKeyField

        public void setKeyField​(DatabaseField keyField,
                                ClassDescriptor descriptor)
        INTERNAL: Set the DatabaseField that will represent the key in a DirectMapMapping.
      • setDescriptorForKeyMapping

        public void setDescriptorForKeyMapping​(ClassDescriptor descriptor)
        INTERNAL: Used during initialization of DirectMapMapping. Sets the descriptor associated with the key.
      • setKeyConverter

        public void setKeyConverter​(Converter keyConverter,
                                    DirectMapMapping mapping)
        INTERNAL: Set a converter on the KeyField of a DirectCollectionMapping.
      • setKeyConverterClassName

        public void setKeyConverterClassName​(java.lang.String keyConverterClassName,
                                             DirectMapMapping mapping)
        INTERNAL: Set the name of the class to be used as a converter for the key of a DirectMapMaping.
      • setKeyMapping

        public void setKeyMapping​(MapKeyMapping mapping)
      • setKeyQuery

        public void setKeyQuery​(DatabaseQuery keyQuery)
        INTERNAL: Some map keys must be obtained from the database. This query is used to obtain the key
        Parameters:
        keyQuery -
      • shouldIncludeKeyInDeleteEvent

        public boolean shouldIncludeKeyInDeleteEvent()
        INTERNAL: Return whether data for a map key must be included on a Delete datamodification event If the keyMapping is privateOwned, that data should be.
        Overrides:
        shouldIncludeKeyInDeleteEvent in class ContainerPolicy
      • shouldUpdateForeignKeysPostInsert

        public boolean shouldUpdateForeignKeysPostInsert()
        INTERNAL: Certain types of container policies require an extra update statement after a relationship is inserted. Return whether this update statement is required.
        Overrides:
        shouldUpdateForeignKeysPostInsert in class ContainerPolicy
      • updateJoinedMappingIndexesForMapKey

        public int updateJoinedMappingIndexesForMapKey​(java.util.Map<DatabaseMapping,​java.lang.Object> indexList,
                                                       int index)
        INTERNAL: Update the joined mapping indices Adds the key mapping and it's index to the list of joined mappings.
        Overrides:
        updateJoinedMappingIndexesForMapKey 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.
        Overrides:
        unwrapKey in class MapContainerPolicy