Interface ModelConverter
-
- All Known Subinterfaces:
TypeSystemAwareModelConverter
,UpdateableModelConverter
- All Known Implementing Classes:
EnumValueModelConverter
,ItemModelConverter
,PrefetchAllModelConverter
,VariantProductModelConverter
public interface ModelConverter
AModelConverter
is responsible for creating and filling a model from an underlying persistence system like the hybris layer, a database, web service.- Since:
- 4.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
afterDetach(java.lang.Object model, ModelContext ctx)
This method is executed after the givenmodel
is attached from the givenModelContext
void
beforeAttach(java.lang.Object model, ModelContext ctx)
This method is executed before the givenmodel
is attached to the givenModelContext
java.lang.Object
create(java.lang.String type)
Creates a new empty model instance.boolean
exists(java.lang.Object model)
Returnstrue
if for the given model a source Item exists and if this item Item#isAlive()java.lang.Object
getAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)
Generic attribute value getter to read attribute data from arbitrary model instances.java.util.Map<java.lang.String,java.util.Set<java.util.Locale>>
getDirtyAttributes(java.lang.Object model)
Returns a map with all modified attribute qualifiers for the given model.java.lang.Object
getLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)
Generic attribute value getter to read attribute data from arbitrary model instances.java.util.Set<java.lang.String>
getPartOfAttributes(TypeService typeService)
Returns a collection of all partof atrributesPersistenceObject
getPersistenceSource(java.lang.Object model)
java.lang.Object
getSource(java.lang.Object model)
Deprecated.since 5.7.0java.lang.String
getType(java.lang.Object model)
Returns the exact type of the given model.java.util.Set<java.lang.String>
getWritablePartOfAttributes(TypeService typeService)
Returns a collection of writable partof atrributesvoid
init(ConverterRegistry registry)
Called once before using the converter the first time.boolean
isModified(java.lang.Object model)
Returnstrue
if the given model is new or the ModelValueHistory of the model contains changed attributes.boolean
isModified(java.lang.Object model, java.lang.String attribute)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.boolean
isModified(java.lang.Object model, java.lang.String attribute, java.util.Locale loc)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed.boolean
isNew(java.lang.Object model)
Returnstrue
if the given model was not persisted yet.boolean
isRemoved(java.lang.Object model)
Returnstrue
if for the given model no source Item exists or this item is not Item#isAlive()boolean
isUpToDate(java.lang.Object model)
The given model is not up-to-date (returnsfalse
) when: the model is new (seeisNew(Object)
) or the model was removed (seeisRemoved(Object)
) or the model was locally modified or the Item in the database is newer as the source item of the modeljava.lang.Object
load(java.lang.Object source)
Creates a new model instance and fills its attributes with data from given source objectvoid
reload(java.lang.Object model)
Fills the attributes of passed model new using mapped source object.void
remove(java.lang.Object model)
Tries to remove the source of the given model.void
save(java.lang.Object model, java.util.Collection<java.lang.String> exclude)
Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.void
setAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.lang.Object value)
Generic attribute value setter to modify attribute data on arbitrary model instances.
-
-
-
Method Detail
-
init
void init(ConverterRegistry registry)
Called once before using the converter the first time.- Parameters:
registry
- the registry holding this converter.
-
create
java.lang.Object create(java.lang.String type)
Creates a new empty model instance.- Returns:
- new empty model
-
getType
java.lang.String getType(java.lang.Object model)
Returns the exact type of the given model.
-
load
java.lang.Object load(java.lang.Object source)
Creates a new model instance and fills its attributes with data from given source object- Parameters:
source
- object which will be used for filling new model- Returns:
- new model instance with data of given source
-
reload
void reload(java.lang.Object model)
Fills the attributes of passed model new using mapped source object.- Parameters:
model
- model which will be filled from scratch using mapped source
-
remove
void remove(java.lang.Object model)
Tries to remove the source of the given model.- Parameters:
model
- the model for which to remove the source
-
save
void save(java.lang.Object model, java.util.Collection<java.lang.String> exclude)
Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.- Parameters:
model
- the model to save
-
getSource
@Deprecated java.lang.Object getSource(java.lang.Object model)
Deprecated.since 5.7.0Returns underlying source for given model.- Parameters:
model
- the model for which to return the source- Returns:
- the underlying source of the given model, or null if the source doesn't (yet) exist
-
isModified
boolean isModified(java.lang.Object model)
Returnstrue
if the given model is new or the ModelValueHistory of the model contains changed attributes.- Parameters:
model
- the model- Returns:
false
otherwise
-
isModified
boolean isModified(java.lang.Object model, java.lang.String attribute)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. If the attribute is localized the current session dataLocale
(see LocaleProvider#getCurrentDataLocale()) is used.- Parameters:
model
- the modelattribute
- the attribute qualifier- Returns:
false
if the attribute was not modified.
-
isModified
boolean isModified(java.lang.Object model, java.lang.String attribute, java.util.Locale loc)
Returnstrue
if the given model is new or the ModelValueHistory for the given attribute (qualifier) was changed. For localized attributes the givenLocale
is used to check for modifications. If the Locale isnull
then all Locales will be checked for modifications. For non-localized attributes the given Locale will be ignored.- Parameters:
model
- the modelattribute
- the attribute qualifierloc
- the Locale. Can benull
.- Returns:
false
otherwise.
-
exists
boolean exists(java.lang.Object model)
Returnstrue
if for the given model a source Item exists and if this item Item#isAlive()- Parameters:
model
- the model- Returns:
false
if the model was not persisted yet (no underlying item) or the item was removed.
-
isRemoved
boolean isRemoved(java.lang.Object model)
Returnstrue
if for the given model no source Item exists or this item is not Item#isAlive()- Parameters:
model
- the model- Returns:
false
if the modelisNew(Object)
or the item is alive.
-
isNew
boolean isNew(java.lang.Object model)
Returnstrue
if the given model was not persisted yet.- Parameters:
model
- the model- Returns:
false
if an AttributeProvider for the given model exists.
-
isUpToDate
boolean isUpToDate(java.lang.Object model)
The given model is not up-to-date (returnsfalse
) when:- the model is new (see
isNew(Object)
) or - the model was removed (see
isRemoved(Object)
) or - the model was locally modified or
- the Item in the database is newer as the source item of the model
- Parameters:
model
- the model- Returns:
true
if the model is up-to-date
- the model is new (see
-
getDirtyAttributes
java.util.Map<java.lang.String,java.util.Set<java.util.Locale>> getDirtyAttributes(java.lang.Object model)
Returns a map with all modified attribute qualifiers for the given model. The keys are all localized and non-localized attribute qualifier which were modified. If the map value isnull
the key is a non-localized attribute qualifier else the map value contains the locale in which language the localized attribute was modified.- Parameters:
model
- the new (not saved) model- Returns:
- a map with all modified attribute qualifier.
-
getAttributeValue
java.lang.Object getAttributeValue(java.lang.Object model, java.lang.String attributeQualifier)
Generic attribute value getter to read attribute data from arbitrary model instances.- Parameters:
model
- the model instanceattributeQualifier
- the attribute qualifier- Returns:
- the attribute value
-
getLocalizedAttributeValue
java.lang.Object getLocalizedAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.util.Locale locale)
Generic attribute value getter to read attribute data from arbitrary model instances.- Parameters:
model
- the model instanceattributeQualifier
- the attribute qualifierlocale
- Locale for which value will be returned- Returns:
- the attribute value
-
setAttributeValue
void setAttributeValue(java.lang.Object model, java.lang.String attributeQualifier, java.lang.Object value)
Generic attribute value setter to modify attribute data on arbitrary model instances.- Parameters:
model
- the modelattributeQualifier
- the attribute qualifiervalue
- the attribute value
-
beforeAttach
void beforeAttach(java.lang.Object model, ModelContext ctx)
This method is executed before the givenmodel
is attached to the givenModelContext
-
afterDetach
void afterDetach(java.lang.Object model, ModelContext ctx)
This method is executed after the givenmodel
is attached from the givenModelContext
-
getWritablePartOfAttributes
java.util.Set<java.lang.String> getWritablePartOfAttributes(TypeService typeService)
Returns a collection of writable partof atrributes
-
getPartOfAttributes
java.util.Set<java.lang.String> getPartOfAttributes(TypeService typeService)
Returns a collection of all partof atrributes
-
getPersistenceSource
PersistenceObject getPersistenceSource(java.lang.Object model)
-
-