FileDocCategorySizeDatePackage
IndirectionPolicy.javaAPI DocGlassfish v2 API13020Tue May 22 16:54:36 BST 2007oracle.toplink.essentials.internal.indirection

IndirectionPolicy

public abstract class IndirectionPolicy extends Object implements Serializable, Cloneable

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

see
ForeignReferenceMapping
author
Mike Norman
since
TOPLink/Java 2.5

Fields Summary
protected DatabaseMapping
mapping
Constructors Summary
public IndirectionPolicy()
INTERNAL: Construct a new indirection policy.

        super();
    
Methods Summary
public java.lang.ObjectbackupCloneAttribute(java.lang.Object attributeValue, java.lang.Object clone, java.lang.Object backup, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork)
INTERNAL: Return a backup clone of the attribute.

        return this.getMapping().buildBackupCloneForPartObject(attributeValue, clone, backup, unitOfWork);
    
protected oracle.toplink.essentials.queryframework.ReadObjectQuerybuildCascadeQuery(oracle.toplink.essentials.internal.sessions.MergeManager mergeManager)
INTERNAL Return true if the refresh shoud refresh on this mapping or not.

        ReadObjectQuery cascadeQuery = new ReadObjectQuery();
        if (mergeManager.shouldCascadeAllParts()) {
            cascadeQuery.cascadeAllParts();
            cascadeQuery.refreshIdentityMapResult();
        }
        if (mergeManager.shouldCascadePrivateParts() && getForeignReferenceMapping().isPrivateOwned()) {
            cascadeQuery.cascadePrivateParts();
            cascadeQuery.refreshIdentityMapResult();
        }

        return cascadeQuery;
    
public java.lang.Objectclone()
INTERNAL: Clones itself.

        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new InternalError();
        }
    
public abstract java.lang.ObjectcloneAttribute(java.lang.Object attributeValue, java.lang.Object original, java.lang.Object clone, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, boolean buildDirectlyFromRow)
INTERNAL: Return a clone of the attribute.

param
builtDirectlyFromRow 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.

public java.util.VectorextractPrimaryKeyForReferenceObject(java.lang.Object referenceObject, oracle.toplink.essentials.internal.sessions.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.

        return this.getOneToOneMapping().extractPrimaryKeysFromRealReferenceObject(referenceObject, session);
    
public abstract oracle.toplink.essentials.internal.sessions.AbstractRecordextractReferenceRow(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.

protected oracle.toplink.essentials.mappings.CollectionMappinggetCollectionMapping()
INTERNAL: Reduce casting clutter....

        return (CollectionMapping)this.getMapping();
    
protected oracle.toplink.essentials.mappings.ForeignReferenceMappinggetForeignReferenceMapping()
INTERNAL: Reduce casting clutter....

        return (ForeignReferenceMapping)this.getMapping();
    
public oracle.toplink.essentials.mappings.DatabaseMappinggetMapping()
INTERNAL: Return the database mapping that uses the indirection policy.

        return mapping;
    
protected oracle.toplink.essentials.mappings.ObjectReferenceMappinggetOneToOneMapping()
INTERNAL: Reduce casting clutter....

        return (ObjectReferenceMapping)this.getMapping();
    
public abstract java.lang.ObjectgetOriginalIndirectionObject(java.lang.Object unitOfWorkIndirectionObject, oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Return the original indirection object for a unit of work indirection object.

public abstract java.lang.ObjectgetRealAttributeValueFromObject(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.

public static java.lang.ObjectgetValueFromProxy(java.lang.Object value)
INTERNAL: Given a proxy object, trigger the indirection and return the actual object represented by the proxy. For non-proxy indirection, this method will simply return the object.

        return value;
    
public voidinitialize()
INTERNAL: Initialize the indirection policy (Do nothing by default)

    
public voiditerateOnAttributeValue(oracle.toplink.essentials.internal.descriptors.DescriptorIterator iterator, java.lang.Object attributeValue)
INTERNAL: Iterate over the specified attribute value, heeding the settings in the iterator.

        if (attributeValue != null) {
            this.getMapping().iterateOnRealAttributeValue(iterator, attributeValue);
        }
    
public abstract java.lang.ObjectnullValueFromRow()
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.

public abstract booleanobjectIsInstantiated(java.lang.Object object)
INTERNAL: Return whether the specified object is instantiated.

public voidsetMapping(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: set the database mapping that uses the indirection policy.

        this.mapping = mapping;
    
public voidsetRealAttributeValueInObject(java.lang.Object target, java.lang.Object attributeValue)
INTERNAL: Set the value of the appropriate attribute of target to attributeValue. In this case, simply place the value inside the target.

        this.getMapping().setAttributeValueInObject(target, attributeValue);
    
public booleanusesIndirection()
INTERNAL: Return whether the indirection policy actually uses indirection. The default is true.

        return true;
    
public booleanusesTransparentIndirection()
INTERNAL: Return whether the indirection policy uses transparent indirection. The default is false.

        return false;
    
public java.lang.ObjectvalidateAttributeOfInstantiatedObject(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. If it is incorrect, throw an exception. If the value is null return a new indirection object to be used for the attribute.

        return attributeValue;
    
public voidvalidateContainerPolicy(oracle.toplink.essentials.exceptions.IntegrityChecker checker)
INTERNAL: Verify that the container policy is compatible with the indirection policy. If it is incorrect, add an exception to the integrity checker.

        // by default, do nothing
    
public voidvalidateDeclaredAttributeType(java.lang.Class attributeType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
INTERNAL: Verify that attributeType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.

        // by default, do nothing
    
public voidvalidateDeclaredAttributeTypeForCollection(java.lang.Class attributeType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
INTERNAL: Verify that attributeType is an appropriate collection type for the indirection policy. If it is incorrect, add an exception to the integrity checker.

        // by default, do nothing
    
public voidvalidateGetMethodReturnType(java.lang.Class returnType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
INTERNAL: Verify that getter returnType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.

        // by default, do nothing
    
public voidvalidateGetMethodReturnTypeForCollection(java.lang.Class returnType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
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.

        // by default, do nothing
    
public voidvalidateSetMethodParameterType(java.lang.Class parameterType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
INTERNAL: Verify that setter parameterType is correct for the indirection policy. If it is incorrect, add an exception to the integrity checker.

        // by default, do nothing
    
public voidvalidateSetMethodParameterTypeForCollection(java.lang.Class parameterType, oracle.toplink.essentials.exceptions.IntegrityChecker checker)
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.

        // by default, do nothing
    
public abstract java.lang.ObjectvalueFromQuery(oracle.toplink.essentials.queryframework.ReadQuery query, oracle.toplink.essentials.internal.sessions.AbstractRecord row, oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the query.

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