Class DescriptorIterator

  • Direct Known Subclasses:
    ReplaceValueHoldersIterator

    public abstract class DescriptorIterator
    extends java.lang.Object
    This class provides a generic way of using the descriptor information to traverse an object graph. Define a subclass, or an inner class, that implements at least #iterate(Object) to implement a new traversal feature without having to change the mapping classes or the object builder. It provides functionality such as a cascading depth, a stack of visited object, and a collection of the visited objects. NOTE: If this works nicely the merge manager, remote traversals, and maybe even aspects of the commit manager could be converted to use this class.
    • Field Detail

      • visitedObjects

        protected java.util.Map visitedObjects
      • visitedStack

        protected java.util.Stack visitedStack
      • usesGroup

        protected boolean usesGroup
      • shouldTrackCurrentGroup

        protected boolean shouldTrackCurrentGroup
      • result

        protected java.lang.Object result
      • shouldIterateOverIndirectionObjects

        protected boolean shouldIterateOverIndirectionObjects
      • shouldIterateOverUninstantiatedIndirectionObjects

        protected boolean shouldIterateOverUninstantiatedIndirectionObjects
      • shouldIterateOverWrappedObjects

        protected boolean shouldIterateOverWrappedObjects
      • shouldIterateOnIndirectionObjects

        protected boolean shouldIterateOnIndirectionObjects
      • shouldIterateOnAggregates

        protected boolean shouldIterateOnAggregates
      • shouldIterateOnPrimitives

        protected boolean shouldIterateOnPrimitives
      • shouldIterateOnFetchGroupAttributesOnly

        protected boolean shouldIterateOnFetchGroupAttributesOnly
      • shouldBreak

        protected boolean shouldBreak
      • cascadeDepth

        protected int cascadeDepth
    • Constructor Detail

      • DescriptorIterator

        public DescriptorIterator()
        Construct a typical iterator: iterate over all the objects process the objects contained by "value holders"... ...but only if they have already been instantiated... ...and don't process the "value holders" themselves process "wrapped" objects skip aggregate objects skip primitives (Strings, Dates, Integers, etc.)
    • Method Detail

      • getCascadeDepth

        public int getCascadeDepth()
      • getDescriptorFor

        protected ClassDescriptor getDescriptorFor​(java.lang.Object object)
        Fetch and return the descriptor for the specified object.
      • getResult

        public java.lang.Object getResult()
      • getVisitedGrandparent

        public java.lang.Object getVisitedGrandparent()
        Return the second-to-last object visited.
      • getVisitedObjects

        public java.util.Map getVisitedObjects()
      • getVisitedParent

        public java.lang.Object getVisitedParent()
        Return the last object visited.
      • getVisitedStack

        public java.util.Stack getVisitedStack()
      • internalIterateAggregateObject

        protected void internalIterateAggregateObject​(java.lang.Object aggregateObject)
        Iterate an aggregate object (i.e. an object that is the target of an AggregateMapping). Override this method if appropriate.
      • internalIterateIndirectContainer

        protected void internalIterateIndirectContainer​(IndirectContainer container)
        Iterate an indirect container (IndirectList or IndirectMap). Override this method if appropriate.
      • internalIteratePrimitive

        protected void internalIteratePrimitive​(java.lang.Object primitiveValue)
        Iterate a primitive object (String, Date, Integer, etc.). Override this method if appropriate.
      • internalIterateReferenceObject

        protected void internalIterateReferenceObject​(java.lang.Object referenceObject)
        Iterate a (a non-Aggregate) reference object. Override this method if appropriate.
      • internalIterateValueHolder

        protected void internalIterateValueHolder​(ValueHolderInterface valueHolder)
        Iterate a value holder. Override this method if appropriate.
      • iterate

        protected abstract void iterate​(java.lang.Object object)
        To define a new iterator create a subclass and define at least this method. Given an object or set of the objects, this method will be called on those objects and any object connected to them by using the descriptors to traverse the object graph. Override the assorted #internalIterate*() methods if appropriate.
      • iterateForAggregateMapping

        public void iterateForAggregateMapping​(java.lang.Object aggregateObject,
                                               DatabaseMapping mapping,
                                               ClassDescriptor descriptor)
        Iterate on the mapping's reference object and recursively iterate on the reference object's reference objects. This is used for aggregate and aggregate collection mappings, which are not iterated on by default.
      • iterateIndirectContainerForMapping

        public void iterateIndirectContainerForMapping​(IndirectContainer container,
                                                       DatabaseMapping mapping)
        Iterate on the indirection object for its mapping.
      • iteratePrimitiveForMapping

        public void iteratePrimitiveForMapping​(java.lang.Object primitiveValue,
                                               DatabaseMapping mapping)
        Iterate on the primitive value for its mapping.
      • iterateReferenceObjectForMapping

        public void iterateReferenceObjectForMapping​(java.lang.Object referenceObject,
                                                     DatabaseMapping mapping)
        Iterate on the mapping's reference object and recursively iterate on the reference object's reference objects.
      • iterateReferenceObjects

        protected void iterateReferenceObjects​(java.lang.Object sourceObject)
        Iterate over the sourceObject's reference objects, updating the visited stack appropriately.
      • internalIterateReferenceObjects

        protected void internalIterateReferenceObjects​(java.lang.Object sourceObject)
      • iterateValueHolderForMapping

        public void iterateValueHolderForMapping​(ValueHolderInterface valueHolder,
                                                 DatabaseMapping mapping)
        Iterate on the value holder for its mapping.
      • setCascadeDepth

        public void setCascadeDepth​(int cascadeDepth)
      • setCurrentDescriptor

        public void setCurrentDescriptor​(ClassDescriptor currentDescriptor)
      • setCurrentMapping

        public void setCurrentMapping​(DatabaseMapping currentMapping)
      • setCurrentItem

        public void setCurrentItem​(AttributeItem item)
      • setCurrentGroup

        public void setCurrentGroup​(AttributeGroup group)
      • setResult

        public void setResult​(java.lang.Object result)
      • setShouldBreak

        public void setShouldBreak​(boolean shouldBreak)
      • setShouldIterateOnAggregates

        public void setShouldIterateOnAggregates​(boolean shouldIterateOnAggregates)
        Set whether the aggregate reference objects themselves should be processed. (The objects referenced by the aggregate objects will be processed either way.)
      • setShouldIterateOnFetchGroupAttributesOnly

        public void setShouldIterateOnFetchGroupAttributesOnly​(boolean shouldIterateOnFetchGroupAttributesOnly)
        Set whether the attributes outside fetch group should be processed.
      • setShouldIterateOnIndirectionObjects

        public void setShouldIterateOnIndirectionObjects​(boolean shouldIterateOnIndirectionObjects)
        Set whether the indirection objects themselves (e.g. the ValueHolders) should be processed.
      • setShouldIterateOnPrimitives

        public void setShouldIterateOnPrimitives​(boolean shouldIterateOnPrimitives)
        Set whether to process primitive reference objects (e.g. Strings, Dates, ints).
      • setShouldIterateOverIndirectionObjects

        public void setShouldIterateOverIndirectionObjects​(boolean shouldIterateOverIndirectionObjects)
        Set whether to process the objects contained by indirection objects (e.g. a ValueHolder's value) - but *without* instantiating them.
        See Also:
        #setShouldIterateOverUninstantiatedIndirectionObjects()
      • setShouldIterateOverUninstantiatedIndirectionObjects

        public void setShouldIterateOverUninstantiatedIndirectionObjects​(boolean shouldIterateOverUninstantiatedIndirectionObjects)
        Set whether to *instantiate* and process the objects contained by indirection objects (e.g. a ValueHolder's value).
      • setShouldIterateOverWrappedObjects

        public void setShouldIterateOverWrappedObjects​(boolean shouldIterateOverWrappedObjects)
      • setShouldTrackCurrentGroup

        public void setShouldTrackCurrentGroup​(boolean shouldTrackCurrentGroup)
      • setVisitedObjects

        public void setVisitedObjects​(java.util.Map visitedObjects)
      • setVisitedStack

        protected void setVisitedStack​(java.util.Stack visitedStack)
      • shouldBreak

        public boolean shouldBreak()
      • shouldCascadeAllParts

        public boolean shouldCascadeAllParts()
      • shouldCascadeNoParts

        public boolean shouldCascadeNoParts()
      • shouldCascadePrivateParts

        public boolean shouldCascadePrivateParts()
      • shouldIterateOnAggregates

        public boolean shouldIterateOnAggregates()
        Return whether the aggregate reference objects themselves should be processed. (The objects referenced by the aggregate objects will be processed either way.)
      • shouldIterateOnFetchGroupAttributesOnly

        public boolean shouldIterateOnFetchGroupAttributesOnly()
        If true then if object has a FetchGroup then iterations not performed on mappings that are outside of the FetchGroup.
      • shouldIterateOnIndirectionObjects

        public boolean shouldIterateOnIndirectionObjects()
        Return whether the indirection objects themselves (e.g. the ValueHolders) should be processed.
      • shouldIterateOnPrimitives

        public boolean shouldIterateOnPrimitives()
        Return whether to process primitive reference objects (e.g. Strings, Dates, ints).
      • shouldIterateOverIndirectionObjects

        public boolean shouldIterateOverIndirectionObjects()
        Return whether to process the objects contained by indirection objects (e.g. a ValueHolder's value) - but *without* instantiating them.
        See Also:
        shouldIterateOverUninstantiatedIndirectionObjects()
      • shouldIterateOverUninstantiatedIndirectionObjects

        public boolean shouldIterateOverUninstantiatedIndirectionObjects()
        Return whether to *instantiate* and process the objects contained by indirection objects (e.g. a ValueHolder's value).
      • shouldIterateOverWrappedObjects

        public boolean shouldIterateOverWrappedObjects()
      • shouldTrackCurrentGroup

        public boolean shouldTrackCurrentGroup()
      • usesGroup

        public boolean usesGroup()
      • startIterationOn

        public void startIterationOn​(java.lang.Object sourceObject)
        This is the root method called to start the iteration.
      • startIterationOn

        public void startIterationOn​(java.lang.Object sourceObject,
                                     AttributeGroup group)