Class IndirectionPolicy
- java.lang.Object
-
- org.eclipse.persistence.internal.indirection.IndirectionPolicy
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
- Direct Known Subclasses:
BasicIndirectionPolicy,NoIndirectionPolicy,TransparentIndirectionPolicy
public abstract class IndirectionPolicy extends java.lang.Object implements java.lang.Cloneable, java.io.SerializablePurpose
: 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
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseMappingmapping
-
Constructor Summary
Constructors Constructor Description IndirectionPolicy()INTERNAL: Construct a new indirection policy.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectbackupCloneAttribute(java.lang.Object attributeValue, java.lang.Object clone, java.lang.Object backup, UnitOfWorkImpl unitOfWork)INTERNAL: Return a backup clone of the attribute.protected ReadObjectQuerybuildCascadeQuery(MergeManager mergeManager)INTERNAL Return true if the refresh should refresh on this mapping or not.abstract java.lang.ObjectbuildIndirectObject(ValueHolderInterface valueHolder)INTERNAL: This method can be used when an Indirection Object is required to be built from a provided ValueHolderInterface object.java.lang.Objectclone()INTERNAL: Clones itself.abstract java.lang.ObjectcloneAttribute(java.lang.Object attributeValue, java.lang.Object original, CacheKey cacheKey, java.lang.Object clone, java.lang.Integer refreshCascade, AbstractSession cloningSession, boolean buildDirectlyFromRow)INTERNAL: Return a clone of the attribute.java.lang.ObjectextractPrimaryKeyForReferenceObject(java.lang.Object referenceObject, AbstractSession session)INTERNAL: Return the primary key for the reference object (i.e.abstract AbstractRecordextractReferenceRow(java.lang.Object referenceObject)INTERNAL: Return the reference row for the reference object.abstract voidfixObjectReferences(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.protected CollectionMappinggetCollectionMapping()INTERNAL: Reduce casting clutter....protected ForeignReferenceMappinggetForeignReferenceMapping()INTERNAL: Reduce casting clutter....DatabaseMappinggetMapping()INTERNAL: Return the database mapping that uses the indirection policy.protected ObjectReferenceMappinggetOneToOneMapping()INTERNAL: Reduce casting clutter....abstract java.lang.ObjectgetOriginalIndirectionObject(java.lang.Object unitOfWorkIndirectionObject, AbstractSession session)INTERNAL: Return the original indirection object for a unit of work indirection object.java.lang.ObjectgetOriginalIndirectionObjectForMerge(java.lang.Object unitOfWorkIndirectionObject, AbstractSession session)INTERNAL: Return the original indirection object for a unit of work indirection object.abstract java.lang.ObjectgetOriginalValueHolder(java.lang.Object unitOfWorkIndirectionObject, AbstractSession session)INTERNAL: Return the original valueHolder object.abstract java.lang.ObjectgetRealAttributeValueFromObject(java.lang.Object object, java.lang.Object attribute)INTERNAL: Return the "real" attribute value, as opposed to any wrapper.protected AbstractTransformationMappinggetTransformationMapping()INTERNAL: Reduce casting clutter....abstract java.lang.ObjectgetValueFromRemoteValueHolder(RemoteValueHolder remoteValueHolder)INTERNAL: Extract and return the appropriate value from the specified remote value holder.voidinitialize()INTERNAL: Initialize the indirection policy (Do nothing by default)voidinstantiateObject(java.lang.Object object, java.lang.Object attribute)INTERNAL: Trigger the instantiation of the value.booleanisAttributeValueFullyBuilt(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.booleanisWeavedObjectBasicIndirectionPolicy()INTERNAL:voiditerateOnAttributeValue(DescriptorIterator iterator, java.lang.Object attributeValue)INTERNAL: Iterate over the specified attribute value, heeding the settings in the iterator.protected voidmergeClientIntoServerValueHolder(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.abstract voidmergeRemoteValueHolder(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.abstract java.lang.ObjectnullValueFromRow()INTERNAL: Return the null value of the appropriate attribute.abstract booleanobjectIsEasilyInstantiated(java.lang.Object object)INTERNAL: Return whether the specified object can be instantiated without database access.abstract booleanobjectIsInstantiated(java.lang.Object object)INTERNAL: Return whether the specified object is instantiated.booleanobjectIsInstantiatedOrChanged(java.lang.Object object)INTERNAL: Return whether the specified object is instantiated, or if it has changes.voidreset(java.lang.Object target)Reset the wrapper used to store the value.voidsetMapping(DatabaseMapping mapping)INTERNAL: set the database mapping that uses the indirection policy.voidsetRealAttributeValueInObject(java.lang.Object target, java.lang.Object attributeValue)INTERNAL: Set the value of the appropriate attribute of target to attributeValue.voidsetRealAttributeValueInObject(java.lang.Object target, java.lang.Object attributeValue, boolean allowChangeTracking)INTERNAL: Same functionality as setRealAttributeValueInObject(Object target, Object attributeValue) but allows overridden behavior for IndirectionPolicies that track changesvoidsetSourceObject(java.lang.Object sourceObject, java.lang.Object attributeValue)INTERNAL: set the source object into QueryBasedValueHolder.voidsetUseLazyInstantiation(java.lang.Boolean useLazyInstantiation)ADVANCED: This method will only change the behavior of TransparentIndirectionPolicy.java.lang.BooleanshouldUseLazyInstantiation()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.booleanusesIndirection()INTERNAL: Return whether the indirection policy actually uses indirection.booleanusesTransparentIndirection()INTERNAL: Return whether the indirection policy uses transparent indirection.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.voidvalidateContainerPolicy(IntegrityChecker checker)INTERNAL: Verify that the container policy is compatible with the indirection policy.voidvalidateDeclaredAttributeType(java.lang.Class attributeType, IntegrityChecker checker)INTERNAL: Verify that attributeType is correct for the indirection policy.voidvalidateDeclaredAttributeTypeForCollection(java.lang.Class attributeType, IntegrityChecker checker)INTERNAL: Verify that attributeType is an appropriate collection type for the indirection policy.voidvalidateGetMethodReturnType(java.lang.Class returnType, IntegrityChecker checker)INTERNAL: Verify that getter returnType is correct for the indirection policy.voidvalidateGetMethodReturnTypeForCollection(java.lang.Class returnType, IntegrityChecker checker)INTERNAL: Verify that getter returnType is an appropriate collection type for the indirection policy.voidvalidateSetMethodParameterType(java.lang.Class parameterType, IntegrityChecker checker)INTERNAL: Verify that setter parameterType is correct for the indirection policy.voidvalidateSetMethodParameterTypeForCollection(java.lang.Class parameterType, IntegrityChecker checker)INTERNAL: Verify that setter parameterType is an appropriate collection type for the indirection policy.abstract java.lang.ObjectvalueFromBatchQuery(ReadQuery batchQuery, AbstractRecord row, ObjectLevelReadQuery originalQuery, CacheKey parentCacheKey)INTERNAL: Return the value to be stored in the object's attribute.abstract java.lang.ObjectvalueFromMethod(java.lang.Object object, AbstractRecord row, AbstractSession session)INTERNAL: Return the value to be stored in the object's attribute.abstract java.lang.ObjectvalueFromQuery(ReadQuery query, AbstractRecord row, java.lang.Object sourceObject, AbstractSession session)INTERNAL: Return the value to be stored in the object's attribute.abstract java.lang.ObjectvalueFromQuery(ReadQuery query, AbstractRecord row, AbstractSession session)INTERNAL: Return the value to be stored in the object's attribute.abstract java.lang.ObjectvalueFromRow(java.lang.Object object)INTERNAL: Return the value to be stored in the object's attribute.
-
-
-
Field Detail
-
mapping
protected DatabaseMapping mapping
-
-
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.
-
buildCascadeQuery
protected ReadObjectQuery buildCascadeQuery(MergeManager mergeManager)
INTERNAL Return true if the refresh should refresh on this mapping or not.
-
buildIndirectObject
public abstract 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.
-
clone
public java.lang.Object clone()
INTERNAL: Clones itself.- Overrides:
clonein classjava.lang.Object
-
cloneAttribute
public abstract 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)INTERNAL: Return a clone of the attribute.- Parameters:
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.
-
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.
-
extractReferenceRow
public abstract 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.
-
fixObjectReferences
public abstract 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.
-
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 java.lang.Object getOriginalIndirectionObject(java.lang.Object unitOfWorkIndirectionObject, AbstractSession session)INTERNAL: Return the original indirection object for a unit of work indirection object.
-
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.
-
getOriginalValueHolder
public abstract 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.
-
getRealAttributeValueFromObject
public abstract 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.
-
instantiateObject
public void instantiateObject(java.lang.Object object, java.lang.Object attribute)INTERNAL: Trigger the instantiation of the value.
-
getTransformationMapping
protected AbstractTransformationMapping getTransformationMapping()
INTERNAL: Reduce casting clutter....
-
getValueFromRemoteValueHolder
public abstract java.lang.Object getValueFromRemoteValueHolder(RemoteValueHolder remoteValueHolder)
INTERNAL: Extract and return the appropriate value from the specified remote value holder.
-
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- 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, java.lang.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(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.
-
nullValueFromRow
public abstract 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.
-
objectIsInstantiated
public abstract boolean objectIsInstantiated(java.lang.Object object)
INTERNAL: Return whether the specified object is instantiated.
-
objectIsEasilyInstantiated
public abstract boolean objectIsEasilyInstantiated(java.lang.Object object)
INTERNAL: Return whether the specified object can be instantiated without database access.
-
objectIsInstantiatedOrChanged
public boolean objectIsInstantiatedOrChanged(java.lang.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(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.
-
setRealAttributeValueInObject
public void setRealAttributeValueInObject(java.lang.Object target, java.lang.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(java.lang.Object sourceObject, java.lang.Object attributeValue)INTERNAL: set the source object into QueryBasedValueHolder. Used only by transparent indirection.
-
setUseLazyInstantiation
public void setUseLazyInstantiation(java.lang.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 java.lang.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(java.lang.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 java.lang.Object validateAttributeOfInstantiatedObject(java.lang.Object attributeValue) throws DescriptorExceptionINTERNAL: 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(java.lang.Class attributeType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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(java.lang.Class attributeType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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(java.lang.Class returnType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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(java.lang.Class returnType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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(java.lang.Class parameterType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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(java.lang.Class parameterType, IntegrityChecker checker) throws DescriptorExceptionINTERNAL: 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 java.lang.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 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.
-
valueFromQuery
public abstract java.lang.Object valueFromQuery(ReadQuery query, AbstractRecord row, java.lang.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 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.
-
valueFromRow
public abstract java.lang.Object valueFromRow(java.lang.Object object)
INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the row.
-
-