T
- the type of the data object to wrap.public abstract class DataObjectWrapperBase<T> extends Object implements DataObjectWrapper<T>
DataObjectWrapper
.Modifier | Constructor and Description |
---|---|
protected |
DataObjectWrapperBase(T dataObject,
DataObjectMetadata metadata,
DataObjectService dataObjectService,
ReferenceLinker referenceLinker)
Creates a data object wrapper.
|
Modifier and Type | Method and Description |
---|---|
boolean |
areAllPrimaryKeyAttributesPopulated()
Returns whether all fields in the primary key are populated with a non-null/non-blank value.
|
boolean |
areAnyPrimaryKeyAttributesPopulated()
Returns whether any fields in the primary key is populated with a non-null/non-blank value.
|
<Y> Y |
convertIfNecessary(Object value,
Class<Y> requiredType) |
<Y> Y |
convertIfNecessary(Object value,
Class<Y> requiredType,
Field field) |
<Y> Y |
convertIfNecessary(Object value,
Class<Y> requiredType,
org.springframework.core.MethodParameter methodParam) |
boolean |
equalsByPrimaryKey(T object)
Determines if the given data object is equal to the data object wrapped by this accessor based on primary key
values only.
|
protected void |
fetchRelationship(MetadataChild relationship,
boolean useForeignKeyAttribute,
boolean nullifyDanglingRelationship)
Fetches and populates the value for the relationship with the given name on the wrapped object.
|
void |
fetchRelationship(String relationshipName)
Fetches and populates the value for the relationship with the given name on the wrapped data object.
|
void |
fetchRelationship(String relationshipName,
boolean useForeignKeyAttribute,
boolean nullifyDanglingRelationship)
Fetches and populates the value for the relationship with the given name on the wrapped object.
|
protected void |
fetchRelationshipUsingAttributes(MetadataChild relationship,
boolean nullifyDanglingRelationship)
Fetches the relationship using the foreign key attributes.
|
protected void |
fetchRelationshipUsingIdentity(MetadataChild relationship,
boolean nullifyDanglingRelationship)
Fetches the relationship using the primary key attributes.
|
PropertyEditor |
findCustomEditor(Class<?> requiredType,
String propertyPath) |
int |
getAutoGrowCollectionLimit() |
Collection<MetadataChild> |
getChildrenMatchingOptions(MaterializeOption... options)
This method retrieves the
MetadataChild objects (DataObjectRelationship or
DataObjectCollection ) which match the given MaterializeOption options. |
org.springframework.core.convert.ConversionService |
getConversionService() |
Map<String,Object> |
getForeignKeyAttributeMap(String relationshipName)
Gets the map of child attribute names to the parent attribute values.
|
Object |
getForeignKeyAttributeValue(String relationshipName)
As
DataObjectWrapper.getForeignKeyValue(String) except only returns the value for the "attribute" foreign key value. |
Object |
getForeignKeyValue(String relationshipName)
Returns the value of the foreign key for the specified relationship on the wrapped data object, or null if the
wrapped object has no value for the requested foreign key.
|
DataObjectMetadata |
getMetadata()
Returns the metadata of the data object wrapped by this accessor.
|
Object |
getPrimaryKeyValue()
Returns the value of the primary key for the wrapped data object, or null if the wrapped object has no value for
it's primary key.
|
Map<String,Object> |
getPrimaryKeyValues()
Returns a map containing the values of the primary keys on this data object.
|
PropertyDescriptor |
getPropertyDescriptor(String propertyName) |
PropertyDescriptor[] |
getPropertyDescriptors() |
Class<?> |
getPropertyType(String propertyName) |
org.springframework.core.convert.TypeDescriptor |
getPropertyTypeDescriptor(String propertyName) |
Class<?> |
getPropertyTypeNullSafe(Class<?> objectType,
String propertyName)
Get property type for property name on object, this can be a nested property and method will
recursively use the metadata to find type.
|
Object |
getPropertyValue(String propertyName) |
Object |
getPropertyValueNullSafe(String propertyName)
Get the current value of the specified property, but suppresses any
NullValueInNestedPathException s that would be thrown if a null value is
encountered in a nested path and just returns null instead. |
List<String> |
getUnpopulatedPrimaryKeyAttributeNames()
Returns the list of field of the primary key which have a null or blank value.
|
Class<T> |
getWrappedClass()
Return the type of the wrapped data object.
|
T |
getWrappedInstance()
Returns the data object wrapped by this accessor.
|
boolean |
isAutoGrowNestedPaths() |
boolean |
isExtractOldValueForEditor() |
boolean |
isReadableProperty(String propertyName) |
boolean |
isWritableProperty(String propertyName) |
void |
linkChanges(Set<String> changedPropertyPaths)
Executes reference linking using the wrapped object as the root and the set of changed paths.
|
void |
linkForeignKeys(boolean onlyLinkReadOnly)
Links foreign key values on the wrapped data object and then recurses through all child relationships and
collections which are cascaded during persistence and does the same.
|
void |
linkForeignKeys(String relationshipName,
boolean onlyLinkReadOnly)
Links foreign keys non-recursively using the relationship with the given name on the wrapped data object.
|
protected void |
linkForeignKeysInternal(DataObjectWrapper<?> wrapped,
MetadataChild relationship,
Object relationshipValue,
boolean onlyLinkReadOnly)
Links foreign keys non-recursively using the relationship with the given name on the wrapped data object.
|
protected void |
linkForeignKeysInternal(Object object,
boolean onlyLinkReadOnly,
Set<Object> linked)
Links all foreign keys on the data object.
|
protected void |
linkForeignKeysInternalWrapped(DataObjectWrapper<?> wrapped,
boolean onlyLinkReadOnly,
Set<Object> linked)
Links all foreign keys on the wrapped data object.
|
void |
materializeReferencedObjects(MaterializeOption... options)
Fetches and populates referenced objects within the wrapped object.
|
void |
materializeReferencedObjectsToDepth(int maxDepth,
MaterializeOption... options)
Fetches and populates referenced objects within the wrapped object.
|
protected void |
populateInverseRelationship(MetadataChild relationship,
Object propertyValue)
Populates the property on the other side of the relationship.
|
void |
registerCustomEditor(Class<?> requiredType,
PropertyEditor propertyEditor) |
void |
registerCustomEditor(Class<?> requiredType,
String propertyPath,
PropertyEditor propertyEditor) |
void |
setAutoGrowCollectionLimit(int autoGrowCollectionLimit) |
void |
setAutoGrowNestedPaths(boolean autoGrowNestedPaths) |
void |
setConversionService(org.springframework.core.convert.ConversionService conversionService) |
void |
setExtractOldValueForEditor(boolean extractOldValueForEditor) |
void |
setPropertyValue(org.springframework.beans.PropertyValue pv) |
void |
setPropertyValue(String propertyName,
Object value) |
void |
setPropertyValues(Map<?,?> map) |
void |
setPropertyValues(org.springframework.beans.PropertyValues pvs) |
void |
setPropertyValues(org.springframework.beans.PropertyValues pvs,
boolean ignoreUnknown) |
void |
setPropertyValues(org.springframework.beans.PropertyValues pvs,
boolean ignoreUnknown,
boolean ignoreInvalid) |
protected DataObjectWrapperBase(T dataObject, DataObjectMetadata metadata, DataObjectService dataObjectService, ReferenceLinker referenceLinker)
dataObject
- the data object to wrap.metadata
- the metadata of the data object.dataObjectService
- the data object service to use.referenceLinker
- the reference linker implementation.public DataObjectMetadata getMetadata()
getMetadata
in interface DataObjectWrapper<T>
public T getWrappedInstance()
getWrappedInstance
in interface DataObjectWrapper<T>
getWrappedInstance
in interface org.springframework.beans.BeanWrapper
public Object getPropertyValueNullSafe(String propertyName) throws org.springframework.beans.BeansException
NullValueInNestedPathException
s that would be thrown if a null value is
encountered in a nested path and just returns null instead. This method is essentially a convenience method to
prevent calling code from having to wrap calls to PropertyAccessor.getPropertyValue(String)
with a try-catch block to
check for NullValueInNestedPathExceptions.getPropertyValueNullSafe
in interface DataObjectWrapper<T>
propertyName
- the name of the property to get the value of
(may be a nested path and/or an indexed/mapped property)org.springframework.beans.InvalidPropertyException
- if there is no such property or
if the property isn't readableorg.springframework.beans.PropertyAccessException
- if the property was valid but the
accessor method failedorg.springframework.beans.BeansException
public Class<T> getWrappedClass()
getWrappedClass
in interface DataObjectWrapper<T>
getWrappedClass
in interface org.springframework.beans.BeanWrapper
null
if no wrapped object has been setpublic PropertyDescriptor[] getPropertyDescriptors()
getPropertyDescriptors
in interface org.springframework.beans.BeanWrapper
public PropertyDescriptor getPropertyDescriptor(String propertyName) throws org.springframework.beans.InvalidPropertyException
getPropertyDescriptor
in interface org.springframework.beans.BeanWrapper
org.springframework.beans.InvalidPropertyException
public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths)
setAutoGrowNestedPaths
in interface org.springframework.beans.BeanWrapper
public boolean isAutoGrowNestedPaths()
isAutoGrowNestedPaths
in interface org.springframework.beans.BeanWrapper
public void setAutoGrowCollectionLimit(int autoGrowCollectionLimit)
setAutoGrowCollectionLimit
in interface org.springframework.beans.BeanWrapper
public int getAutoGrowCollectionLimit()
getAutoGrowCollectionLimit
in interface org.springframework.beans.BeanWrapper
public void setConversionService(org.springframework.core.convert.ConversionService conversionService)
setConversionService
in interface org.springframework.beans.ConfigurablePropertyAccessor
public org.springframework.core.convert.ConversionService getConversionService()
getConversionService
in interface org.springframework.beans.ConfigurablePropertyAccessor
public void setExtractOldValueForEditor(boolean extractOldValueForEditor)
setExtractOldValueForEditor
in interface org.springframework.beans.ConfigurablePropertyAccessor
public boolean isExtractOldValueForEditor()
isExtractOldValueForEditor
in interface org.springframework.beans.ConfigurablePropertyAccessor
public boolean isReadableProperty(String propertyName)
isReadableProperty
in interface org.springframework.beans.PropertyAccessor
public boolean isWritableProperty(String propertyName)
isWritableProperty
in interface org.springframework.beans.PropertyAccessor
public Class<?> getPropertyType(String propertyName) throws org.springframework.beans.BeansException
getPropertyType
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public org.springframework.core.convert.TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws org.springframework.beans.BeansException
getPropertyTypeDescriptor
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public Object getPropertyValue(String propertyName) throws org.springframework.beans.BeansException
getPropertyValue
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValue(String propertyName, Object value) throws org.springframework.beans.BeansException
setPropertyValue
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValue(org.springframework.beans.PropertyValue pv) throws org.springframework.beans.BeansException
setPropertyValue
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValues(Map<?,?> map) throws org.springframework.beans.BeansException
setPropertyValues
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValues(org.springframework.beans.PropertyValues pvs) throws org.springframework.beans.BeansException
setPropertyValues
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValues(org.springframework.beans.PropertyValues pvs, boolean ignoreUnknown) throws org.springframework.beans.BeansException
setPropertyValues
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void setPropertyValues(org.springframework.beans.PropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid) throws org.springframework.beans.BeansException
setPropertyValues
in interface org.springframework.beans.PropertyAccessor
org.springframework.beans.BeansException
public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor)
registerCustomEditor
in interface org.springframework.beans.PropertyEditorRegistry
public void registerCustomEditor(Class<?> requiredType, String propertyPath, PropertyEditor propertyEditor)
registerCustomEditor
in interface org.springframework.beans.PropertyEditorRegistry
public PropertyEditor findCustomEditor(Class<?> requiredType, String propertyPath)
findCustomEditor
in interface org.springframework.beans.PropertyEditorRegistry
public <Y> Y convertIfNecessary(Object value, Class<Y> requiredType) throws org.springframework.beans.TypeMismatchException
convertIfNecessary
in interface org.springframework.beans.TypeConverter
org.springframework.beans.TypeMismatchException
public <Y> Y convertIfNecessary(Object value, Class<Y> requiredType, org.springframework.core.MethodParameter methodParam) throws org.springframework.beans.TypeMismatchException
convertIfNecessary
in interface org.springframework.beans.TypeConverter
org.springframework.beans.TypeMismatchException
public <Y> Y convertIfNecessary(Object value, Class<Y> requiredType, Field field) throws org.springframework.beans.TypeMismatchException
convertIfNecessary
in interface org.springframework.beans.TypeConverter
org.springframework.beans.TypeMismatchException
public Map<String,Object> getPrimaryKeyValues()
getPrimaryKeyValues
in interface DataObjectWrapper<T>
public Object getPrimaryKeyValue()
If the primary key consists of multiple values, this method will return an instance of CompoundKey
,
otherwise the single primary key value will be returned. If the primary key consists of multiple values but
those values are only partially populated, this method will return null.
getPrimaryKeyValue
in interface DataObjectWrapper<T>
public boolean areAllPrimaryKeyAttributesPopulated()
areAllPrimaryKeyAttributesPopulated
in interface DataObjectWrapper<T>
public boolean areAnyPrimaryKeyAttributesPopulated()
areAnyPrimaryKeyAttributesPopulated
in interface DataObjectWrapper<T>
public List<String> getUnpopulatedPrimaryKeyAttributeNames()
getUnpopulatedPrimaryKeyAttributeNames
in interface DataObjectWrapper<T>
public boolean equalsByPrimaryKey(T object)
equalsByPrimaryKey
in interface DataObjectWrapper<T>
object
- the object to compare to the data object wrapped by this accessorpublic Object getForeignKeyValue(String relationshipName)
If the foreign key is a compound/composite and consists of multiple values, this method will return an
instance of CompoundKey
, otherwise the single foreign key value will be returned. If the foreign key is
compound/composite but
those values are only partially populated, this method will return null.
It is common that a data object may have more than one field or set of fields that constitute a specific foreign key for the specified relationship. In such cases there would be an attribute (or attributes) which represent the foreign key as well as the related object itself. For example, consider the following scenario:
public class One {
String twoId;
Two two;
}
In this case, twoId
is an attribute that serves as a foreign key to Two
, but the two
attribute would contain an internal twoId
attribute which is the primary key value for Two
and
represents the foreign key in this case.
In cases like above, the twoId
attribute on the One
class would take precedence unless it
contains a null value, in which case this method will attempt to extract a non-null foreign key value from the
related object.
getForeignKeyValue
in interface DataObjectWrapper<T>
relationshipName
- the name of the relationship on the wrapped data object for which to determine the
foreign key valuepublic Object getForeignKeyAttributeValue(String relationshipName)
DataObjectWrapper.getForeignKeyValue(String)
except only returns the value for the "attribute" foreign key value. If
the wrapped data object has no attribute foreign key for the given relationship, this method will return null.getForeignKeyAttributeValue
in interface DataObjectWrapper<T>
relationshipName
- the name of the relationship on the wrapped data object for which to determine the
foreign key valuepublic Map<String,Object> getForeignKeyAttributeMap(String relationshipName)
relationshipName
- the name of the relationship for which to get the map.public Class<?> getPropertyTypeNullSafe(Class<?> objectType, String propertyName)
getPropertyTypeNullSafe
in interface DataObjectWrapper<T>
objectType
- - Root object typepropertyName
- - Property namepublic void linkChanges(Set<String> changedPropertyPaths)
Executes reference linker as per the algorithm described on
ReferenceLinker
linkChanges
in interface DataObjectWrapper<T>
changedPropertyPaths
- the Set of changed property paths relative to the wrapped objectReferenceLinker.linkChanges(Object, java.util.Set)
public void linkForeignKeys(boolean onlyLinkReadOnly)
In this context, linking of foreign key values means that on data objects that have both a field (or fields) that represent a foreign key to a relationship as well as an actual reference object for that relationship, if that foreign key field(s) is read only, then it will copy the value of the primary key(s) on the reference object to the associated foreign key field(s).
If onlyLinkReadOnly is true, this method will only link values into foreign keys that are "read-only" according to the metadata of the data object. This is to avoid situations where the foreign key field itself is the "master" value for the key. In those situations you do not want a read-only reference object to obliterate or corrupt the master key.
linkForeignKeys
in interface DataObjectWrapper<T>
onlyLinkReadOnly
- indicates whether or not only read-only foreign keys should be linkedprotected void linkForeignKeysInternal(Object object, boolean onlyLinkReadOnly, Set<Object> linked)
object
- the object to link.onlyLinkReadOnly
- whether to only link read-only objects.linked
- the set of currently linked objects, used as a base case to exit out of recursion.protected void linkForeignKeysInternalWrapped(DataObjectWrapper<?> wrapped, boolean onlyLinkReadOnly, Set<Object> linked)
wrapped
- the wrapped object to link.onlyLinkReadOnly
- whether to only link read-only objects.linked
- the set of currently linked objects, used as a base case to exit out of recursion.public void fetchRelationship(String relationshipName)
This is done by identifying the current foreign key attribute value for the relationship using the algorithm
described on DataObjectWrapper.getForeignKeyAttributeValue(String)
and then loading the related object using that foreign
key value, updating the relationship value on the wrapped data object afterward.
If the foreign key value is null or the loading of the related object using the foreign key returns a null value, this method will set the relationship value to null.
This method is equivalent to invoking DataObjectWrapper.fetchRelationship(String, boolean, boolean)
passing "true" for
both useForeignKeyAttribute
and nullifyDanglingRelationship
.
fetchRelationship
in interface DataObjectWrapper<T>
relationshipName
- the name of the relationship on the wrapped data object to refreshpublic void fetchRelationship(String relationshipName, boolean useForeignKeyAttribute, boolean nullifyDanglingRelationship)
The value of useForeignKeyAttribute
will be used to determine whether the foreign key attribute is
used to fetch the relationship (if this parameter is "true"), or whether the primary key on the related object
itself will be used (if it is false). In the case that the primary key is used, once the relationship has been
fetched, the foreign key field value (if one exists) will also be updated to remain in sync with the
reference object.
If no related object is found when attempting to fetch by the key values, then the behavior of this method
will depend upon the value passed for nullifyDanglingRelationship
. If false, this method will not modify
the wrapped object. If true, then the related object will be set to null.
fetchRelationship
in interface DataObjectWrapper<T>
relationshipName
- the name of the relationship on the wrapped data object to refreshuseForeignKeyAttribute
- if true, use the foreign key attribute to fetch the relationship, otherwise use the
primary key value on the related objectnullifyDanglingRelationship
- if true and no relationship value is found for the given key then set the
related object to null, otherwise leave the existing object state aloneprotected void fetchRelationship(MetadataChild relationship, boolean useForeignKeyAttribute, boolean nullifyDanglingRelationship)
relationship
- the relationship on the wrapped data object to refreshuseForeignKeyAttribute
- whether to use the foreign key attribute to fetch the relationshipnullifyDanglingRelationship
- whether to set the related object to null if no relationship value is foundprotected void fetchRelationshipUsingAttributes(MetadataChild relationship, boolean nullifyDanglingRelationship)
relationship
- the relationship on the wrapped data object to refreshnullifyDanglingRelationship
- whether to set the related object to null if no relationship value is foundprotected void fetchRelationshipUsingIdentity(MetadataChild relationship, boolean nullifyDanglingRelationship)
relationship
- the relationship on the wrapped data object to refreshnullifyDanglingRelationship
- whether to set the related object to null if no relationship value is foundpublic void linkForeignKeys(String relationshipName, boolean onlyLinkReadOnly)
If onlyLinkReadOnly is true then it will only perform linking for foreign key fields that are "read-only" according to the metadata for the data object. This is to avoid situations where the foreign key field itself is the "master" value for the key. In those situations you do not want a read-only reference object to obliterate or corrupt the master key.
linkForeignKeys
in interface DataObjectWrapper<T>
relationshipName
- the name of the relationship on the wrapped data object for which to link foreign keys,
must not be a nested pathonlyLinkReadOnly
- indicates whether or not only read-only foreign keys should be linkedpublic void materializeReferencedObjects(MaterializeOption... options)
DataObjectWrapper.fetchRelationship(String)
for
details on how the relationships will be fetched.
By default, this method will go through and instantiate all lazy-loaded, non-persisted-with-parent reference
objects and collections on the master object. See MaterializeOption
for the available options.
This method does not recurse into child objects. For that, use the
DataObjectWrapper.materializeReferencedObjectsToDepth(int, MaterializeOption...)
method.materializeReferencedObjects
in interface DataObjectWrapper<T>
options
- An optional list of MaterializeOption
objects which may adjust the behavior of this method.DataObjectWrapper.fetchRelationship(String)
,
MaterializeOption
public void materializeReferencedObjectsToDepth(int maxDepth, MaterializeOption... options)
DataObjectWrapper.fetchRelationship(String)
for
details on how the relationships will be fetched.
By default, this method will go through and instantiate all lazy-loaded, non-persisted-with-parent reference
objects and collections on the master object. See MaterializeOption
for the available options.materializeReferencedObjectsToDepth
in interface DataObjectWrapper<T>
maxDepth
- The number of levels of child objects to refresh. A value of 1 will only materialize the child object
on the wrapped object.options
- An optional list of MaterializeOption
objects which may adjust the behavior of this method.DataObjectWrapper.fetchRelationship(String)
,
MaterializeOption
public Collection<MetadataChild> getChildrenMatchingOptions(MaterializeOption... options)
MetadataChild
objects (DataObjectRelationship
or
DataObjectCollection
) which match the given MaterializeOption
options.
It utilizes the known information in the DataObjectMetadata
and compares the flags there with the options
given.
If no options are given, this method will return all DataObjectRelationship
and
DataObjectCollection
objects which are not updatable (not MetadataChild.isSavedWithParent()
) and
are lazily loaded (MetadataChild.isLoadedDynamicallyUponUse()
).options
- An optional list of MaterializeOption
objects to alter the default behavior.MetadataChild
objects matching the given parameters.protected void linkForeignKeysInternal(DataObjectWrapper<?> wrapped, MetadataChild relationship, Object relationshipValue, boolean onlyLinkReadOnly)
wrapped
- the wrapped object to link.relationship
- the relationship on the wrapped data object for which to link foreign keys.relationshipValue
- the value of the relationship.onlyLinkReadOnly
- indicates whether or not only read-only foreign keys should be linked.protected void populateInverseRelationship(MetadataChild relationship, Object propertyValue)
relationship
- the relationship on the wrapped data object for which to populate the inverse relationship.propertyValue
- the value of the property.Copyright © 2005–2014 The Kuali Foundation. All rights reserved.