Class OrderedListContainerPolicy

All Implemented Interfaces:
Serializable, Cloneable, CoreContainerPolicy<AbstractSession>

public class OrderedListContainerPolicy extends ListContainerPolicy

Purpose: A OrderedListContainerPolicy is ContainerPolicy whose container class implements the List interface and is ordered by an @OrderBy.

Responsibilities: Provide the functionality to operate on an instance of a List.

See Also:
  • Field Details

  • Constructor Details

    • OrderedListContainerPolicy

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

      public OrderedListContainerPolicy(Class<?> containerClass)
      INTERNAL: Construct a new policy for the specified class.
    • OrderedListContainerPolicy

      public OrderedListContainerPolicy(String containerClassName)
      INTERNAL: Construct a new policy for the specified class name.
  • Method Details

    • addAll

      public boolean addAll(List elements, Object container, AbstractSession session, List<AbstractRecord> dbRows, ObjectBuildingQuery query, CacheKey parentCacheKey, boolean isTargetProtected)
      INTERNAL: Add a list of elements to container. This is used to add to a collection independent of JDK 1.1 and 1.2. The session may be required to wrap for the wrapper policy. The row may be required by subclasses Return whether the container changed
      Overrides:
      addAll in class ContainerPolicy
    • addAll

      public boolean addAll(List elements, Object container, AbstractSession session, List<AbstractRecord> dbRows, DataReadQuery query, CacheKey parentCacheKey, boolean isTargetProtected)
      INTERNAL: Add a list of elements to container. This is used to add to a collection independent of JDK 1.1 and 1.2. The session may be required to wrap for the wrapper policy. The row may be required by subclasses Return whether the container changed
      Overrides:
      addAll in class ContainerPolicy
    • addAll

      protected boolean addAll(List elements, Object container, AbstractSession session, List<AbstractRecord> dbRows, ReadQuery query, CacheKey parentCacheKey)
    • addIntoAtIndex

      protected void addIntoAtIndex(Integer index, Object object, Object container, AbstractSession session)
      INTERNAL: Add element into a container which implements the List interface. Add at a particular index.
    • compareCollectionsForChange

      public void compareCollectionsForChange(Object oldList, Object newList, CollectionChangeRecord changeRecord, AbstractSession session, ClassDescriptor referenceDescriptor)
      INTERNAL: This method is used to calculate the differences between two collections. This algorithm is a work in progress. It works great and all, but like anything, you can always make it better.
      Overrides:
      compareCollectionsForChange in class ContainerPolicy
    • correctOrderList

      public List correctOrderList(List<IndexedObject> indexedObjects)
      PUBLIC: Correct object's order in the list. The method is called only in one case - when the list of order indexes read from db is invalid (contains nulls, duplicates, negative values, values greater/equal list size). Each element of the indexedObjects is a pair of the order index and the corresponding object. The goal of the method is to return back the list of objects (not indexed objects!) in the correct order. The objects should not be altered. The default implementation of the method sorts indexedObjects according to their indexes (null less than any non-null). For example: indexedObjects = {{2, objectA}, {5, ObjectB}} returns {objectA, objectB}; indexedObjects = {{2, objectA}, {-1, ObjectB}} returns {objectB, objectA}; indexedObjects = {{2, objectA}, {null, ObjectB}} returns {objectB, objectA}; This method could be overridden by the user.
    • getChangeValuesFrom

      public Iterator getChangeValuesFrom(Map map)
      INTERNAL: Used to create an iterator on a the Map object passed to CollectionChangeRecord.addRemoveChange() to access the values to be removed. In the case of some container policies the values will actually be the keys.
      Overrides:
      getChangeValuesFrom in class ContainerPolicy
    • getListOrderField

      public DatabaseField getListOrderField()
    • setListOrderField

      public void setListOrderField(DatabaseField field)
    • getOrderCorrectionType

      public OrderCorrectionType getOrderCorrectionType()
    • setOrderCorrectionType

      public void setOrderCorrectionType(OrderCorrectionType orderCorrectionType)
    • iteratorFor

      public Object iteratorFor(Object container)
      INTERNAL: Return an list iterator for the given container.
      Specified by:
      iteratorFor in interface CoreContainerPolicy<AbstractSession>
      Overrides:
      iteratorFor in class CollectionContainerPolicy
      Parameters:
      container - java.lang.Object
      Returns:
      java.util.Enumeration/java.util.Iterator
      See Also:
    • isOrderedListPolicy

      public boolean isOrderedListPolicy()
      Overrides:
      isOrderedListPolicy in class ContainerPolicy
    • mergeChanges

      public void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, AbstractSession targetSession, boolean isSynchronizeOnMerge)
      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 change set. Synchronize if system property is specified. If not, default to clone the target collection. No need to synchronize if the collection is new.
      Overrides:
      mergeChanges in class ContainerPolicy
    • mergeChanges

      protected void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, 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 change set.
      Overrides:
      mergeChanges in class ContainerPolicy
    • registerRemoveNewObjectIfRequired

      protected void registerRemoveNewObjectIfRequired(ObjectChangeSet objectChanges, MergeManager mergeManager)
      INTERNAL:
    • removeFromAtIndex

      protected void removeFromAtIndex(int index, Object container)
      INTERNAL: Remove the element at the specified index.
    • recordAddToCollectionInChangeRecord

      public void recordAddToCollectionInChangeRecord(ObjectChangeSet changeSetToAdd, 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:
      recordAddToCollectionInChangeRecord in class ListContainerPolicy
    • recordRemoveFromCollectionInChangeRecord

      public void recordRemoveFromCollectionInChangeRecord(ObjectChangeSet changeSetToRemove, CollectionChangeRecord collectionChangeRecord)
      Description copied from class: ListContainerPolicy
      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:
      recordRemoveFromCollectionInChangeRecord in class ListContainerPolicy
    • recordUpdateToCollectionInChangeRecord

      public void recordUpdateToCollectionInChangeRecord(CollectionChangeEvent event, ObjectChangeSet changeSet, CollectionChangeRecord collectionChangeRecord)
      Description copied from class: ContainerPolicy
      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
    • shouldAddAll

      public boolean shouldAddAll()
      INTERNAL: Indicates whether addAll method should be called to add entire collection, or it's possible to call addInto multiple times instead.
      Overrides:
      shouldAddAll in class ContainerPolicy
    • getAdditionalFieldsForJoin

      public List<DatabaseField> getAdditionalFieldsForJoin(CollectionMapping baseMapping)
      INTERNAL: Return any additional fields required by the policy for a fetch join.
      Overrides:
      getAdditionalFieldsForJoin in class ContainerPolicy
    • updateJoinedMappingIndexesForMapKey

      public int updateJoinedMappingIndexesForMapKey(Map<DatabaseMapping,Object> indexList, int index)
      INTERNAL: Add the index field count.
      Overrides:
      updateJoinedMappingIndexesForMapKey in class ContainerPolicy
    • updateChangeRecordForSelfMerge

      public void updateChangeRecordForSelfMerge(ChangeRecord changeRecord, Object source, Object target, ForeignReferenceMapping mapping, UnitOfWorkChangeSet parentUOWChangeSet, UnitOfWorkImpl unitOfWork)
      INTERNAL: Update a ChangeRecord to replace the ChangeSet for the old entity with the changeSet for the new Entity. This is used when an Entity is merged into itself and the Entity reference new or detached entities.
      Overrides:
      updateChangeRecordForSelfMerge in class ListContainerPolicy
    • getAdditionalTablesForJoinQuery

      public List<DatabaseTable> getAdditionalTablesForJoinQuery()
      INTERNAL: Return any tables that will be required when this mapping is used as part of a join query.
      Overrides:
      getAdditionalTablesForJoinQuery in class ContainerPolicy
    • addAdditionalFieldsToQuery

      public void addAdditionalFieldsToQuery(ReadQuery selectionQuery, Expression baseExpression)
      INTERNAL: Add the index field to the query.
      Overrides:
      addAdditionalFieldsToQuery in class ContainerPolicy
      See Also: