public class ReferenceLinker extends Object
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.
Constructor and Description |
---|
ReferenceLinker() |
Modifier and Type | Method and Description |
---|---|
protected List<String> |
assembleLinkingPaths(Link link)
Returns a list of link paths based on provided link.
|
protected void |
cascadeLinkingAnnotations(DataObjectWrapper<?> wrapped,
Map<String,Set<String>> decomposedPaths,
Set<Object> linked)
Gets indexes that have been modified.
|
protected Map<String,Set<String>> |
decomposePropertyPaths(Set<String> changedPropertyPaths)
Returns decomposed property paths based on changedPropertyPaths
|
protected Map<String,Set<String>> |
decomposePropertyPaths(Set<String> changedPropertyPaths,
String prefix)
Returns decomposed property paths that start with the provide prefix
|
DataObjectService |
getDataObjectService()
Returns the DataObjectService used by this class
|
protected boolean |
isPrimaryKeyModified(DataObjectMetadata metadata,
Set<String> modifiedPropertyPaths)
Checks if primary key can be modified.
|
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.
|
void |
linkChanges(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 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.
|
protected void |
linkCollectionChanges(DataObjectWrapper<?> wrapped,
Map<String,Set<String>> decomposedPaths,
Set<Object> linked)
Link changes for collections on the given wrapped data object.
|
protected void |
linkRelationshipChanges(DataObjectWrapper<?> wrapped,
Map<String,Set<String>> decomposedPaths,
Set<Object> linked)
Link changes for relationships on the given wrapped data object.
|
void |
setDataObjectService(DataObjectService dataObjectService)
Specify the DataObjectService to be used during linking.
|
public ReferenceLinker()
public DataObjectService getDataObjectService()
public void setDataObjectService(DataObjectService dataObjectService)
The linker will use the DataObjectService to fetch relationships and query metadata.
dataObjectService
- the DataObjectService to injectpublic void linkChanges(Object rootObject, Set<String> changedPropertyPaths)
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.
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 algorithmprotected void linkChangesInternal(Object object, Map<String,Set<String>> changedPropertyPaths, Set<Object> linked)
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, see
decomposePropertyPaths(java.util.Set)
linked
- a set containing objects which have already been linked, used to prevent infinite recursion due to
circular referencesprotected void linkRelationshipChanges(DataObjectWrapper<?> wrapped, Map<String,Set<String>> decomposedPaths, Set<Object> linked)
wrapped
- the wrapped data objectdecomposedPaths
- the decomposed map of changed property pathslinked
- a set containing objects which have already been linkedprotected void linkCollectionChanges(DataObjectWrapper<?> wrapped, Map<String,Set<String>> decomposedPaths, Set<Object> linked)
wrapped
- the wrapped data objectdecomposedPaths
- the decomposed map of changed property pathslinked
- a set containing objects which have already been linkedprotected void linkBiDirectionalCollection(DataObjectWrapper<?> parentWrapper, DataObjectWrapper<?> elementWrapper, DataObjectCollection collectionMetadata)
collectionMetadata
- collectionelementWrapper
- elementparentWrapper
- parentprotected boolean isPrimaryKeyModified(DataObjectMetadata metadata, Set<String> modifiedPropertyPaths)
protected void cascadeLinkingAnnotations(DataObjectWrapper<?> wrapped, Map<String,Set<String>> decomposedPaths, Set<Object> linked)
Returns a list of cascade links in the field names that are also in the decomposed paths.
decomposedPaths
- contains field names to be used.linked
- wrapped
- used to get all field names.protected List<String> assembleLinkingPaths(Link link)
link
- used get paths from.protected Map<String,Set<String>> decomposePropertyPaths(Set<String> changedPropertyPaths)
changedPropertyPaths
- changes to property pathsprotected Map<String,Set<String>> decomposePropertyPaths(Set<String> changedPropertyPaths, String prefix)
changedPropertyPaths
- changes to property pathsprefix
- filter that paths must start withCopyright © 2005–2015 The Kuali Foundation. All rights reserved.