Class DirectMapMapping

java.lang.Object
org.eclipse.persistence.core.mappings.CoreMapping<AttributeAccessor,org.eclipse.persistence.internal.sessions.AbstractSession,org.eclipse.persistence.internal.queries.ContainerPolicy,ClassDescriptor,org.eclipse.persistence.internal.helper.DatabaseField>
All Implemented Interfaces:
Serializable, Cloneable, ContainerMapping, MapComponentMapping, RelationalMapping

public class DirectMapMapping extends DirectCollectionMapping implements MapComponentMapping
Mapping for a collection of key-value pairs. The key and value must be simple types (String, Number, Date, etc.) and stored in a single table along with a foreign key to the source object. A converter can be used on the key and value if the desired object types do not match the data types.
See Also:
Author:
Steven Vo
  • Constructor Details

    • DirectMapMapping

      public DirectMapMapping()
      DirectMapCollectionMapping constructor
  • Method Details

    • setContainerPolicy

      public void setContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy containerPolicy)
      ADVANCED: Configure the mapping to use a container policy. This must be a MappedKeyMapContainerPolicy policy. Set the valueMapping for the policy.
      Specified by:
      setContainerPolicy in interface ContainerMapping
      Overrides:
      setContainerPolicy in class DirectCollectionMapping
    • getKeyConverter

      public Converter getKeyConverter()
      PUBLIC: Return the converter on the mapping. A converter can be used to convert between the key's object value and database value.
    • setKeyConverter

      public void setKeyConverter(Converter keyConverter)
      PUBLIC: Set the converter on the mapping. A converter can be used to convert between the key's object value and database value.
    • setKeyConverterClassName

      public void setKeyConverterClassName(String keyConverterClassName)
      INTERNAL: Set the converter class name on the mapping. Initialized in convertClassNamesToClasses. A converter can be used to convert between the key's object value and database value.
    • addToCollectionChangeRecord

      public void addToCollectionChangeRecord(Object newKey, Object newValue, org.eclipse.persistence.internal.sessions.ObjectChangeSet objectChangeSet, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow) throws DescriptorException
      INTERNAL: Add a new value and its change set to the collection change record. This is used by attribute change tracking. If a value has changed then issue a remove first with the key then an add.
      Throws:
      DescriptorException
    • buildCloneForPartObject

      public Object buildCloneForPartObject(Object attributeValue, Object original, org.eclipse.persistence.internal.identitymaps.CacheKey cacheKey, Object clone, org.eclipse.persistence.internal.sessions.AbstractSession cloningSession, Integer refreshCascade, boolean isExisting, boolean isFromSharedCache)
      INTERNAL: Require for cloning, the part must be cloned. Ignore the objects, use the attribute value.
      Overrides:
      buildCloneForPartObject in class CollectionMapping
    • calculateDeferredChanges

      public void calculateDeferredChanges(org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: Used by AttributeLevelChangeTracking to update a changeRecord with calculated changes as opposed to detected changes. If an attribute can not be change tracked it's changes can be detected through this process.
      Overrides:
      calculateDeferredChanges in class DirectCollectionMapping
    • cascadeDiscoverAndPersistUnregisteredNewObjects

      public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, Set cascadeErrors)
      INTERNAL: Cascade discover and persist new objects during commit.
      Overrides:
      cascadeDiscoverAndPersistUnregisteredNewObjects in class DirectCollectionMapping
    • cascadePerformRemoveIfRequired

      public void cascadePerformRemoveIfRequired(Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, Map visitedObjects)
      INTERNAL: Cascade perform delete through mappings that require the cascade
      Overrides:
      cascadePerformRemoveIfRequired in class DirectCollectionMapping
    • cascadeRegisterNewIfRequired

      public void cascadeRegisterNewIfRequired(Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow, Map visitedObjects)
      INTERNAL: Cascade registerNew for Create through mappings that require the cascade
      Overrides:
      cascadeRegisterNewIfRequired in class DirectCollectionMapping
    • compareCollectionsForChange

      public void compareCollectionsForChange(Object oldCollection, Object newCollection, org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: This method is used to calculate the differences between two collections.
      Overrides:
      compareCollectionsForChange in class DirectCollectionMapping
    • compareForChange

      public org.eclipse.persistence.internal.sessions.ChangeRecord compareForChange(Object clone, Object backUp, org.eclipse.persistence.internal.sessions.ObjectChangeSet owner, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: This method compares the changes between two direct collections. Comparisons are made on equality not identity.
      Overrides:
      compareForChange in class DirectCollectionMapping
      Returns:
      prototype.changeset.ChangeRecord
    • compareObjects

      public boolean compareObjects(Object firstObject, Object secondObject, org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: Compare the attributes belonging to this mapping for the objects.
      Overrides:
      compareObjects in class DirectCollectionMapping
    • convertClassNamesToClasses

      public void convertClassNamesToClasses(ClassLoader classLoader)
      Description copied from class: DirectCollectionMapping
      INTERNAL: Convert all the class-name-based settings in this mapping to actual class-based settings This method is implemented by subclasses as necessary.
      Overrides:
      convertClassNamesToClasses in class DirectCollectionMapping
    • createMapComponentFromRow

      public Object createMapComponentFromRow(org.eclipse.persistence.internal.sessions.AbstractRecord dbRow, ObjectBuildingQuery query, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, org.eclipse.persistence.internal.sessions.AbstractSession session, boolean isTargetProtected)
      INTERNAL Called when a DatabaseMapping is used to map the key in a collection. Returns the key.
      Specified by:
      createMapComponentFromRow in interface MapComponentMapping
    • getDirectKeyField

      public org.eclipse.persistence.internal.helper.DatabaseField getDirectKeyField()
      INTERNAL:
    • initialize

      public void initialize(org.eclipse.persistence.internal.sessions.AbstractSession session) throws DescriptorException
      INTERNAL: Initialize and validate the mapping properties.
      Overrides:
      initialize in class DirectCollectionMapping
      Throws:
      DescriptorException
    • initializeDeleteQuery

      protected void initializeDeleteQuery(org.eclipse.persistence.internal.sessions.AbstractSession session)
      Overrides:
      initializeDeleteQuery in class DirectCollectionMapping
    • initializeInsertQuery

      protected void initializeInsertQuery(org.eclipse.persistence.internal.sessions.AbstractSession session)
      Initialize insert query. This query is used to insert the collection of objects into the reference table.
      Overrides:
      initializeInsertQuery in class DirectCollectionMapping
    • initializeSelectionStatement

      protected void initializeSelectionStatement(org.eclipse.persistence.internal.sessions.AbstractSession session)
      Overrides:
      initializeSelectionStatement in class DirectCollectionMapping
    • iterateOnRealAttributeValue

      public void iterateOnRealAttributeValue(org.eclipse.persistence.internal.descriptors.DescriptorIterator iterator, Object realAttributeValue)
      INTERNAL: Iterate on the attribute value. The value holder has already been processed. PERF: Avoid iteration if not required.
      Overrides:
      iterateOnRealAttributeValue in class DirectCollectionMapping
    • iterateOnElement

      public void iterateOnElement(org.eclipse.persistence.internal.descriptors.DescriptorIterator iterator, Object element)
      INTERNAL: Iterate on the specified element.
      Overrides:
      iterateOnElement in class DirectCollectionMapping
    • isDirectMapMapping

      public boolean isDirectMapMapping()
      INTERNAL: Related mapping should implement this method to return true.
      Overrides:
      isDirectMapMapping in class DatabaseMapping
    • mergeChangesIntoObject

      public void mergeChangesIntoObject(Object target, org.eclipse.persistence.internal.sessions.ChangeRecord changeRecord, Object source, org.eclipse.persistence.internal.sessions.MergeManager mergeManager, org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
      INTERNAL: Merge changes from the source to the target object. Because this is a collection mapping, values are added to or removed from the collection based on the changeset.
      Overrides:
      mergeChangesIntoObject in class DirectCollectionMapping
    • mergeIntoObject

      public void mergeIntoObject(Object target, boolean isTargetUnInitialized, Object source, org.eclipse.persistence.internal.sessions.MergeManager mergeManager, org.eclipse.persistence.internal.sessions.AbstractSession targetSession)
      INTERNAL: Merge changes from the source to the target object.
      Overrides:
      mergeIntoObject in class DirectCollectionMapping
    • performDataModificationEvent

      public void performDataModificationEvent(Object[] event, org.eclipse.persistence.internal.sessions.AbstractSession session) throws DatabaseException, DescriptorException
      INTERNAL: Perform the commit event. This is used in the uow to delay data modifications. This is mostly dealt with in the superclass. Private Owned deletes require extra functionality
      Overrides:
      performDataModificationEvent in class DirectCollectionMapping
      Throws:
      DatabaseException
      DescriptorException
    • postCalculateChanges

      public void postCalculateChanges(ChangeRecord changeRecord, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow)
      INTERNAL: Overridden by mappings that require additional processing of the change record after the record has been calculated.
      Overrides:
      postCalculateChanges in class DirectCollectionMapping
    • postInsert

      public void postInsert(WriteObjectQuery query) throws DatabaseException
      INTERNAL: Insert the private owned object.
      Overrides:
      postInsert in class DirectCollectionMapping
      Throws:
      DatabaseException
    • postUpdateWithChangeSet

      protected void postUpdateWithChangeSet(WriteObjectQuery writeQuery) throws DatabaseException
      INTERNAL: Update private owned part.
      Overrides:
      postUpdateWithChangeSet in class DirectCollectionMapping
      Throws:
      DatabaseException
    • preDelete

      public void preDelete(DeleteObjectQuery query) throws DatabaseException
      INTERNAL: Propagate the preDelete event through the container policy if necessary
      Overrides:
      preDelete in class DirectCollectionMapping
      Throws:
      DatabaseException
    • initOrRebuildSelectQuery

      protected void initOrRebuildSelectQuery()
      INTERNAL: Rebuild select query.
      Overrides:
      initOrRebuildSelectQuery in class DirectCollectionMapping
    • recordPrivateOwnedRemovals

      public void recordPrivateOwnedRemovals(Object object, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow)
      INTERNAL: Overridden by mappings that require additional processing of the change record after the record has been calculated.
      Overrides:
      recordPrivateOwnedRemovals in class DirectCollectionMapping
    • removeFromCollectionChangeRecord

      protected void removeFromCollectionChangeRecord(Object newKey, Object newValue, org.eclipse.persistence.internal.sessions.ObjectChangeSet objectChangeSet, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow) throws DescriptorException
      INTERNAL: Remove a value and its change set from the collection change record. This is used by attribute change tracking.
      Throws:
      DescriptorException
    • setDirectKeyField

      public void setDirectKeyField(org.eclipse.persistence.internal.helper.DatabaseField keyField)
      INTERNAL:
    • setDirectKeyFieldClassification

      public void setDirectKeyFieldClassification(Class fieldType)
      ADVANCED: Set the class type of the field value. This can be used if field value differs from the object value, has specific typing requirements such as usage of java.sql.Blob or NChar. This must be called after the field name has been set.
    • setDirectKeyFieldClassificationName

      public void setDirectKeyFieldClassificationName(String fieldTypeName)
      ADVANCED: Set the class type name of the field value. This can be used if field value differs from the object value, has specific typing requirements such as usage of java.sql.Blob or NChar. This must be called after the direct key field has been set.
    • setDirectKeyFieldName

      public void setDirectKeyFieldName(String fieldName)
      PUBLIC: Set the direct key field name in the reference table. This is the field that the primitive data value of the Map key is stored in.
    • updateChangeRecord

      public void updateChangeRecord(Object clone, Object newValue, Object oldValue, org.eclipse.persistence.internal.sessions.ObjectChangeSet objectChangeSet, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow) throws DescriptorException
      INTERNAL: Either create a new change record or update the change record with the new value. This is used by attribute change tracking.
      Overrides:
      updateChangeRecord in class DirectCollectionMapping
      Throws:
      DescriptorException
    • updateCollectionChangeRecord

      public void updateCollectionChangeRecord(CollectionChangeEvent event, org.eclipse.persistence.internal.sessions.ObjectChangeSet changeSet, org.eclipse.persistence.internal.sessions.UnitOfWorkImpl uow)
      INTERNAL: Add or removes a new value and its change set to the collection change record based on the event passed in. This is used by attribute change tracking.
      Overrides:
      updateCollectionChangeRecord in class DirectCollectionMapping
    • useMapClass

      public void useMapClass(Class concreteClass)
      PUBLIC: Configure the mapping to use an instance of the specified container class to hold the target objects.

      The default container class is java.util.Hashtable.

      The container class must implements (directly or indirectly) the Map interface.

      Note: Do not use both useMapClass(Class concreteClass), useTransparentMap(). The last use of one of the two methods will override the previous one.

      Overrides:
      useMapClass in class CollectionMapping
    • useTransparentMap

      public void useTransparentMap()
      PUBLIC: Configure the mapping to use an instance of the specified container class to hold the target objects.

      The container class must implement (directly or indirectly) the Map interface.

      Note: Do not use both useMapClass(Class concreteClass), useTransparentMap(). The last use of one of the two methods will override the previous one.

    • setKeyClass

      public void setKeyClass(Class keyClass)
      PUBLIC: This is a helper method to set the key converter to a TypeConversionConverter. This ensures that the key value from the database is converted to the correct Java type. The converter can also be set directly. Note that setting the converter to another converter will overwrite this setting.
    • getKeyClass

      public Class getKeyClass()
      PUBLIC: This is a helper method to get the object class from the key converter if it is a TypeConversionConverter. This returns null if not using a TypeConversionConverter key converter.
    • setValueClass

      public void setValueClass(Class valueClass)
      PUBLIC: This is a helper method to set the value converter to a TypeConversionConverter. This ensures that the value from the database is converted to the correct Java type. The converter can also be set directly. Note that setting the converter to another converter will overwrite this setting.
    • simpleAddToCollectionChangeRecord

      public void simpleAddToCollectionChangeRecord(Object referenceKey, Object objectToAdd, org.eclipse.persistence.internal.sessions.ObjectChangeSet changeSet, org.eclipse.persistence.internal.sessions.AbstractSession session)
      ADVANCED: This method is used to have an object add to a collection once the changeSet is applied The referenceKey parameter should only be used for direct Maps.
      Overrides:
      simpleAddToCollectionChangeRecord in class DirectCollectionMapping
    • simpleRemoveFromCollectionChangeRecord

      public void simpleRemoveFromCollectionChangeRecord(Object referenceKey, Object objectToRemove, org.eclipse.persistence.internal.sessions.ObjectChangeSet changeSet, org.eclipse.persistence.internal.sessions.AbstractSession session)
      ADVANCED: This method is used to have an object removed from a collection once the changeSet is applied The referenceKey parameter should only be used for direct Maps.
      Overrides:
      simpleRemoveFromCollectionChangeRecord in class DirectCollectionMapping
    • getValueClass

      public Class getValueClass()
      PUBLIC: This is a helper method to get the object class from the value converter if it is a TypeConversionConverter. This returns null if not using a TypeConversionConverter value converter.
    • executeBatchQuery

      protected void executeBatchQuery(DatabaseQuery query, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, Map referenceDataByKey, org.eclipse.persistence.internal.sessions.AbstractSession session, org.eclipse.persistence.internal.sessions.AbstractRecord translationRow)
      INTERNAL: Prepare and execute the batch query and store the results for each source object in a map keyed by the mappings source keys of the source objects.
      Overrides:
      executeBatchQuery in class DirectCollectionMapping
    • valueFromRowInternalWithJoin

      protected Object valueFromRowInternalWithJoin(org.eclipse.persistence.internal.sessions.AbstractRecord row, org.eclipse.persistence.internal.queries.JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, org.eclipse.persistence.internal.identitymaps.CacheKey parentCacheKey, org.eclipse.persistence.internal.sessions.AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException
      INTERNAL: Return the value of the field from the row or a value holder on the query to obtain the object.
      Overrides:
      valueFromRowInternalWithJoin in class DirectCollectionMapping
      Throws:
      DatabaseException