Module org.eclipse.persistence.core
Class IndirectionPolicy
java.lang.Object
org.eclipse.persistence.internal.indirection.IndirectionPolicy
- All Implemented Interfaces:
Serializable
,Cloneable
- Direct Known Subclasses:
BasicIndirectionPolicy
,NoIndirectionPolicy
,TransparentIndirectionPolicy
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
- See Also:
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
INTERNAL: Construct a new indirection policy. -
Method Summary
Modifier and TypeMethodDescriptionbackupCloneAttribute
(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) INTERNAL: Return a backup clone of the attribute.protected ReadObjectQuery
buildCascadeQuery
(MergeManager mergeManager) INTERNAL Return true if the refresh should refresh on this mapping or not.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.clone()
INTERNAL: Clones itself.abstract Object
cloneAttribute
(Object attributeValue, Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession, boolean buildDirectlyFromRow) INTERNAL: Return a clone of the attribute.extractPrimaryKeyForReferenceObject
(Object referenceObject, AbstractSession session) INTERNAL: Return the primary key for the reference object (i.e.abstract AbstractRecord
extractReferenceRow
(Object referenceObject) INTERNAL: Return the reference row for the reference object.abstract void
fixObjectReferences
(Object object, Map<Object, ObjectDescriptor> objectDescriptors, Map<Object, Object> processedObjects, ObjectLevelReadQuery query, DistributedSession session) INTERNAL: An object has been serialized from the server to the client.protected CollectionMapping
INTERNAL: Reduce casting clutter....protected ForeignReferenceMapping
INTERNAL: Reduce casting clutter....INTERNAL: Return the database mapping that uses the indirection policy.protected ObjectReferenceMapping
INTERNAL: Reduce casting clutter....abstract Object
getOriginalIndirectionObject
(Object unitOfWorkIndirectionObject, AbstractSession session) INTERNAL: Return the original indirection object for a unit of work indirection object.getOriginalIndirectionObjectForMerge
(Object unitOfWorkIndirectionObject, AbstractSession session) INTERNAL: Return the original indirection object for a unit of work indirection object.abstract Object
getOriginalValueHolder
(Object unitOfWorkIndirectionObject, AbstractSession session) INTERNAL: Return the original valueHolder object.abstract Object
getRealAttributeValueFromObject
(Object object, Object attribute) INTERNAL: Return the "real" attribute value, as opposed to any wrapper.protected AbstractTransformationMapping
INTERNAL: Reduce casting clutter....abstract Object
getValueFromRemoteValueHolder
(RemoteValueHolder<?> remoteValueHolder) INTERNAL: Extract and return the appropriate value from the specified remote value holder.void
INTERNAL: Initialize the indirection policy (Do nothing by default)void
instantiateObject
(Object object, Object attribute) INTERNAL: Trigger the instantiation of the value.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.boolean
INTERNAL:void
iterateOnAttributeValue
(DescriptorIterator iterator, Object attributeValue) INTERNAL: Iterate over the specified attribute value, heeding the settings in the iterator.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.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.abstract Object
INTERNAL: Return the null value of the appropriate attribute.abstract boolean
objectIsEasilyInstantiated
(Object object) INTERNAL: Return whether the specified object can be instantiated without database access.abstract boolean
objectIsInstantiated
(Object object) INTERNAL: Return whether the specified object is instantiated.boolean
objectIsInstantiatedOrChanged
(Object object) INTERNAL: Return whether the specified object is instantiated, or if it has changes.void
Reset the wrapper used to store the value.void
setMapping
(DatabaseMapping mapping) INTERNAL: set the database mapping that uses the indirection policy.void
setRealAttributeValueInObject
(Object target, Object attributeValue) INTERNAL: Set the value of the appropriate attribute of target to attributeValue.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 changesvoid
setSourceObject
(Object sourceObject, Object attributeValue) INTERNAL: set the source object into QueryBasedValueHolder.void
setUseLazyInstantiation
(Boolean useLazyInstantiation) ADVANCED: This method will only change the behavior of TransparentIndirectionPolicy.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.boolean
INTERNAL: Return whether the indirection policy actually uses indirection.boolean
INTERNAL: Return whether the indirection policy uses transparent indirection.validateAttributeOfInstantiatedObject
(Object attributeValue) INTERNAL: Verify that the value of the attribute within an instantiated object is of the appropriate type for the indirection policy.void
validateContainerPolicy
(IntegrityChecker checker) INTERNAL: Verify that the container policy is compatible with the indirection policy.void
validateDeclaredAttributeType
(Class<?> attributeType, IntegrityChecker checker) INTERNAL: Verify that attributeType is correct for the indirection policy.void
validateDeclaredAttributeTypeForCollection
(Class<?> attributeType, IntegrityChecker checker) INTERNAL: Verify that attributeType is an appropriate collection type for the indirection policy.void
validateGetMethodReturnType
(Class<?> returnType, IntegrityChecker checker) INTERNAL: Verify that getter returnType is correct for the indirection policy.void
validateGetMethodReturnTypeForCollection
(Class<?> returnType, IntegrityChecker checker) INTERNAL: Verify that getter returnType is an appropriate collection type for the indirection policy.void
validateSetMethodParameterType
(Class<?> parameterType, IntegrityChecker checker) INTERNAL: Verify that setter parameterType is correct for the indirection policy.void
validateSetMethodParameterTypeForCollection
(Class<?> parameterType, IntegrityChecker checker) INTERNAL: Verify that setter parameterType is an appropriate collection type for the indirection policy.abstract Object
valueFromBatchQuery
(ReadQuery batchQuery, AbstractRecord row, ObjectLevelReadQuery originalQuery, CacheKey parentCacheKey) INTERNAL: Return the value to be stored in the object's attribute.abstract Object
valueFromMethod
(Object object, AbstractRecord row, AbstractSession session) INTERNAL: Return the value to be stored in the object's attribute.abstract Object
valueFromQuery
(ReadQuery query, AbstractRecord row, Object sourceObject, AbstractSession session) INTERNAL: Return the value to be stored in the object's attribute.abstract Object
valueFromQuery
(ReadQuery query, AbstractRecord row, AbstractSession session) INTERNAL: Return the value to be stored in the object's attribute.abstract Object
valueFromRow
(Object object) INTERNAL: Return the value to be stored in the object's attribute.
-
Field Details
-
mapping
-
-
Constructor Details
-
IndirectionPolicy
protected IndirectionPolicy()INTERNAL: Construct a new indirection policy.
-
-
Method Details
-
backupCloneAttribute
public Object backupCloneAttribute(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) INTERNAL: Return a backup clone of the attribute. -
buildCascadeQuery
INTERNAL Return true if the refresh should refresh on this mapping or not. -
buildIndirectObject
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
INTERNAL: Clones itself. -
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
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
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<Object, ObjectDescriptor> objectDescriptors, Map<Object, Object> 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
INTERNAL: Reduce casting clutter.... -
getForeignReferenceMapping
INTERNAL: Reduce casting clutter.... -
getMapping
INTERNAL: Return the database mapping that uses the indirection policy. -
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
INTERNAL: Return the "real" attribute value, as opposed to any wrapper. This will trigger the wrapper to instantiate the value. -
instantiateObject
INTERNAL: Trigger the instantiation of the value. -
getTransformationMapping
INTERNAL: Reduce casting clutter.... -
getValueFromRemoteValueHolder
INTERNAL: Extract and return the appropriate value from the specified remote value holder. -
isAttributeValueFullyBuilt
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- See Also:
-
initialize
public void initialize()INTERNAL: Initialize the indirection policy (Do nothing by default) -
isWeavedObjectBasicIndirectionPolicy
public boolean isWeavedObjectBasicIndirectionPolicy()INTERNAL: -
iterateOnAttributeValue
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
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
INTERNAL: Return whether the specified object is instantiated. -
objectIsEasilyInstantiated
INTERNAL: Return whether the specified object can be instantiated without database access. -
objectIsInstantiatedOrChanged
INTERNAL: Return whether the specified object is instantiated, or if it has changes. -
setMapping
INTERNAL: set the database mapping that uses the indirection policy. -
setRealAttributeValueInObject
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 -
setSourceObject
INTERNAL: set the source object into QueryBasedValueHolder. Used only by transparent indirection. -
setUseLazyInstantiation
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
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
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
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
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
INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the query. -
valueFromRow
INTERNAL: Return the value to be stored in the object's attribute. This value is determined by the row.
-