Class TransparentIndirectionPolicy

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public class TransparentIndirectionPolicy
    extends IndirectionPolicy

    Purpose

    : TransparentIndirectionPolicy implements the behavior necessary for a a CollectionMapping to use IndirectContainers to delay the reading of objects from the database until they are actually needed.
    Since:
    TOPLink/Java 2.5
    Author:
    Big Country
    See Also:
    CollectionMapping, IndirectContainer, Serialized Form
    • Field Detail

      • defaultContainerSize

        protected static java.lang.Integer defaultContainerSize
      • containerPolicy

        protected ContainerPolicy containerPolicy
        PERF: Cache the mappings container policy.
      • useLazyInstantiation

        protected java.lang.Boolean useLazyInstantiation
        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.
    • Constructor Detail

      • TransparentIndirectionPolicy

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

      • backupCloneAttribute

        public java.lang.Object backupCloneAttribute​(java.lang.Object attributeValue,
                                                     java.lang.Object clone,
                                                     java.lang.Object backup,
                                                     UnitOfWorkImpl unitOfWork)
        INTERNAL: Return a backup clone of the attribute.
        Overrides:
        backupCloneAttribute in class IndirectionPolicy
      • buildBackupClone

        protected java.lang.Object buildBackupClone​(IndirectContainer container)
        INTERNAL: Return a backup clone of a clone container that has not been read from the database yet. This is used by the indirection policy to hook together a UOW clone with its backup clone - only when the clone (the working copy returned to the user) instantiates its contents from the database will these contents be copied to the backup clone.
      • buildIndirectContainer

        protected IndirectContainer buildIndirectContainer()
        Construct and return an instance of the specified indirect container class.
      • buildIndirectContainer

        protected java.lang.Object buildIndirectContainer​(ValueHolderInterface valueHolder)
        Return a new IndirectContainer with the specified value holder.
      • buildIndirectObject

        public java.lang.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.
        Specified by:
        buildIndirectObject in class IndirectionPolicy
      • cloneAttribute

        public java.lang.Object cloneAttribute​(java.lang.Object attributeValue,
                                               java.lang.Object original,
                                               CacheKey cacheKey,
                                               java.lang.Object clone,
                                               java.lang.Integer refreshCascade,
                                               AbstractSession cloningSession,
                                               boolean buildDirectlyFromRow)
        Return a clone of the attribute.
        Specified by:
        cloneAttribute in class IndirectionPolicy
        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.
      • containerPolicyIsValid

        protected boolean containerPolicyIsValid()
        INTERNAL: Return whether the container policy is valid for the indirection policy. In this case, the container policy MUST be configured for an IndirectContainer.
      • extractPrimaryKeyForReferenceObject

        public java.lang.Object extractPrimaryKeyForReferenceObject​(java.lang.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. OneToOneMappings should not be using transparent direction.
        Overrides:
        extractPrimaryKeyForReferenceObject in class IndirectionPolicy
      • extractReferenceRow

        public AbstractRecord extractReferenceRow​(java.lang.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.
        Specified by:
        extractReferenceRow in class IndirectionPolicy
      • fixObjectReferences

        public void fixObjectReferences​(java.lang.Object object,
                                        java.util.Map objectDescriptors,
                                        java.util.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.
        Specified by:
        fixObjectReferences in class IndirectionPolicy
      • getContainerClass

        protected java.lang.Class getContainerClass()
        INTERNAL: Return the container class for the mapping.
      • getContainerPolicy

        protected ContainerPolicy getContainerPolicy()
        INTERNAL: Return the container policy for the mapping.
      • getDefaultContainerSize

        protected static int getDefaultContainerSize()
        INTERNAL: Return the the size to of container to create. Default to using default constructor.
      • getOriginalIndirectionObject

        public java.lang.Object getOriginalIndirectionObject​(java.lang.Object unitOfWorkIndirectionObject,
                                                             AbstractSession session)
        INTERNAL: Return the original indirection object for a unit of work indirection object.
        Specified by:
        getOriginalIndirectionObject in class IndirectionPolicy
      • getOriginalIndirectionObjectForMerge

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

        public java.lang.Object getOriginalValueHolder​(java.lang.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.
        Specified by:
        getOriginalValueHolder in class IndirectionPolicy
      • getRealAttributeValueFromObject

        public java.lang.Object getRealAttributeValueFromObject​(java.lang.Object object,
                                                                java.lang.Object attribute)
        INTERNAL: Return the "real" attribute value, as opposed to any wrapper. This will trigger the wrapper to instantiate the value.
        Specified by:
        getRealAttributeValueFromObject in class IndirectionPolicy
      • instantiateObject

        public void instantiateObject​(java.lang.Object object,
                                      java.lang.Object attribute)
        INTERNAL: Trigger the instantiation of the value.
        Overrides:
        instantiateObject in class IndirectionPolicy
      • isAttributeValueFullyBuilt

        public boolean isAttributeValueFullyBuilt​(java.lang.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
        Overrides:
        isAttributeValueFullyBuilt in class IndirectionPolicy
        Parameters:
        attributeValue -
        Returns:
        See Also:
        validateAttributeOfInstantiatedObject(java.lang.Object)
      • getUseLazyInstantiation

        public java.lang.Boolean getUseLazyInstantiation()
      • setRealAttributeValueInObject

        public void setRealAttributeValueInObject​(java.lang.Object target,
                                                  java.lang.Object attributeValue)
        INTERNAL: Set the value of the appropriate attribute of target to attributeValue. If the Target has yet to be instantiated then we need to instantiate the target to ensure that the backup clone is instantiated for comparison.
        Overrides:
        setRealAttributeValueInObject in class IndirectionPolicy
      • setSourceObject

        public void setSourceObject​(java.lang.Object sourceObject,
                                    java.lang.Object attributeValue)
        INTERNAL: set the source object into QueryBasedValueHolder.
        Overrides:
        setSourceObject in class IndirectionPolicy
      • setUseLazyInstantiation

        public void setUseLazyInstantiation​(java.lang.Boolean useLazyInstantiation)
        ADVANCED: 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.
        Overrides:
        setUseLazyInstantiation in class IndirectionPolicy
      • shouldUseLazyInstantiation

        public java.lang.Boolean shouldUseLazyInstantiation()
        ADVANCED: 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.
        Overrides:
        shouldUseLazyInstantiation in class IndirectionPolicy
      • mergeRemoteValueHolder

        public void mergeRemoteValueHolder​(java.lang.Object clientSideDomainObject,
                                           java.lang.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.
        Specified by:
        mergeRemoteValueHolder in class IndirectionPolicy
      • nullValueFromRow

        public java.lang.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. OneToOneMappings should not be using transparent direction.
        Specified by:
        nullValueFromRow in class IndirectionPolicy
      • objectIsInstantiated

        public boolean objectIsInstantiated​(java.lang.Object object)
        INTERNAL: Return whether the specified object is instantiated.
        Specified by:
        objectIsInstantiated in class IndirectionPolicy
      • objectIsEasilyInstantiated

        public boolean objectIsEasilyInstantiated​(java.lang.Object object)
        INTERNAL: Return whether the specified object can be instantiated without database access.
        Specified by:
        objectIsEasilyInstantiated in class IndirectionPolicy
      • objectIsInstantiatedOrChanged

        public boolean objectIsInstantiatedOrChanged​(java.lang.Object object)
        INTERNAL: Return whether the specified object is instantiated, or if it has changes.
        Overrides:
        objectIsInstantiatedOrChanged in class IndirectionPolicy
      • setDefaultContainerSize

        public static void setDefaultContainerSize​(int defaultSize)
        ADVANCED: Set the size to of container to create. Default to using default constructor.
      • typeIsValid

        protected boolean typeIsValid​(java.lang.Class declaredType)
        INTERNAL: Return whether the type is appropriate for the indirection policy. In this case, the attribute type MUST be compatible with the one specified by the ContainerPolicy (i.e. either the container policy class is a subclass of the declared type [jdk1.1] or the container policy class implements the declared interface [jdk1.2]).
      • usesTransparentIndirection

        public boolean usesTransparentIndirection()
        INTERNAL: Return whether the indirection policy uses transparent indirection.
        Overrides:
        usesTransparentIndirection in class IndirectionPolicy
      • validateAttributeOfInstantiatedObject

        public java.lang.Object validateAttributeOfInstantiatedObject​(java.lang.Object attributeValue)
        INTERNAL: Verify that the value of the attribute within an instantiated object is of the appropriate type for the indirection policy. In this case, the attribute must be non-null and it must be at least a subclass or implementor of the container type. If the value is null return a new indirection object to be used for the attribute.
        Overrides:
        validateAttributeOfInstantiatedObject in class IndirectionPolicy
      • validateGetMethodReturnType

        public void validateGetMethodReturnType​(java.lang.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. In this case, the attribute type MUST be compatible with the one specified by the ContainerPolicy.
        Overrides:
        validateGetMethodReturnType in class IndirectionPolicy
        Throws:
        DescriptorException
      • validateSetMethodParameterType

        public void validateSetMethodParameterType​(java.lang.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. In this case, the attribute type MUST be compatible with the one specified by the ContainerPolicy.
        Overrides:
        validateSetMethodParameterType in class IndirectionPolicy
        Throws:
        DescriptorException
      • validTypeName

        protected java.lang.String validTypeName()
        INTERNAL: Return the type that is appropriate for the indirection policy.
      • valueFromMethod

        public java.lang.Object valueFromMethod​(java.lang.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. TransformationMappings should not be using transparent direction.
        Specified by:
        valueFromMethod in class IndirectionPolicy
      • valueFromQuery

        public java.lang.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. In this case, wrap the query in an IndirectContainer for later invocation.
        Specified by:
        valueFromQuery in class IndirectionPolicy
      • valueFromQuery

        public java.lang.Object valueFromQuery​(ReadQuery query,
                                               AbstractRecord row,
                                               java.lang.Object object,
                                               AbstractSession session)
        INTERNAL: A combination of valueFromQuery and valueFromRow(object). Sometimes the attribute is known (joining) but we still need to hang on to the query (pessimistic locking).
        Specified by:
        valueFromQuery in class IndirectionPolicy
      • valueFromRow

        public java.lang.Object valueFromRow​(java.lang.Object object)
        INTERNAL: Return the value to be stored in the object's attribute. This allows wrapping of the real value, none is required for transparent.
        Specified by:
        valueFromRow in class IndirectionPolicy