public interface ModelService
| Modifier and Type | Method and Description |
|---|---|
void |
attach(java.lang.Object model)
Attaches a model instance to the current model context.
|
void |
clearTransactionsSettings()
Clears any local transactions settings set by
enableTransactions() or disableTransactions()
methods which influences on save operations. |
<T> T |
clone(java.lang.Object original,
java.lang.Class<T> targetType)
Creates a deep copy of the given model except that the result object type may be changed here.
|
<T> T |
clone(java.lang.Object original,
java.lang.Class<T> targetType,
ModelCloningContext ctx)
Creates a deep copy of the given model except that the result object type may be changed here.
|
<T> T |
clone(T original)
Creates a deep copy of the given model.
|
<T> T |
clone(T original,
ModelCloningContext ctx)
Creates a deep copy of the given model.
|
<T> T |
create(java.lang.Class modelClass)
Creates a new empty model instance of those class which is registered for given type model.
|
<T> T |
create(java.lang.String typeCode)
Creates a new empty model instance of those class which is registered for given type code.
|
void |
detach(java.lang.Object model)
Removes a model instance from the current model context.
|
void |
detach(PK sourcePK)
Removes a model instance from the current model context.
|
void |
detachAll()
Removes all model instances attached to the current model context.
|
void |
disableTransactions()
Disables transactions for save operation.
|
void |
enableTransactions()
Enables transactions for save operation.
|
<T> T |
get(java.lang.Object source)
Returns a model instance for the given source object.
|
<T> T |
get(java.lang.Object source,
java.lang.String conversionType)
Special loading method, which allows to specify the type for looking up the converter to be used.
|
<T> T |
get(PK sourcePK)
Returns a model instance for the source object the given pk represents.
|
<T extends java.util.Collection> |
getAll(java.util.Collection<? extends java.lang.Object> sources,
T result)
Convenience method to load all objects in a source collection and adding the loaded objects to a result
collection.
|
<T extends java.util.Collection> |
getAll(java.util.Collection<? extends java.lang.Object> sources,
T result,
java.lang.String conversionType)
Convenience method to load all objects in a source collection and adding the loaded objects to a result
collection.
|
<T extends java.util.Collection> |
getAllSources(java.util.Collection<? extends java.lang.Object> models,
T result)
Convenience method to load all the sources of a given collection of models
|
<T> T |
getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier)
Generic attribute value getter to read attribute data from arbitrary model instances.
|
<T> T |
getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale locale)
Generic attribute value getter to read attribute data for given Locale from arbitrary model instances.
|
<T> java.util.Map<java.util.Locale,T> |
getAttributeValues(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale... locales)
Generic attribute value getter to read attribute data for given list of Locales from arbitrary model instances.
|
<T> T |
getByExample(T example)
Deprecated.
since 6.1.0 - Please use
FlexibleSearchService.getModelByExample(Object). |
java.lang.String |
getModelType(java.lang.Class modelClass)
Returns the type mapped to a model class.
|
java.lang.String |
getModelType(java.lang.Object model)
Returns the actual type of a given model instance.
|
java.lang.Class |
getModelTypeClass(java.lang.Class modelClass)
If the given class is a model class the mapped jalo class will be returned.
|
<T> T |
getSource(java.lang.Object model)
Returns underlying source for given model.
|
<T> T |
getWithLock(java.lang.Object source)
Lock jalo item and wrap it into model.
|
void |
initDefaults(java.lang.Object model)
Initializes newly created model instance.
|
boolean |
isAttached(java.lang.Object model)
Tells if the model is attached to the context
|
boolean |
isModified(java.lang.Object model)
Tells if the model has been modified.
|
boolean |
isNew(java.lang.Object model)
Tells if the model has been created and has not been saved yet.
|
boolean |
isRemoved(java.lang.Object model)
Tells if the model has been removed.
|
boolean |
isSourceAttached(java.lang.Object source) |
boolean |
isUniqueConstraintErrorAsRootCause(java.lang.Exception e)
Checks whether the root cause of the given exception is the database rejecting a new item due to some unique key constraint violation.
|
boolean |
isUpToDate(java.lang.Object model)
Checks if the given model represents the current persistent state of its source.
|
void |
lock(java.lang.Object source)
Lock jalo item for changes.
|
void |
lock(PK itemPK)
Lock item with given PK in for changes.
|
void |
refresh(java.lang.Object model)
Requests the persistence layer to fetch a new, updated version of the passed model.
|
void |
remove(java.lang.Object model)
Tries to remove the source (and all part-of elements) of the given model.
|
void |
remove(PK pk)
Tries to remove the source belonging to the specified PK.
|
void |
removeAll(java.util.Collection<? extends java.lang.Object> models)
Tries to remove the source (and all part-of elements) of the given collection of models.
|
void |
removeAll(java.lang.Object... models)
Tries to remove the source (and all part-of elements) of the given collection of models.
|
void |
save(java.lang.Object model)
Saves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped
yet.
|
void |
saveAll()
Saves all modified and new model instances which are attached to the current request context.
|
void |
saveAll(java.util.Collection<? extends java.lang.Object> models)
Saves several model model instances at once.
|
void |
saveAll(java.lang.Object... models)
Saves several model model instances at once.
|
<T> void |
setAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Map<java.util.Locale,T> value)
Generic attribute value setter to modify attribute data on arbitrary model instances for a given Locale.
|
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.
|
<T> T |
toModelLayer(java.lang.Object persistentValue)
Converts arbitrary values into a representation to be used inside the model layer.
|
<T> T |
toPersistenceLayer(java.lang.Object modelValue)
Converts arbitrary model layer values into a form which may be used in persistence layer.
|
void attach(java.lang.Object model)
model - the model instance to attachjava.lang.IllegalStateException - if the current context already holds a model for the same source elementvoid detach(java.lang.Object model)
saveAll(). Please note that loading a model for its source again results in a new instance being attached
to the context! This context keeps track of all models being loaded, created or modified. There is a single
context per thread/request. Loading models for the same source element multiple times will return a single model
instance inside one context (thread/request).model - the model instance to detachvoid detach(PK sourcePK)
saveAll(). Please note that loading a model for its source again results in a new instance being attached
to the context! This context keeps track of all models being loaded, created or modified. There is a single
context per thread/request. Loading models for the same source element multiple times will return a single model
instance inside one context (thread/request).sourcePK - the source primary key belonging to the model to be detachedvoid detachAll()
saveAll(). Also note that loading models for their sources again results in new
instances being attached to the context!<T> T clone(T original)
<T> T clone(java.lang.Object original,
java.lang.Class<T> targetType)
<T> T clone(T original,
ModelCloningContext ctx)
ModelCloningContext for details.<T> T clone(java.lang.Object original,
java.lang.Class<T> targetType,
ModelCloningContext ctx)
ModelCloningContext for details.<T> T create(java.lang.Class modelClass)
modelClass - the model class to create a new instance of<T> T create(java.lang.String typeCode)
typeCode - type code whose registered model implementation will be used for instantiation<T> T get(java.lang.Object source)
source - the object for which to retrieve a model instance<T> T get(java.lang.Object source,
java.lang.String conversionType)
get(Object) - use with care!source - the persistent object to convertconversionType - the type to use when looking up the converter<T> T get(PK sourcePK)
sourcePK - the object pk for which to retrieve a model instance<T extends java.util.Collection> T getAll(java.util.Collection<? extends java.lang.Object> sources,
T result)
sources - the objects for which to retrieve model instancesresult - the collection to add the model instances toget(Object)<T extends java.util.Collection> T getAll(java.util.Collection<? extends java.lang.Object> sources,
T result,
java.lang.String conversionType)
sources - the objects for which to retrieve model instancesresult - the collection to add the model instances toconversionType - the type to be used for looking up the model converterget(Object)void refresh(java.lang.Object model)
model - model to be updatedvoid save(java.lang.Object model) throws ModelSavingException
model - the model to saveModelSavingException - if the save operation failedsaveAll(Collection)void saveAll(java.util.Collection<? extends java.lang.Object> models)
throws ModelSavingException
models - the model instances to saveModelSavingExceptionsave(Object)void saveAll(java.lang.Object... models)
throws ModelSavingException
models - the model instances to saveModelSavingExceptionsave(Object)void saveAll()
throws ModelSavingException
attach(Object)ModelSavingExceptionboolean isUniqueConstraintErrorAsRootCause(java.lang.Exception e)
void remove(java.lang.Object model)
throws ModelRemovalException
model - the model for which to remove the sourceModelRemovalException - if the remove action failedvoid removeAll(java.util.Collection<? extends java.lang.Object> models)
throws ModelRemovalException
models - the models for which to remove the sourceModelRemovalException - if the remove action failedvoid removeAll(java.lang.Object... models)
throws ModelRemovalException
models - the models for which to remove the sourceModelRemovalException - if the remove action failedvoid remove(PK pk) throws ModelRemovalException
pk - the primary key of the source to removeModelRemovalException - if the remove action failed<T> T getSource(java.lang.Object model)
model - the model for which to return the source<T extends java.util.Collection> T getAllSources(java.util.Collection<? extends java.lang.Object> models,
T result)
models - the objects for which to retrieve model instancesresult - the collection to add the model instances toModelValidationException - in case of a validation errorjava.lang.String getModelType(java.lang.Class modelClass)
modelClass - the model classjava.lang.Class getModelTypeClass(java.lang.Class modelClass)
modelClass - a model classjava.lang.String getModelType(java.lang.Object model)
model - the model instance<T> T toModelLayer(java.lang.Object persistentValue)
persistentValue - the value loaded from persistence layer.<T> T toPersistenceLayer(java.lang.Object modelValue)
modelValue - the value to be translated back into persistence layer formjava.lang.IllegalStateException - if models are found which do not have a persistence representation (yet) - be sure to save all models
before converting them!void initDefaults(java.lang.Object model)
throws ModelInitializationException
ModelService s = ...
// create plain instance - no defaults whatsoever
ProductModel myModel = new ProductModel();
// now load defaults
s.initDefaults( myModel );
model - ModelInitializationException<T> T getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier)
model - the model instanceattributeQualifier - the attribute qualifier<T> T getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale locale)
T - model - the model instanceattributeQualifier - the attribute qualifier for which value must be returnedlocale - the locale for which value must be returnedjava.lang.IllegalArgumentException - when value cannot be find for given localejava.lang.NullPointerException - when model, attributeQualifier or locale is null<T> java.util.Map<java.util.Locale,T> getAttributeValues(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale... locales)
T - model - the model instanceattributeQualifier - the attribute qualifier for which value must be returnedlocales - Locales for which value must be returned (at least one locale is required)java.lang.NullPointerException - when model, attributeQualifier or locale is nullvoid setAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.lang.Object value)
model - the modelattributeQualifier - the attribute qualifiervalue - the attribute valuejava.lang.NullPointerException - when model or attributeQualifier is null<T> void setAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Map<java.util.Locale,T> value)
model - the model instanceattributeQualifier - the attribute qualifier for which value must be returnedvalue - map of values mapped to the corresponding Localeboolean isUpToDate(java.lang.Object model)
model - the model to checkboolean isModified(java.lang.Object model)
model - the model to checkboolean isNew(java.lang.Object model)
model - the model to checkboolean isRemoved(java.lang.Object model)
model - the model to checkboolean isAttached(java.lang.Object model)
model - the model to checkboolean isSourceAttached(java.lang.Object source)
void enableTransactions()
Enables transactions for save operation. This setting overrides the global setting and has higher
priority. Enabling transactions is done via session (session key: "enableTransactionalSaves") so to make it
temporary please use
SessionService.executeInLocalView(de.hybris.platform.servicelayer.session.SessionExecutionBody)
. If you are not planning use local session, please remove completely session key "enableTransactionalSaves" from
the session to back to the global setting using clearTransactionsSettings() method.
Global setting is controlled by property: model.service.transactional.saves
Example usage:
sessionService.executeInLocalView(new SessionExecutionBody()
{
@Override
public Object execute()
{
modelService.enableTransactions();
modelService.save(someModel);
return someModel;
}
});
void disableTransactions()
Disables transactions for save operation. This setting overrides the global setting and has higher
priority. Disabling transactions is done via session (session key: "enableTransactionalSaves") so to make it
temporary please use
SessionService.executeInLocalView(de.hybris.platform.servicelayer.session.SessionExecutionBody)
. If you are not planning use local session, please remove completely session key "enableTransactionalSaves" from
the session to back to the global setting using clearTransactionsSettings() method.
Global setting is controlled by property: model.service.transactional.saves
Example usage:
sessionService.executeInLocalView(new SessionExecutionBody()
{
@Override
public Object execute()
{
modelService.disableTransactions();
modelService.save(someModel);
return someModel;
}
});
void clearTransactionsSettings()
enableTransactions() or disableTransactions()
methods which influences on save operations. After executing this method global setting for
transactions will be respected.@Deprecated <T> T getByExample(T example)
FlexibleSearchService.getModelByExample(Object).T - the type of the example and the return typeexample - the exampleModelNotFoundException - if nothing was foundAmbiguousIdentifierException - if by the given searchparams to many models where foundvoid lock(PK itemPK)
Calls to lock can only be made between calls to Transaction.begin() and
Transaction.commit() or Transaction.rollback(). All locks that are acquired during a transaction
are automatically released on calls to Transaction.commit() or Transaction.rollback(). If a lock
is held by another transaction, this method will block until the lock can be acquired.
itemPK - pk of the item to lock.void lock(java.lang.Object source)
Item.
Calls to lock can only be made between calls to Transaction.begin() and
Transaction.commit() or Transaction.rollback(). All locks that are acquired during a transaction
are automatically released on calls to Transaction.commit() or Transaction.rollback(). If a lock
is held by another transaction, this method will block until the lock can be acquired.
source - item to lock.<T> T getWithLock(java.lang.Object source)
Item.
Calls to lock can only be made between calls to Transaction.begin() and
Transaction.commit() or Transaction.rollback(). All locks that are acquired during a transaction
are automatically released on calls to Transaction.commit() or Transaction.rollback(). If a lock
is held by another transaction, this method will block until the lock can be acquired.
T - Type of returned model.source - item to lock.Copyright © 2018 SAP SE. All Rights Reserved.