public class DefaultModelService extends AbstractModelService
ModelService.AbstractService.SerializableDTO| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ENABLE_TRANSACTIONAL_SAVES |
tenant| Constructor and Description |
|---|
DefaultModelService() |
| 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
ModelService.enableTransactions() or ModelService.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 modelPkOrItem)
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.
|
protected void |
detachViaSource(PersistenceObject persistenceObject) |
void |
disableTransactions()
Disables transactions for save operation.
|
protected void |
doAttach(java.lang.Object model,
PersistenceObject source,
ModelConverter conv,
ModelContext ctx) |
protected <T> T |
doCreate(ModelConverter conv,
java.lang.String type) |
protected void |
doDetach(java.lang.Object model,
java.lang.Object source,
ModelConverter conv) |
protected <T> T |
doLoad(ModelConverter conv,
PersistenceObject source) |
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> 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 ages - Please use FlexibleSearchService.getModelByExample().
|
ConverterRegistry |
getConverterRegistry() |
InterceptorRegistry |
getInterceptorRegistry() |
ModelCloningContext |
getModelCloningContext() |
ModelCloningStrategy |
getModelCloningStrategy() |
ModelContext |
getModelContext() |
protected ModelConverter |
getModelConverterByModel(java.lang.Object model) |
protected ModelConverter |
getModelConverterBySource(PersistenceObject persistenceObject) |
protected java.lang.Object |
getModelForPersistentValue(java.lang.Object persistentValue) |
ModelSearchStrategy |
getModelSearchStrategy() |
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.
|
protected java.lang.Object |
getPersistentValueForModel(java.lang.Object model) |
SessionService |
getSessionService() |
<T> T |
getSource(java.lang.Object model)
Returns underlying source for given model.
|
protected java.lang.String |
getSourceTypeFromModel(java.lang.Object model) |
protected java.lang.String |
getSourceTypeFromSource(PersistenceObject persistenceObject) |
<T> T |
getWithLock(java.lang.Object source)
Default implementation delegates to
Transaction.lock(Item). |
WritePersistenceGateway |
getWritePersistenceGateway() |
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
|
protected boolean |
isHanaConstraintViolation(java.lang.Exception e) |
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) |
protected boolean |
isSpringConcurrencyException(java.lang.Exception e) |
protected boolean |
isSpringDuplicateKeyException(java.lang.Exception e) |
protected boolean |
isSQLServerConstraintViolation(java.lang.Exception e) |
boolean |
isUniqueConstraintErrorAsRooCause(java.lang.Exception e)
Deprecated.
since 6.1.0
|
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)
Default implementation delegates to
Transaction.lock(Item). |
void |
lock(PK itemPK)
Default implementation delegates to
Transaction.lock(Item). |
ConverterRegistry |
lookupConverterRegistry()
Must be overwritten! Use <lookup-method> in spring.
|
InterceptorRegistry |
lookupInterceptorRegistry()
Must be overwritten! Use <lookup-method> in spring.
|
ModelCloningContext |
lookupModelCloningContext()
Must be overwritten! Use <lookup-method> in spring.
|
ModelCloningStrategy |
lookupModelCloningStrategy()
Must be overwritten! Use <lookup-method> in spring.
|
ModelSearchStrategy |
lookupModelSearchStrategy()
Must be overwritten! Use <lookup-method> in spring.
|
SessionService |
lookupSessionService()
Must be overwritten! Use <lookup-method> in spring.
|
WritePersistenceGateway |
lookupWritePersistenceGateway()
Must be overwritten! Use <lookup-method> in spring.
|
protected void |
notifyLoadInterceptors(java.lang.Object model,
PersistenceObject source) |
boolean |
preloadItems(java.util.List<PK> pks) |
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.
|
void |
setCacheInvalidator(CacheInvalidator invalidator)
Deprecated.
|
void |
setCascader(Cascader cascader) |
void |
setChangeSetBuilder(ChangeSetBuilder builder) |
void |
setEventService(EventService eventService) |
void |
setModelContext(ModelContext modelContext) |
void |
setModelExtractor(ModelExtractor factory) |
void |
setModelPersister(ModelPersister modelPersister) |
void |
setPersistenceTypeService(PersistenceTypeService persistenceTypeService) |
void |
setSldDataContainerProvider(DefaultSLDDataContainerProvider sldDataContainerProvider) |
void |
setSourceTransformer(SourceTransformer sourceTransformer) |
void |
setTransactional(boolean transactional) |
void |
setTransactionTemplate(TransactionTemplate transactionTemplate) |
getAll, getAll, getAllSources, toModelLayer, toPersistenceLayerafterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, setTenantScope, writeReplacepublic static final java.lang.String ENABLE_TRANSACTIONAL_SAVES
public void attach(java.lang.Object model)
ModelServicemodel - the model instance to attachpublic void clearTransactionsSettings()
ModelServiceModelService.enableTransactions() or ModelService.disableTransactions()
methods which influences on save operations. After executing this method global setting for
transactions will be respected.public <T> T clone(T original)
ModelServicepublic <T> T clone(java.lang.Object original,
java.lang.Class<T> targetType)
ModelServicepublic <T> T clone(T original,
ModelCloningContext ctx)
ModelServiceModelCloningContext for details.public <T> T clone(java.lang.Object original,
java.lang.Class<T> targetType,
ModelCloningContext ctx)
ModelServiceModelCloningContext for details.public <T> T create(java.lang.Class modelClass)
ModelServicemodelClass - the model class to create a new instance ofpublic <T> T create(java.lang.String typeCode)
ModelServicetypeCode - type code whose registered model implementation will be used for instantiationpublic void detach(java.lang.Object modelPkOrItem)
ModelServiceModelService.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).modelPkOrItem - the model instance to detachpublic void detach(PK sourcePK)
ModelServiceModelService.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 detachedpublic void detachAll()
ModelServiceModelService.saveAll(). Also note that loading models for their sources again results in new
instances being attached to the context!public void disableTransactions()
ModelService
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 ModelService.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;
}
});
public void enableTransactions()
ModelService
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 ModelService.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;
}
});
public <T> T get(java.lang.Object source)
ModelServicesource - the object for which to retrieve a model instancepublic <T> T get(java.lang.Object source,
java.lang.String conversionType)
ModelServiceModelService.get(Object) - use with care!source - the persistent object to convertconversionType - the type to use when looking up the converterpublic <T> T get(PK sourcePK)
ModelServicesourcePK - the object pk for which to retrieve a model instancepublic <T> T getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier)
ModelServicemodel - the model instanceattributeQualifier - the attribute qualifierpublic <T> T getAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale locale)
ModelServicemodel - the model instanceattributeQualifier - the attribute qualifier for which value must be returnedlocale - the locale for which value must be returnedpublic <T> java.util.Map<java.util.Locale,T> getAttributeValues(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Locale... locales)
ModelServicemodel - 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)@Deprecated public <T> T getByExample(T example)
ModelServiceT - the type of the example and the return typeexample - the examplepublic java.lang.String getModelType(java.lang.Class modelClass)
ModelServicemodelClass - the model classpublic java.lang.String getModelType(java.lang.Object model)
ModelServicemodel - the model instancepublic java.lang.Class getModelTypeClass(java.lang.Class modelClass)
ModelServicemodelClass - a model classpublic <T> T getSource(java.lang.Object model)
ModelServicemodel - the model for which to return the sourcepublic void initDefaults(java.lang.Object model)
throws ModelInitializationException
ModelService
ModelService s = ...
// create plain instance - no defaults whatsoever
ProductModel myModel = new ProductModel();
// now load defaults
s.initDefaults( myModel );
ModelInitializationExceptionpublic boolean preloadItems(java.util.List<PK> pks)
public boolean isModified(java.lang.Object model)
ModelServicemodel - the model to checkpublic boolean isNew(java.lang.Object model)
ModelServicemodel - the model to checkpublic boolean isRemoved(java.lang.Object model)
ModelServicemodel - the model to checkpublic boolean isUpToDate(java.lang.Object model)
ModelServicemodel - the model to checkpublic void refresh(java.lang.Object model)
ModelServicemodel - model to be updatedpublic void remove(java.lang.Object model)
throws ModelRemovalException
ModelServicemodel - the model for which to remove the sourceModelRemovalException - if the remove action failedpublic void remove(PK pk) throws ModelRemovalException
ModelServicepk - the primary key of the source to removeModelRemovalException - if the remove action failedpublic void removeAll(java.util.Collection<? extends java.lang.Object> models)
throws ModelRemovalException
ModelServicemodels - the models for which to remove the sourceModelRemovalException - if the remove action failedpublic void removeAll(java.lang.Object... models)
throws ModelRemovalException
ModelServicemodels - the models for which to remove the sourceModelRemovalException - if the remove action failed@Deprecated public boolean isUniqueConstraintErrorAsRooCause(java.lang.Exception e)
ModelServicepublic boolean isUniqueConstraintErrorAsRootCause(java.lang.Exception e)
ModelServiceprotected boolean isSQLServerConstraintViolation(java.lang.Exception e)
protected boolean isHanaConstraintViolation(java.lang.Exception e)
protected boolean isSpringDuplicateKeyException(java.lang.Exception e)
protected boolean isSpringConcurrencyException(java.lang.Exception e)
public void save(java.lang.Object model)
ModelServicemodel - the model to saveModelService.saveAll(Collection)public void saveAll()
throws ModelSavingException
ModelServiceModelService.attach(Object)ModelSavingExceptionpublic void saveAll(java.util.Collection<? extends java.lang.Object> models)
throws ModelSavingException
ModelServicemodels - the model instances to saveModelSavingExceptionModelService.save(Object)public void saveAll(java.lang.Object... models)
throws ModelSavingException
ModelServicesaveAll in interface ModelServicesaveAll in class AbstractModelServicemodels - the model instances to saveModelSavingExceptionModelService.save(Object)public void setAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.lang.Object value)
ModelServicemodel - the modelattributeQualifier - the attribute qualifiervalue - the attribute valuepublic <T> void setAttributeValue(java.lang.Object model,
java.lang.String attributeQualifier,
java.util.Map<java.util.Locale,T> value)
ModelServicemodel - the model instanceattributeQualifier - the attribute qualifier for which value must be returnedvalue - map of values mapped to the corresponding Localepublic void setTransactionTemplate(TransactionTemplate transactionTemplate)
public void setModelContext(ModelContext modelContext)
public void setModelPersister(ModelPersister modelPersister)
public void setModelExtractor(ModelExtractor factory)
public void setChangeSetBuilder(ChangeSetBuilder builder)
@Deprecated public void setCacheInvalidator(CacheInvalidator invalidator)
public void setEventService(EventService eventService)
public void setTransactional(boolean transactional)
protected void detachViaSource(PersistenceObject persistenceObject)
protected void doAttach(java.lang.Object model,
PersistenceObject source,
ModelConverter conv,
ModelContext ctx)
protected <T> T doCreate(ModelConverter conv, java.lang.String type)
protected void doDetach(java.lang.Object model,
java.lang.Object source,
ModelConverter conv)
protected <T> T doLoad(ModelConverter conv, PersistenceObject source)
protected ModelConverter getModelConverterByModel(java.lang.Object model)
protected ModelConverter getModelConverterBySource(PersistenceObject persistenceObject)
protected java.lang.Object getModelForPersistentValue(java.lang.Object persistentValue)
getModelForPersistentValue in class AbstractModelServiceprotected java.lang.Object getPersistentValueForModel(java.lang.Object model)
getPersistentValueForModel in class AbstractModelServiceprotected java.lang.String getSourceTypeFromModel(java.lang.Object model)
protected java.lang.String getSourceTypeFromSource(PersistenceObject persistenceObject)
protected void notifyLoadInterceptors(java.lang.Object model,
PersistenceObject source)
public void lock(PK itemPK)
Transaction.lock(Item).itemPK - pk of the item to lock.public void lock(java.lang.Object source)
Transaction.lock(Item).source - item to lock.public <T> T getWithLock(java.lang.Object source)
Transaction.lock(Item).T - Type of returned model.source - item to lock.public boolean isAttached(java.lang.Object model)
ModelServicemodel - the model to checkpublic boolean isSourceAttached(java.lang.Object source)
public ConverterRegistry getConverterRegistry()
public InterceptorRegistry getInterceptorRegistry()
public ModelCloningContext getModelCloningContext()
public ModelCloningStrategy getModelCloningStrategy()
public ModelContext getModelContext()
public ModelSearchStrategy getModelSearchStrategy()
public SessionService getSessionService()
public WritePersistenceGateway getWritePersistenceGateway()
public ConverterRegistry lookupConverterRegistry()
public InterceptorRegistry lookupInterceptorRegistry()
public ModelCloningContext lookupModelCloningContext()
public ModelCloningStrategy lookupModelCloningStrategy()
public ModelSearchStrategy lookupModelSearchStrategy()
public SessionService lookupSessionService()
public WritePersistenceGateway lookupWritePersistenceGateway()
public void setPersistenceTypeService(PersistenceTypeService persistenceTypeService)
public void setCascader(Cascader cascader)
public void setSourceTransformer(SourceTransformer sourceTransformer)
public void setSldDataContainerProvider(DefaultSLDDataContainerProvider sldDataContainerProvider)
Copyright © 2018 SAP SE. All Rights Reserved.