Class ReferenceLinker
This may include fetching relationships as keys are changed that would necessitate updating the object graph, and may also ensure that foreign key values are kept in sync in situations where a data object may have more than one field or object that stores the same foreign key.
This class has a single method linkChanges(Object, java.util.Set) which takes a data object and a list
of property paths for fields which have been modified. It then uses this information determine how to link up
relationships and foreign key fields, recursing through the object graph as needed.
Linking occurs from the bottom up, such that this class will attempt to perform a post-order traversal to visit the modified objects furthest from the root first, and then backtracking and linking back to the root. The linking algorithm handles circular references as well to ensure that the linking process terminates successfully.
The ReferenceLinker requires access to the DataObjectService so it must be injected using the
provided setDataObjectService(org.kuali.rice.krad.data.DataObjectService) method.
- Author:
- Kuali Rice Team (rice.collab@kuali.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassembleLinkingPaths(Link link) Returns a list of link paths based on provided link.protected voidcascadeLinkingAnnotations(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Gets indexes that have been modified.decomposePropertyPaths(Set<String> changedPropertyPaths) Returns decomposed property paths based on changedPropertyPathsdecomposePropertyPaths(Set<String> changedPropertyPaths, String prefix) Returns decomposed property paths that start with the provide prefixReturns the DataObjectService used by this classprotected booleanisPrimaryKeyModified(DataObjectMetadata metadata, Set<String> modifiedPropertyPaths) Checks if primary key can be modified.protected voidlinkBiDirectionalCollection(DataObjectWrapper<?> parentWrapper, DataObjectWrapper<?> elementWrapper, DataObjectCollection collectionMetadata) Performs bi-directional collection linking, ensuring that for bi-directional collection relationships that both sides of the relationship are properly populated.voidlinkChanges(Object rootObject, Set<String> changedPropertyPaths) Performs linking of references and keys for the given root object based on the given set of changed property paths that should be considered during the linking process.protected voidlinkChangesInternal(Object object, Map<String, Set<String>> changedPropertyPaths, Set<Object> linked) Internal implementation of link changes which is implemented to support recursion through the object graph.protected voidlinkCollectionChanges(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Link changes for collections on the given wrapped data object.protected voidlinkRelationshipChanges(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Link changes for relationships on the given wrapped data object.voidsetDataObjectService(DataObjectService dataObjectService) Specify the DataObjectService to be used during linking.
-
Constructor Details
-
ReferenceLinker
public ReferenceLinker()
-
-
Method Details
-
getDataObjectService
Returns the DataObjectService used by this class- Returns:
- the DataObjectService used by this class
-
setDataObjectService
Specify the DataObjectService to be used during linking.The linker will use the DataObjectService to fetch relationships and query metadata.
- Parameters:
dataObjectService- the DataObjectService to inject
-
linkChanges
Performs linking of references and keys for the given root object based on the given set of changed property paths that should be considered during the linking process.The root object should be non-null and also a valid data object (such that
DataObjectService.supports(Class)returns true for it). If neither of these conditions is true, this method will return immediately.See class-level documentation for specifics on how the linking algorithm functions.
- Parameters:
rootObject- the root object from which to perform the linkingchangedPropertyPaths- the set of property paths relative to the root object that should be considered modified by the linking algorithm
-
linkChangesInternal
protected void linkChangesInternal(Object object, Map<String, Set<String>> changedPropertyPaths, Set<Object> linked) Internal implementation of link changes which is implemented to support recursion through the object graph.- Parameters:
object- the object from which to linkchangedPropertyPaths- a decomposed property path map where the key of the map is a direct property path relative to the given object and the values are the remainder of the path relative to the parent path, seedecomposePropertyPaths(java.util.Set)linked- a set containing objects which have already been linked, used to prevent infinite recursion due to circular references
-
linkRelationshipChanges
protected void linkRelationshipChanges(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Link changes for relationships on the given wrapped data object.- Parameters:
wrapped- the wrapped data objectdecomposedPaths- the decomposed map of changed property pathslinked- a set containing objects which have already been linked
-
linkCollectionChanges
protected void linkCollectionChanges(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Link changes for collections on the given wrapped data object.- Parameters:
wrapped- the wrapped data objectdecomposedPaths- the decomposed map of changed property pathslinked- a set containing objects which have already been linked
-
linkBiDirectionalCollection
protected void linkBiDirectionalCollection(DataObjectWrapper<?> parentWrapper, DataObjectWrapper<?> elementWrapper, DataObjectCollection collectionMetadata) Performs bi-directional collection linking, ensuring that for bi-directional collection relationships that both sides of the relationship are properly populated.- Parameters:
parentWrapper- parentelementWrapper- elementcollectionMetadata- collection
-
isPrimaryKeyModified
protected boolean isPrimaryKeyModified(DataObjectMetadata metadata, Set<String> modifiedPropertyPaths) Checks if primary key can be modified.- Returns:
- whether primary key can be modified.
-
cascadeLinkingAnnotations
protected void cascadeLinkingAnnotations(DataObjectWrapper<?> wrapped, Map<String, Set<String>> decomposedPaths, Set<Object> linked) Gets indexes that have been modified.Returns a list of cascade links in the field names that are also in the decomposed paths.
- Parameters:
wrapped- used to get all field names.decomposedPaths- contains field names to be used.linked-
-
assembleLinkingPaths
Returns a list of link paths based on provided link.- Parameters:
link- used get paths from.- Returns:
- list of paths
-
decomposePropertyPaths
Returns decomposed property paths based on changedPropertyPaths- Parameters:
changedPropertyPaths- changes to property paths- Returns:
- map decomposed property paths with changedPropertyPaths
-
decomposePropertyPaths
protected Map<String,Set<String>> decomposePropertyPaths(Set<String> changedPropertyPaths, String prefix) Returns decomposed property paths that start with the provide prefix- Parameters:
changedPropertyPaths- changes to property pathsprefix- filter that paths must start with- Returns:
- map decomposed property paths with changedPropertyPaths
-