T
- public class ExistingEntityMergeTransformer<T> extends Object implements org.apache.commons.collections.Transformer
Modifier and Type | Field and Description |
---|---|
protected Map<Object,org.apache.commons.collections.Transformer> |
customMergeActions
Map fieldName (String) or value type (Class) to a
Transformer that accepts an Array of
{Parent existing entity, fieldName as String, new transient object for field} and returns the final Object.The mapper can also result in null (No transformer) in which case it implies to ignore any copy/merge actions. If the transformer throws a ContinueProcessingException then the calling code can assume that the transformer has decided to relenquish control
and let the caller deal with the data-type in a default way. |
protected Collection<String> |
fieldNamesToMerge
The values for field names mentioned in this Collection will be merged into the new Entity, i.e.
|
protected boolean |
ignoreNullsForPrimitiveTypes
If true and a field is a primitive type, it will prevent updating the resultant object from un-wanted null values from a partial input object.
|
protected Map<Class,List<String>> |
immutableFieldNames
The field name(s) [map of exact Type to identity fields for entity or related entity exact type], used to uniquely identify the looked up entity;
note these fields will also not be overridden during any merge process in default implementation.
|
protected boolean |
mergeFieldMode
If true, will merge the fields from the source (override in case of conflict) with the existing field values
else all the values for the entity will be afresh.
|
protected Collection<Class<?>> |
typesRequireDeepCopy
While copying from new Entity to existing one, if it matches any of the types here
it will scan the object recursively to dig out properties and sent back in the original persisted object if that already
exists.
|
Constructor and Description |
---|
ExistingEntityMergeTransformer() |
ExistingEntityMergeTransformer(ExistingEntityMergeTransformer t) |
Modifier and Type | Method and Description |
---|---|
protected <X> void |
copy(X storedEntity,
X lookedUpEntity,
Stack parents)
Copy from lookedUpEintity into storedEntity.
|
protected <X> boolean |
copySpecificTypes(X storedEntity,
X lookedUpEntity,
Stack parents)
Override and provide custom handling of Specific Types
|
static Class |
getClosestParent(Collection<Class> classes,
Class child)
Given a collection of classes, determine which is the closest parent of the provided class.
|
protected org.apache.commons.collections.Transformer |
getCustomMergeAction(String fieldName,
Class type)
Look for any Custom Merge actions defined.
|
Map<Object,org.apache.commons.collections.Transformer> |
getCustomMergeActions()
Map fieldName (String) or value type (Class) to a
Transformer that accepts an Array of {existing stored entity, new transient object} and
returns the final Object.The mapper can also result in null (No transformer) in which case it implies to ignore any copy/merge actions. |
Collection<String> |
getFieldNamesToMerge()
The values for field names mentioned in this Collection will be merged into the new Entity, i.e.
|
Map<Class,List<String>> |
getIdentityFieldNames()
Deprecated.
|
protected List<String> |
getIdFieldsForClass(Class c)
Deprecated.
|
Map<Class,List<String>> |
getImmutableFieldNames()
The field name(s) [map of exact Type to identity fields for entity or related entity exact type], used to uniquely identify the looked up entity;
note these fields will also not be overridden during any merge process in default implementation.
|
protected List<String> |
getImmutableFieldsForClass(Class c)
Get list of all fields for class that we do not want to override
|
Collection<Class<?>> |
getTypesRequireDeepCopy()
While copying from new Entity to existing one, if it matches any of the types here
it will scan the object recursively to dig out properties and sent back in the original persisted object if that already
exists.
|
boolean |
isIgnoreNullsForPrimitiveTypes()
If true and a field is a primitive type, it will prevent updating the resultant object from un-wanted null values from a partial input object.
|
boolean |
isMergeFieldMode()
If true, will merge the fields from the Excel (override in case of conflict) with the existing field values
else all the values for the entity will be afresh.
|
protected <X> boolean |
isMutable(X storedEntity,
X lookedUpEntity,
String fieldName)
To modify or not modify the field in storedEntity.
|
protected <X> boolean |
isMutablePrimitive(X storedEntity,
String fieldName,
Object value)
To modify or not modify a primitive field in storedEntity.
|
static boolean |
isValidOrPrimitiveFieldType(Class<?> type) |
protected T |
mergeFields(T storedEntity,
T lookedUpEntity)
Records from the new Source sheet maybe merged with existing values in store (current)
If mergeFieldMode is true, it will keep original values (where the looked-up one is null) and only override with the ones supplied by the looked-up one else except for the Identifier fields, other fields will all be overwritten. |
protected boolean |
requiredDeepCopy(Object value) |
void |
setCustomMergeActions(Map<Object,org.apache.commons.collections.Transformer> customMergeActions)
Map fieldName (String) or value type (Class) to a
Transformer that accepts an Array of {existing stored entity, new transient object} and
returns the final Object.The mapper can also result in null (No transformer) in which case it implies to ignore any copy/merge actions. |
void |
setFieldNamesToMerge(Collection<String> fieldNamesToMerge)
The values for field names mentioned in this Collection will be merged into the new Entity, i.e.
|
void |
setIdentityFieldNames(Map<Class,List<String>> identityFieldNames)
Deprecated.
|
void |
setIgnoreNullsForPrimitiveTypes(boolean ignoreNullsForPrimitiveTypes)
If true and a field is a primitive type, it will prevent updating the resultant object from un-wanted null values from a partial input object.
|
void |
setImmutableFieldNames(Map<Class,List<String>> immutableFieldNames)
The field name(s) [map of exact Type to identity fields for entity or related entity exact type], used to uniquely identify the looked up entity;
note these fields will also not be overridden during any merge process in default implementation.
|
void |
setMergeFieldMode(boolean mergeFieldMode)
If true, will merge the fields from the Excel (override in case of conflict) with the existing field values
else all the values for the entity will be afresh.
|
void |
setTypesRequireDeepCopy(Collection<Class<?>> typesRequireDeepCopy)
While copying from new Entity to existing one, if it matches any of the types here
it will scan the object recursively to dig out properties and sent back in the original persisted object if that already
exists.
|
Object |
transform(Object in) |
protected Object |
treatNewEntity(Object newObject,
Stack parents)
During the process of Merge/Copy if a new Object is being set it may need to be additionally treated.
Like persist on database etc before its set in the main Entity. |
protected boolean mergeFieldMode
protected boolean ignoreNullsForPrimitiveTypes
immutableFieldNames
,
isMutablePrimitive(Object, String, Object)
protected Collection<Class<?>> typesRequireDeepCopy
protected Collection<String> fieldNamesToMerge
mergeFieldMode
is false and we want to ensure certain fields are not overwritten by a new entity.<simple ClassName>.<fieldName>
protected Map<Class,List<String>> immutableFieldNames
protected Map<Object,org.apache.commons.collections.Transformer> customMergeActions
Transformer
that accepts an Array of
{Parent existing entity, fieldName as String, new transient object for field} and returns the final Object.ContinueProcessingException
then the calling code can assume that the transformer has decided to relenquish control
and let the caller deal with the data-type in a default way. This is to handle custom cases (specially for Collection
s where a certain type in the
collection may not agree to be being merged by the converter).public ExistingEntityMergeTransformer()
public ExistingEntityMergeTransformer(ExistingEntityMergeTransformer t)
public static boolean isValidOrPrimitiveFieldType(Class<?> type)
protected boolean requiredDeepCopy(Object value)
protected <X> boolean copySpecificTypes(X storedEntity, X lookedUpEntity, Stack parents) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
storedEntity
- lookedUpEntity
- parents
- as a Stack of parents; 0th being root entity and last being immediate parent. Parents are useful as we recurse down and need a reference to a parent entityIllegalAccessException
InvocationTargetException
NoSuchMethodException
protected Object treatNewEntity(Object newObject, Stack parents)
newObject
- as Object to be treated that is replacing a null value in the Existing entityparents
- as a Stack of parents; 0th being root entity and last being immediate parent. Parents are useful as we recurse down and need a reference to a parent entityprotected org.apache.commons.collections.Transformer getCustomMergeAction(String fieldName, Class type)
fieldName
- as StringoldValue
- as object, old value persisted (fetched from lookup)value
- as objectTransformer
that accepts an Array of {Parent existing entity, fieldName as String, new transient object for field} and returns the final Object.ContinueProcessingException
then the calling code can assume that the transformer has decided to relenquish control
and let the caller deal with the data-type in a default way. This is to handle custom cases (specially for Collection
s where a certain type in the
collection may not agree to be being merged by the converter).protected <X> void copy(X storedEntity, X lookedUpEntity, Stack parents) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
storedEntity
- as persisted/existing entitylookedUpEntity
- (fresh transient entity), that by intent is to be merged into storedEntityIllegalAccessException
InvocationTargetException
NoSuchMethodException
protected <X> boolean isMutable(X storedEntity, X lookedUpEntity, String fieldName)
storedEntity
- as persisted/existing entitylookedUpEntity
- as new entity that by intent is to be merged into storedEntityfieldName
- as Stringprotected <X> boolean isMutablePrimitive(X storedEntity, String fieldName, Object value)
requiredDeepCopy(Object)
.immutableFieldNames
.storedEntity
- as persisted/existing entityfieldName
- as StringcustomMergeActions
,
requiredDeepCopy(Object)
,
immutableFieldNames
ignoreNullsForPrimitiveTypes
if false, then it is mutable.protected T mergeFields(T storedEntity, T lookedUpEntity) throws Exception
storedEntity
- as TlookedUpEntity
- (fresh transient entity) as TException
public Object transform(Object in)
transform
in interface org.apache.commons.collections.Transformer
public static Class getClosestParent(Collection<Class> classes, Class child)
classes
- @Deprecated protected List<String> getIdFieldsForClass(Class c)
getImmutableFieldsForClass(Class)
protected List<String> getImmutableFieldsForClass(Class c)
c
- as Classpublic boolean isMergeFieldMode()
public void setMergeFieldMode(boolean mergeFieldMode)
@Deprecated public Map<Class,List<String>> getIdentityFieldNames()
getImmutableFieldNames()
@Deprecated public void setIdentityFieldNames(Map<Class,List<String>> identityFieldNames)
setImmutableFieldNames(Map)
public Map<Class,List<String>> getImmutableFieldNames()
public void setImmutableFieldNames(Map<Class,List<String>> immutableFieldNames)
public boolean isIgnoreNullsForPrimitiveTypes()
immutableFieldNames
,
isMutablePrimitive(Object, String, Object)
public void setIgnoreNullsForPrimitiveTypes(boolean ignoreNullsForPrimitiveTypes)
immutableFieldNames
,
isMutablePrimitive(Object, String, Object)
public Collection<Class<?>> getTypesRequireDeepCopy()
public void setTypesRequireDeepCopy(Collection<Class<?>> typesRequireDeepCopy)
public Collection<String> getFieldNamesToMerge()
mergeFieldMode
is false and we want to ensure certain fields are not overwritten by a new entity.<simple ClassName>.<fieldName>
public void setFieldNamesToMerge(Collection<String> fieldNamesToMerge)
mergeFieldMode
is false and we want to ensure certain fields are not overwritten by a new entity.<simple ClassName>.<fieldName>
public Map<Object,org.apache.commons.collections.Transformer> getCustomMergeActions()
Transformer
that accepts an Array of {existing stored entity, new transient object} and
returns the final Object.public void setCustomMergeActions(Map<Object,org.apache.commons.collections.Transformer> customMergeActions)
Transformer
that accepts an Array of {existing stored entity, new transient object} and
returns the final Object.Copyright © 2018. All rights reserved.