Interface PersistenceContext
- All Known Implementing Classes:
DefaultPersistenceContext,StorageRequest
public interface PersistenceContext
Captures all parameters related to persistence of an item data.
While persisting a complex item with nested item(s), a context is created for each item being persisted.
-
Method Summary
Modifier and TypeMethodDescriptionIndicates locale, in which data must be returned in the response to the persistence request.default LocaleIndicates the language, in which localized attributes content is provided.Determines whether the payload item that can be retrieved bygetIntegrationItem()method has been persisted already in the course of the root persistent context processing and retrieves the persisted item from the context.Retrieves item data to be persisted.default StringReturns name of thePostPersistHookto be executed after saving this context data.default StringReturns name of thePrePersistHookto be executed before saving this context data.getReferencedContext(TypeAttributeDescriptor attribute) Retrieves the persistence context for an item referenced by the specified attributegetReferencedContexts(TypeAttributeDescriptor attribute) Retrieves the persistence contexts for the items referenced by the specified attributeRetrieves the top most persistence contextRetrieves the persistence context that the referenced context was gotten frombooleanDetermines whether a new item model can be created for the context payload.default booleanIndicates the persistence is to replace the item attributes with what's provided in theIntegrationItem.voidAdds the item model corresponding to the payload, i.e.Creates aItemSearchRequestfrom thisPersistenceContext
-
Method Details
-
getIntegrationItem
Retrieves item data to be persisted.- Returns:
- item data to be persisted into an
ItemModel.
-
getReferencedContext
Retrieves the persistence context for an item referenced by the specified attribute- Parameters:
attribute- specifies referenced item- Returns:
- the context containing information about the referenced item
-
getReferencedContexts
Retrieves the persistence contexts for the items referenced by the specified attribute- Parameters:
attribute- specifies referenced items- Returns:
- the context containing information about the referenced items
-
getSourceContext
Optional<PersistenceContext> getSourceContext()Retrieves the persistence context that the referenced context was gotten from- Returns:
- parent context, from which this context was retrieved. If this context is the root item context, Optional.empty is returned
-
getContextItem
Determines whether the payload item that can be retrieved bygetIntegrationItem()method has been persisted already in the course of the root persistent context processing and retrieves the persisted item from the context. This is the case when a nested item refers back to another item present earlier on the payload graph. For example, an Order contains OrderEntries and OrderEntry refers back to its container Order. The already persisted item match should be done by the item type and its key value. Only when those two characteristics match, the context item was already persisted and can be retrieved by this method.- Returns:
- an item, if this persistent context represents an already persisted payload item from higher levels of the root
item graph or an empty
Optional, if the item was not persisted yet. - See Also:
-
putItem
Adds the item model corresponding to the payload, i.e.getIntegrationItem(), into this context for being persisted. Every single payload item that is converted to anItemModelmust be put into this context explicitly. -
getRootContext
Retrieves the top most persistence context- Returns:
- the root context
-
toItemSearchRequest
Creates aItemSearchRequestfrom thisPersistenceContext- Returns:
- a newly constructed ItemSearchRequest
-
isReplaceAttributes
default boolean isReplaceAttributes()Indicates the persistence is to replace the item attributes with what's provided in theIntegrationItem. This is primarily applicable to collections. The default behavior is to append to the collection. With this method being true, the item's collection attribute will be replaced instead of appended.- Returns:
- true means to replace attributes, otherwise false.
-
isItemCanBeCreated
boolean isItemCanBeCreated()Determines whether a new item model can be created for the context payload.- Returns:
true, when new item can be create, if an item matching the context was not found in the persistent storage;false, if the context implies update only and therefore the item should not be created, if it does not exist yet.
-
getPrePersistHook
Returns name of thePrePersistHookto be executed before saving this context data.- Returns:
- name of the hook to execute or
null, if there is no need to execute a hook.
-
getPostPersistHook
Returns name of thePostPersistHookto be executed after saving this context data.- Returns:
- name of the hook to execute or
null, if there is no need to execute a hook.
-
getAcceptLocale
Indicates locale, in which data must be returned in the response to the persistence request.- Returns:
- locale to be used for localized attribute values in the response. The locale should be always explicitly specified in this context, so that clients would not need to duplicate logic for determining a default value to be used for returned data.
-
getContentLocale
Indicates the language, in which localized attributes content is provided.- Returns:
- content locale that must be always explicitly specified in this context, so that clients would not need to duplicate logic for determining a locale for the localized attributes in the payload.
-