Class IndirectionPolicy

  • All Implemented Interfaces:
    Serializable, Cloneable
    Direct Known Subclasses:
    BasicIndirectionPolicy, NoIndirectionPolicy, TransparentIndirectionPolicy

    public abstract class IndirectionPolicy
    extends Object
    implements Cloneable, Serializable

    Purpose

    : An IndirectionPolicy acts as a 'rules' holder that determines the behavior of a ForeignReferenceMapping (or TransformationMapping) with respect to indirection, or lack thereof.

    Description

    : IndirectionPolicy is an abstract class that defines the protocol to be implemented by subclasses so that the assorted DatabaseMappings can use an assortment of indirection policies:
    • no indirection policy (read everything from database)
    • basic indirection policy (use ValueHolders)
    • transparent indirection policy (collections only)
    • proxy indirection policy (transparent 1:1 indirection using JDK 1.3's Proxy)

    Responsibilities

    :
    • instantiate the various IndirectionPolicies

    Since:
    TOPLink/Java 2.5
    Author:
    Mike Norman
    See Also:
    ForeignReferenceMapping, Serialized Form
    • Constructor Detail

      • IndirectionPolicy

        public IndirectionPolicy()
        INTERNAL: Construct a new indirection policy.
    • Method Detail

      • backupCloneAttribute

        public Object backupCloneAttribute​(Object attributeValue,
                                           Object clone,
                                           Object backup,
                                           UnitOfWorkImpl unitOfWork)
        INTERNAL: Return a backup clone of the attribute.
      • buildCascadeQuery

        protected ReadObjectQuery buildCascadeQuery​(MergeManager mergeManager)
        INTERNAL Return true if the refresh should refresh on this mapping or not.
      • buildIndirectObject

        public abstract Object buildIndirectObject​(ValueHolderInterface valueHolder)
        INTERNAL: This method can be used when an Indirection Object is required to be built from a provided ValueHolderInterface object. This may be used for custom value holder types. Certain policies like the TransparentIndirectionPolicy may wrap the valueholder in another object.
      • clone

        public Object clone()
        INTERNAL: Clones itself.
        Overrides:
        clone in class Object
      • cloneAttribute

        public abstract Object cloneAttribute​(Object attributeValue,
                                              Object original,
                                              CacheKey cacheKey,
                                              Object clone,
                                              Integer refreshCascade,
                                              AbstractSession cloningSession,
                                              boolean buildDirectlyFromRow)
        INTERNAL: Return a clone of the attribute.
        Parameters:
        buildDirectlyFromRow - indicates that we are building the clone directly from a row as opposed to building the original from the row, putting it in the shared cache, and then cloning the original.
      • extractPrimaryKeyForReferenceObject

        public Object extractPrimaryKeyForReferenceObject​(Object referenceObject,
                                                          AbstractSession session)
        INTERNAL: Return the primary key for the reference object (i.e. the object object referenced by domainObject and specified by mapping). This key will be used by a RemoteValueHolder.
      • extractReferenceRow

        public abstract AbstractRecord extractReferenceRow​(Object referenceObject)
        INTERNAL: Return the reference row for the reference object. This allows the new row to be built without instantiating the reference object. Return null if the object has already been instantiated.
      • fixObjectReferences

        public abstract void fixObjectReferences​(Object object,
                                                 Map objectDescriptors,
                                                 Map processedObjects,
                                                 ObjectLevelReadQuery query,
                                                 DistributedSession session)
        INTERNAL: An object has been serialized from the server to the client. Replace the transient attributes of the remote value holders with client-side objects.
      • getCollectionMapping

        protected CollectionMapping getCollectionMapping()
        INTERNAL: Reduce casting clutter....
      • getForeignReferenceMapping

        protected ForeignReferenceMapping getForeignReferenceMapping()
        INTERNAL: Reduce casting clutter....
      • getMapping

        public DatabaseMapping getMapping()
        INTERNAL: Return the database mapping that uses the indirection policy.
      • getOneToOneMapping

        protected ObjectReferenceMapping getOneToOneMapping()
        INTERNAL: Reduce casting clutter....
      • getOriginalIndirectionObject

        public abstract Object getOriginalIndirectionObject​(Object unitOfWorkIndirectionObject,
                                                            AbstractSession session)
        INTERNAL: Return the original indirection object for a unit of work indirection object.
      • getOriginalIndirectionObjectForMerge

        public Object getOriginalIndirectionObjectForMerge​(Object unitOfWorkIndirectionObject,
                                                           AbstractSession session)
        INTERNAL: Return the original indirection object for a unit of work indirection object.
      • getOriginalValueHolder

        public abstract Object getOriginalValueHolder​(Object unitOfWorkIndirectionObject,
                                                      AbstractSession session)
        INTERNAL: Return the original valueHolder object. Access to the underlying valueholder may be required when serializing the valueholder or converting the valueHolder to another type.
      • getRealAttributeValueFromObject

        public abstract Object getRealAttributeValueFromObject​(Object object,
                                                               Object attribute)
        INTERNAL: Return the "real" attribute value, as opposed to any wrapper. This will trigger the wrapper to instantiate the value.
      • instantiateObject

        public void instantiateObject​(Object object,
                                      Object attribute)
        INTERNAL: Trigger the instantiation of the value.
      • getValueFromRemoteValueHolder

        public abstract Object getValueFromRemoteValueHolder​(RemoteValueHolder remoteValueHolder)
        INTERNAL: Extract and return the appropriate value from the specified remote value holder.
      • isAttributeValueFullyBuilt

        public boolean isAttributeValueFullyBuilt​(Object attributeValue)
        INTERNAL: The method validateAttributeOfInstantiatedObject(Object attributeValue) fixes the value of the attributeValue in cases where it is null and indirection requires that it contain some specific data structure. Return whether this will happen. This method is used to help determine if indirection has been triggered
        Parameters:
        attributeValue -
        Returns:
        See Also:
        validateAttributeOfInstantiatedObject(java.lang.Object)
      • initialize

        public void initialize()
        INTERNAL: Initialize the indirection policy (Do nothing by default)
      • isWeavedObjectBasicIndirectionPolicy

        public boolean isWeavedObjectBasicIndirectionPolicy()
        INTERNAL:
      • iterateOnAttributeValue

        public void iterateOnAttributeValue​(DescriptorIterator iterator,
                                            Object attributeValue)
        INTERNAL: Iterate over the specified attribute value, heeding the settings in the iterator.
      • mergeClientIntoServerValueHolder

        protected void mergeClientIntoServerValueHolder​(RemoteValueHolder serverValueHolder,
                                                        MergeManager mergeManager)
        INTERNAL Replace the client value holder with the server value holder, after copying some of the settings from the client value holder.
      • mergeRemoteValueHolder

        public abstract void mergeRemoteValueHolder​(Object clientSideDomainObject,
                                                    Object serverSideDomainObject,
                                                    MergeManager mergeManager)
        INTERNAL Replace the client value holder with the server value holder, after copying some of the settings from the client value holder.
      • nullValueFromRow

        public abstract Object nullValueFromRow()
        INTERNAL: Return the null value of the appropriate attribute. That is, the field from the database is NULL, return what should be placed in the object's attribute as a result.
      • objectIsInstantiated

        public abstract boolean objectIsInstantiated​(Object object)
        INTERNAL: Return whether the specified object is instantiated.
      • objectIsEasilyInstantiated

        public abstract boolean objectIsEasilyInstantiated​(Object object)
        INTERNAL: Return whether the specified object can be instantiated without database access.
      • objectIsInstantiatedOrChanged

        public boolean objectIsInstantiatedOrChanged​(Object object)
        INTERNAL: Return whether the specified object is instantiated, or if it has changes.
      • setMapping

        public void setMapping​(DatabaseMapping mapping)
        INTERNAL: set the database mapping that uses the indirection policy.
      • setRealAttributeValueInObject

        public void setRealAttributeValueInObject​(Object target,
                                                  Object attributeValue)
        INTERNAL: Set the value of the appropriate attribute of target to attributeValue. In this case, simply place the value inside the target.
      • setRealAttributeValueInObject

        public void setRealAttributeValueInObject​(Object target,
                                                  Object attributeValue,
                                                  boolean allowChangeTracking)
        INTERNAL: Same functionality as setRealAttributeValueInObject(Object target, Object attributeValue) but allows overridden behavior for IndirectionPolicies that track changes
        Parameters:
        target -
        attributeValue -
        allowChangeTracking -
      • setSourceObject

        public void setSourceObject​(Object sourceObject,
                                    Object attributeValue)
        INTERNAL: set the source object into QueryBasedValueHolder. Used only by transparent indirection.
      • setUseLazyInstantiation

        public void setUseLazyInstantiation​(Boolean useLazyInstantiation)
        ADVANCED: This method will only change the behavior of TransparentIndirectionPolicy. IndirectList and IndirectSet can be configured not to instantiate the list from the database when you add and remove from them. IndirectList defaults to this behavior. When Set to true, the collection associated with this TransparentIndirection will be setup so as not to instantiate for adds and removes. The weakness of this setting for an IndirectSet is that when the set is not instantiated, if a duplicate element is added, it will not be detected until commit time.
      • shouldUseLazyInstantiation

        public Boolean shouldUseLazyInstantiation()
        ADVANCED: Returns false unless this is a transparent indirection policy IndirectList and IndirectSet can be configured not to instantiate the list from the database when you add and remove from them. IndirectList defaults to this behavior. When Set to true, the collection associated with this TransparentIndirection will be setup so as not to instantiate for adds and removes. The weakness of this setting for an IndirectSet is that when the set is not instantiated, if a duplicate element is added, it will not be detected until commit time.
      • reset

        public void reset​(Object target)
        Reset the wrapper used to store the value. This is only required if a wrapper is used.
      • usesIndirection

        public boolean usesIndirection()
        INTERNAL: Return whether the indirection policy actually uses indirection. The default is true.
      • usesTransparentIndirection

        public boolean usesTransparentIndirection()
        INTERNAL: Return whether the indirection policy uses transparent indirection. The default is false.
      • validateAttributeOfInstantiatedObject

        public Object validateAttributeOfInstantiatedObject​(Object attributeValue)
                                                     throws DescriptorException
        INTERNAL: Verify that the value of the attribute within an instantiated object is of the appropriate type for the indirection policy. If it is incorrect, throw an exception. If the value is null return a new indirection object to be used for the attribute.
        Throws:
        DescriptorException
      • validateContainerPolicy

        public void validateContainerPolicy​(IntegrityChecker checker)
                                     throws DescriptorException
        INTERNAL: Verify that the container policy is compatible with the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateDeclaredAttributeType

        public void validateDeclaredAttributeType​(Class attributeType,
                                                  IntegrityChecker checker)
                                           throws DescriptorException
        INTERNAL: Verify that attributeType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateDeclaredAttributeTypeForCollection

        public void validateDeclaredAttributeTypeForCollection​(Class attributeType,
                                                               IntegrityChecker checker)
                                                        throws DescriptorException
        INTERNAL: Verify that attributeType is an appropriate collection type for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateGetMethodReturnType

        public void validateGetMethodReturnType​(Class returnType,
                                                IntegrityChecker checker)
                                         throws DescriptorException
        INTERNAL: Verify that getter returnType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateGetMethodReturnTypeForCollection

        public void validateGetMethodReturnTypeForCollection​(Class returnType,
                                                             IntegrityChecker checker)
                                                      throws DescriptorException
        INTERNAL: Verify that getter returnType is an appropriate collection type for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateSetMethodParameterType

        public void validateSetMethodParameterType​(Class parameterType,
                                                   IntegrityChecker checker)
                                            throws DescriptorException
        INTERNAL: Verify that setter parameterType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • validateSetMethodParameterTypeForCollection

        public void validateSetMethodParameterTypeForCollection​(Class parameterType,
                                                                IntegrityChecker checker)
                                                         throws DescriptorException
        INTERNAL: Verify that setter parameterType is an appropriate collection type for the indirection policy. If it is incorrect, add an exception to the integrity checker.
        Throws:
        DescriptorException
      • valueFromBatchQuery

        public abstract Object valueFromBatchQuery​(ReadQuery batchQuery,
                                                   AbstractRecord row,
                                                   ObjectLevelReadQuery originalQuery,
                                                   CacheKey parentCacheKey)
        INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the batchQuery.
      • valueFromMethod

        public abstract Object valueFromMethod​(Object object,
                                               AbstractRecord row,
                                               AbstractSession session)
        INTERNAL: Return the value to be stored in the object's attribute. This value is determined by invoking the appropriate method on the object and passing it the row and session.
      • valueFromQuery

        public abstract Object valueFromQuery​(ReadQuery query,
                                              AbstractRecord row,
                                              Object sourceObject,
                                              AbstractSession session)
        INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the query.
      • valueFromQuery

        public abstract Object valueFromQuery​(ReadQuery query,
                                              AbstractRecord row,
                                              AbstractSession session)
        INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the query.
      • valueFromRow

        public abstract Object valueFromRow​(Object object)
        INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the row.