Class DefaultModelService
- All Implemented Interfaces:
ModelService,Serializable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean
ModelService.- Since:
- 4.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
AbstractService.SerializableDTO -
Field Summary
FieldsFields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
tenant -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAttaches a model instance to the current model context.voidClears any local transactions settings set byModelService.enableTransactions()orModelService.disableTransactions()methods which influences onsaveoperations.<T> TCreates a deep copy of the given model except that the result object type may be changed here.<T> Tclone(Object original, Class<T> targetType, ModelCloningContext ctx) Creates a deep copy of the given model except that the result object type may be changed here.<T> Tclone(T original) Creates a deep copy of the given model.<T> Tclone(T original, ModelCloningContext ctx) Creates a deep copy of the given model.<T> TCreates a new empty model instance of those class which is registered for given type model.<T> TCreates a new empty model instance of those class which is registered for given type code.voidRemoves a model instance from the current model context.voidRemoves a model instance from the current model context.voidRemoves all model instances attached to the current model context.protected voiddetachViaSource(PersistenceObject persistenceObject) voidDisables transactions for save operation.protected voiddoAttach(Object model, PersistenceObject source, ModelConverter conv, ModelContext ctx) protected <T> TdoCreate(ModelConverter conv, String type) protected voiddoDetach(Object model, Object source, ModelConverter conv) protected <T> TdoLoad(ModelConverter conv, PersistenceObject source) voidEnables transactions for save operation.<T> TReturns a model instance for the source object the given pk represents.<T> TReturns a model instance for the given source object.<T> TSpecial loading method, which allows to specify the type for looking up the converter to be used.<T> TgetAttributeValue(Object model, String attributeQualifier) Generic attribute value getter to read attribute data from arbitrary model instances.<T> TgetAttributeValue(Object model, String attributeQualifier, Locale locale) Generic attribute value getter to read attribute data for given Locale from arbitrary model instances.getAttributeValues(Object model, String attributeQualifier, Locale... locales) Generic attribute value getter to read attribute data for given list of Locales from arbitrary model instances.<T> TgetByExample(T example) Deprecated, for removal: This API element is subject to removal in a future version.since ages - Please use FlexibleSearchService.getModelByExample().protected ModelConvertergetModelConverterByModel(Object model) protected ModelConvertergetModelConverterBySource(PersistenceObject persistenceObject) protected ObjectgetModelForPersistentValue(Object persistentValue) getModelType(Class modelClass) Returns the type mapped to a model class.getModelType(Object model) Returns the actual type of a given model instance.getModelTypeClass(Class modelClass) If the given class is a model class the mapped jalo class will be returned.protected ObjectgetPersistentValueForModel(Object model) <T> TReturns underlying source for given model.protected StringgetSourceTypeFromModel(Object model) protected StringgetSourceTypeFromSource(PersistenceObject persistenceObject) <T> TgetWithLock(Object source) Default implementation delegates toTransaction.lock(Item).voidinitDefaults(Object model) Initializes newly created model instance.booleanisAttached(Object model) Tells if the model is attached to the contextprotected booleanbooleanisModified(Object model) Tells if the model has been modified.booleanTells if the model has been created and has not been saved yet.booleanTells if the model has been removed.booleanisSourceAttached(Object source) protected booleanprotected booleanprotected booleanprotected booleanbooleanChecks whether the root cause of the given exception is the database rejecting a new item due to some unique key constraint violation.booleanisUpToDate(Object model) Checks if the given model represents the current persistent state of its source.voidDefault implementation delegates toTransaction.lock(Item).voidDefault implementation delegates toTransaction.lock(Item).Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.Must be overwritten! Use <lookup-method> in spring.protected voidnotifyLoadInterceptors(Object model, PersistenceObject source) booleanpreloadItems(List<PK> pks) Prepares objects to save.voidRequests the persistence layer to fetch a new, updated version of the passed model.voidTries to remove the source belonging to the specified PK.voidTries to remove the source (and all part-of elements) of the given model.voidTries to remove the source (and all part-of elements) of the given collection of models.voidremoveAll(Collection<? extends Object> models) Tries to remove the source (and all part-of elements) of the given collection of models.protected voidremoveAll(Collection<? extends Object> models, boolean transactional) voidSaves all attribute values from the model to the wrapped source object or creates a new one if no source is mapped yet.voidsaveAll()Saves all modified and new model instances which are attached to the current request context.voidSaves several model model instances at once.voidsaveAll(Collection<? extends Object> models) Saves several model model instances at once.protected voidsaveAll(Collection<? extends Object> models, boolean transactional) voidsetAttributeValue(Object model, String attributeQualifier, Object value) Generic attribute value setter to modify attribute data on arbitrary model instances.<T> voidsetAttributeValue(Object model, String attributeQualifier, Map<Locale, T> value) Generic attribute value setter to modify attribute data on arbitrary model instances for a given Locale.voidsetCacheInvalidator(CacheInvalidator invalidator) Deprecated, for removal: This API element is subject to removal in a future version.voidsetCascader(Cascader cascader) voidsetChangeSetBuilder(ChangeSetBuilder builder) voidsetEventService(EventService eventService) voidsetModelContext(ModelContext modelContext) voidsetModelExtractor(ModelExtractor factory) voidsetModelPersister(ModelPersister modelPersister) voidsetPersistenceTypeService(PersistenceTypeService persistenceTypeService) voidsetSldDataContainerProvider(DefaultSLDDataContainerProvider sldDataContainerProvider) voidsetSourceTransformer(SourceTransformer sourceTransformer) voidsetTransactional(boolean transactional) voidsetTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate) Methods inherited from class de.hybris.platform.servicelayer.internal.model.impl.AbstractModelService
getAll, getAll, getAllSources, toModelLayer, toPersistenceLayerMethods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
afterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, writeReplace
-
Field Details
-
ENABLE_TRANSACTIONAL_SAVES
- See Also:
-
-
Constructor Details
-
DefaultModelService
public DefaultModelService()
-
-
Method Details
-
attach
Description copied from interface:ModelServiceAttaches a model instance to the current model context. This is necessary for all models being created manually using their constructors. 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).- Parameters:
model- the model instance to attach
-
clearTransactionsSettings
public void clearTransactionsSettings()Description copied from interface:ModelServiceClears any local transactions settings set byModelService.enableTransactions()orModelService.disableTransactions()methods which influences onsaveoperations. After executing this method global setting for transactions will be respected. -
clone
public <T> T clone(T original) Description copied from interface:ModelServiceCreates a deep copy of the given model. The resulting object is not persisted yet in order to allow modifications like unique key adjustments etc. -
clone
Description copied from interface:ModelServiceCreates a deep copy of the given model except that the result object type may be changed here. Please note that only attributes that exist in both types are actually copied! The resulting object is not persisted yet in order to allow modifications like unique key adjustments etc. -
clone
Description copied from interface:ModelServiceCreates a deep copy of the given model. The resulting object is not persisted yet in order to allow modifications like unique key adjustments etc. The optional context allows to adjust the cloning process in some aspects. SeeModelCloningContextfor details. -
clone
Description copied from interface:ModelServiceCreates a deep copy of the given model except that the result object type may be changed here. Please note that only attributes that exist in both types are actually copied! The resulting object is not persisted yet in order to allow modifications like unique key adjustments etc. The optional context allows to adjust the cloning process in some aspects. SeeModelCloningContextfor details. -
create
Description copied from interface:ModelServiceCreates a new empty model instance of those class which is registered for given type model.- Parameters:
modelClass- the model class to create a new instance of- Returns:
- new empty model
-
create
Description copied from interface:ModelServiceCreates a new empty model instance of those class which is registered for given type code.- Parameters:
typeCode- type code whose registered model implementation will be used for instantiation- Returns:
- new empty model
-
detach
Description copied from interface:ModelServiceRemoves a model instance from the current model context. Afterward it will no longer be saved automatically viaModelService.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).- Parameters:
modelPkOrItem- the model instance to detach
-
detach
Description copied from interface:ModelServiceRemoves a model instance from the current model context. Afterward it will no longer be saved automatically viaModelService.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).- Parameters:
sourcePK- the source primary key belonging to the model to be detached
-
detachAll
public void detachAll()Description copied from interface:ModelServiceRemoves all model instances attached to the current model context. Afterward they will no longer be saved automatically viaModelService.saveAll(). Also note that loading models for their sources again results in new instances being attached to the context! -
disableTransactions
public void disableTransactions()Description copied from interface:ModelServiceDisables 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 usingModelService.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; } }); -
enableTransactions
public void enableTransactions()Description copied from interface:ModelServiceEnables 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 usingModelService.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; } }); -
get
Description copied from interface:ModelServiceReturns a model instance for the given source object. It is tried to find a target class using the type of the source object.- Parameters:
source- the object for which to retrieve a model instance- Returns:
- a model for the given source object
-
get
Description copied from interface:ModelServiceSpecial loading method, which allows to specify the type for looking up the converter to be used. Normally there is no need to prefer this toModelService.get(Object)- use with care!- Parameters:
source- the persistent object to convertconversionType- the type to use when looking up the converter
-
get
Description copied from interface:ModelServiceReturns a model instance for the source object the given pk represents. It is tried to find a target class using the type of the source object resolved from given PK.- Parameters:
sourcePK- the object pk for which to retrieve a model instance- Returns:
- a model for the given source object pk
-
getAttributeValue
Description copied from interface:ModelServiceGeneric attribute value getter to read attribute data from arbitrary model instances. If attribute is localized value for current Locale is returned.- Parameters:
model- the model instanceattributeQualifier- the attribute qualifier
-
getAttributeValue
Description copied from interface:ModelServiceGeneric attribute value getter to read attribute data for given Locale from arbitrary model instances.- Parameters:
model- the model instanceattributeQualifier- the attribute qualifier for which value must be returnedlocale- the locale for which value must be returned
-
getAttributeValues
public <T> Map<Locale,T> getAttributeValues(Object model, String attributeQualifier, Locale... locales) Description copied from interface:ModelServiceGeneric attribute value getter to read attribute data for given list of Locales from arbitrary model instances. This method returns immutable map of values mapped to the corresponding locale. If none of the values for a given locale can be found, an empty map will be returned.- Parameters:
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)- Returns:
- immutable map of values mapped to the corresponding Locale
-
getByExample
Deprecated, for removal: This API element is subject to removal in a future version.since ages - Please use FlexibleSearchService.getModelByExample().Description copied from interface:ModelServiceSearch for an existing object (in the database) by a given (not saved) example. Every modified attribute in this example is used as search parameter.- Type Parameters:
T- the type of the example and the return type- Parameters:
example- the example- Returns:
- the result if this was found by the example.
-
getModelType
Description copied from interface:ModelServiceReturns the type mapped to a model class.- Parameters:
modelClass- the model class
-
getModelType
Description copied from interface:ModelServiceReturns the actual type of a given model instance.- Parameters:
model- the model instance
-
getModelTypeClass
Description copied from interface:ModelServiceIf the given class is a model class the mapped jalo class will be returned. Otherwise the same class is returned.- Parameters:
modelClass- a model class- Returns:
- the mapped jalo class
-
getSource
Description copied from interface:ModelServiceReturns 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
-
initDefaults
Description copied from interface:ModelServiceInitializes newly created model instance.ModelService s = ... // create plain instance - no defaults whatsoever ProductModel myModel = new ProductModel(); // now load defaults s.initDefaults( myModel );- Throws:
ModelInitializationException
-
preloadItems
-
isModified
Description copied from interface:ModelServiceTells if the model has been modified. This applies to models which have been create or modified after loading.- Parameters:
model- the model to check
-
isNew
Description copied from interface:ModelServiceTells if the model has been created and has not been saved yet.- Parameters:
model- the model to check
-
isRemoved
Description copied from interface:ModelServiceTells if the model has been removed.- Parameters:
model- the model to check
-
isUpToDate
Description copied from interface:ModelServiceChecks if the given model represents the current persistent state of its source. It is considered to be up to date if- the model is not modified
- the model is not new
- a source exists for this model
- the persistence version of the source item is the same as stored inside the model
- Parameters:
model- the model to check
-
refresh
Description copied from interface:ModelServiceRequests the persistence layer to fetch a new, updated version of the passed model.- Parameters:
model- model to be updated
-
remove
Description copied from interface:ModelServiceTries to remove the source (and all part-of elements) of the given model.- Parameters:
model- the model for which to remove the source- Throws:
ModelRemovalException- if the remove action failed
-
remove
Description copied from interface:ModelServiceTries to remove the source belonging to the specified PK.- Parameters:
pk- the primary key of the source to remove- Throws:
ModelRemovalException- if the remove action failed
-
removeAll
Description copied from interface:ModelServiceTries to remove the source (and all part-of elements) of the given collection of models.- Parameters:
models- the models for which to remove the source- Throws:
ModelRemovalException- if the remove action failed
-
removeAll
Description copied from interface:ModelServiceTries to remove the source (and all part-of elements) of the given collection of models.- Parameters:
models- the models for which to remove the source- Throws:
ModelRemovalException- if the remove action failed
-
removeAll
-
isUniqueConstraintErrorAsRootCause
Description copied from interface:ModelServiceChecks whether the root cause of the given exception is the database rejecting a new item due to some unique key constraint violation. -
isSQLServerConstraintViolation
-
isHanaConstraintViolation
-
isSpringDuplicateKeyException
-
isSpringConcurrencyException
-
save
Description copied from interface:ModelServiceSaves 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- See Also:
-
saveAll
Description copied from interface:ModelServiceSaves all modified and new model instances which are attached to the current request context. A model becomes attached if- it has been loaded
- it has been created
- it has been attached explicitly via
ModelService.attach(Object)
- Throws:
ModelSavingException
-
saveAll
Description copied from interface:ModelServiceSaves several model model instances at once. If at least one instance causes a validation error no modifications are written.- Parameters:
models- the model instances to save- Throws:
ModelSavingException- See Also:
-
saveAll
Description copied from interface:ModelServiceSaves several model model instances at once. If at least one instance causes a validation error no modifications are written.- Specified by:
saveAllin interfaceModelService- Overrides:
saveAllin classAbstractModelService- Parameters:
models- the model instances to save- Throws:
ModelSavingException- See Also:
-
saveAll
-
prepareObjectsToSave
Prepares objects to save. -
setAttributeValue
Description copied from interface:ModelServiceGeneric attribute value setter to modify attribute data on arbitrary model instances.- Parameters:
model- the modelattributeQualifier- the attribute qualifiervalue- the attribute value
-
setAttributeValue
Description copied from interface:ModelServiceGeneric attribute value setter to modify attribute data on arbitrary model instances for a given Locale.- Parameters:
model- the model instanceattributeQualifier- the attribute qualifier for which value must be returnedvalue- map of values mapped to the corresponding Locale
-
setTransactionTemplate
public void setTransactionTemplate(org.springframework.transaction.support.TransactionTemplate transactionTemplate) -
setModelContext
-
setModelPersister
-
setModelExtractor
-
setChangeSetBuilder
-
setCacheInvalidator
@Deprecated(since="ages", forRemoval=true) public void setCacheInvalidator(CacheInvalidator invalidator) Deprecated, for removal: This API element is subject to removal in a future version. -
setEventService
-
setTransactional
public void setTransactional(boolean transactional) -
detachViaSource
-
doAttach
protected void doAttach(Object model, PersistenceObject source, ModelConverter conv, ModelContext ctx) -
doCreate
-
doDetach
-
doLoad
-
getModelConverterByModel
-
getModelConverterBySource
-
getModelForPersistentValue
- Specified by:
getModelForPersistentValuein classAbstractModelService
-
getPersistentValueForModel
- Specified by:
getPersistentValueForModelin classAbstractModelService
-
getSourceTypeFromModel
-
getSourceTypeFromSource
-
notifyLoadInterceptors
-
isTransactional
protected boolean isTransactional() -
lock
Default implementation delegates toTransaction.lock(Item).- Parameters:
itemPK- pk of the item to lock.
-
lock
Default implementation delegates toTransaction.lock(Item).- Parameters:
source- item to lock.
-
getWithLock
Default implementation delegates toTransaction.lock(Item).- Type Parameters:
T- Type of returned model.- Parameters:
source- item to lock.- Returns:
- locked model for given source.
-
isAttached
Description copied from interface:ModelServiceTells if the model is attached to the context- Parameters:
model- the model to check
-
isSourceAttached
-
getConverterRegistry
-
getInterceptorRegistry
-
getModelCloningContext
-
getModelCloningStrategy
-
getModelContext
-
getModelSearchStrategy
-
getSessionService
-
getWritePersistenceGateway
-
lookupConverterRegistry
Must be overwritten! Use <lookup-method> in spring. -
lookupInterceptorRegistry
Must be overwritten! Use <lookup-method> in spring. -
lookupModelCloningContext
Must be overwritten! Use <lookup-method> in spring. -
lookupModelCloningStrategy
Must be overwritten! Use <lookup-method> in spring. -
lookupModelSearchStrategy
Must be overwritten! Use <lookup-method> in spring. -
lookupSessionService
Must be overwritten! Use <lookup-method> in spring. -
lookupWritePersistenceGateway
Must be overwritten! Use <lookup-method> in spring. -
setPersistenceTypeService
-
setCascader
-
setSourceTransformer
-
setSldDataContainerProvider
-