Class DataContextImpl
- All Implemented Interfaces:
DataContext,DataContextInternal
DataContext which commits data to DataManager.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classprotected classNested classes/interfaces inherited from interface io.jmix.flowui.model.DataContext
DataContext.ChangeEvent, DataContext.PostCommitEvent, DataContext.PreCommitEvent -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Function<SaveContext,Set<Object>> protected DataManagerprotected booleanprotected Map<Object,Map<String, DataContextImpl.EmbeddedPropertyChangeListener>> protected EntityReferencesNormalizerprotected EntityStatesprotected EntitySystemStateSupportprotected EventHubprotected Metadataprotected MetadataToolsprotected DataContextInternalprotected DataContextImpl.PropertyChangeListenerprotected StandardSerialization -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddChangeListener(Consumer<DataContext.ChangeEvent> listener) Adds a listener toDataContext.ChangeEvent.Adds a listener toDataContext.PostCommitEvent.Adds a listener toDataContext.PreCommitEvent.protected voidcleanupContextAfterRemoveEntity(DataContextInternal context, Object removedEntity) voidclear()Evicts all tracked entities.commit()Commits changed and removed instances to the middleware.booleanReturns true if the context contains the given entity (distinguished by its class and id).protected ObjectcopyEntity(Object srcEntity) protected voidcopySystemState(Object srcEntity, Object dstEntity) <T> TCreates an entity instance and merges it into the context.createObservableList(Object notifiedEntity) createObservableList(List<Object> list, Object notifiedEntity) createObservableSet(Object notifiedEntity) protected ObservableSet<Object>createObservableSet(Set<Object> set, Object notifiedEntity) protected booleanentityHasReference(Object entity, Object refEntity) voidRemoves the entity from the context so the context stops tracking it.voidClears the lists of created/modified/deleted entities and evicts these entities.protected ListfilterCommittedInstances(Set<Object> instances) <T> TReturns an entity instance by its class and id.<T> Tfind(T entity) Returns the instance of entity with the same id if it exists in this context.protected voidfireChangeListener(Object entity) getAll()Returns a function which will be used to commit data instead of standard implementation.Returns an immutable set of entities registered as modified.Returns a mutable set of entities registered as modified.Returns a parent context, if any.Returns an immutable set of entities registered for removal.booleanReturns true if the context has detected changes in the tracked entities.protected ObjectinternalMerge(Object entity, Map<Object, Object> mergedMap, boolean isRoot, MergeOptions options) booleanisModified(Object entity) Returns true if the context has detected changes in the given entity.booleanReturns true if the context has registered removal of the given entity.protected Objectmerge(Collection entities) Merge the given entities into the context.merge(Collection entities, MergeOptions options) Merge the given entities into the context.<T> Tmerge(T entity) Same asDataContext.merge(Object, MergeOptions)with default options.<T> Tmerge(T entity, MergeOptions options) Merge the given entity into the context.protected EntitySetmergeCommitted(Set<Object> committed) protected voidmergeLazyLoadingState(Object srcEntity, Object dstEntity) protected voidmergeList(List<Object> list, Object managedEntity, MetaProperty property, boolean replace, MergeOptions options, Map<Object, Object> mergedMap) protected voidmergeSet(Set<Object> set, Object managedEntity, MetaProperty property, boolean replace, MergeOptions options, Map<Object, Object> mergedMap) protected voidmergeState(Object srcEntity, Object dstEntity, Map<Object, Object> mergedMap, boolean isRoot, MergeOptions options) protected voidmergeSystemState(Object srcEntity, Object dstEntity, boolean isRoot, MergeOptions options) protected voidprotected StringprintEntity(Object entity, int level, Set<Object> visited) protected StringprintObject(Object object) voidRemoves the entity from the context and registers it as deleted.protected voidremoveFromCollections(Object entityToRemove) protected voidremoveListeners(Object entity) voidsetCommitDelegate(Function<SaveContext, Set<Object>> delegate) Sets a function which will be used to commit data instead of standard implementation.voidsetModified(Object entity, boolean modified) Registers or unregisters the given entity as modified.voidsetParent(DataContext parentContext) Sets the parent context.protected voidsetPropertyValue(Object entity, MetaProperty property, Object value) protected voidsetPropertyValue(Object entity, MetaProperty property, Object value, boolean checkEquals) protected Collection<Object>wrapLazyValueIntoObservableCollection(Collection<Object> collection, Object notifiedEntity)
-
Field Details
-
metadata
-
metadataTools
-
entityStates
-
dataManager
-
entitySystemStateSupport
-
entityReferencesNormalizer
-
standardSerialization
-
events
-
-
modifiedInstances
-
removedInstances
-
propertyChangeListener
-
disableListeners
protected boolean disableListeners -
parentContext
-
commitDelegate
-
embeddedPropertyListeners
protected Map<Object,Map<String, embeddedPropertyListenersDataContextImpl.EmbeddedPropertyChangeListener>> -
nullIdEntitiesMap
-
-
Constructor Details
-
DataContextImpl
public DataContextImpl()
-
-
Method Details
-
getParent
Description copied from interface:DataContextReturns a parent context, if any. If the parent context is set,DataContext.commit()method merges the changed instances to it instead of sending to the middleware.- Specified by:
getParentin interfaceDataContext
-
setParent
Description copied from interface:DataContextSets the parent context. If the parent context is set,DataContext.commit()method merges the changed instances to it instead of sending to the middleware.- Specified by:
setParentin interfaceDataContext
-
addChangeListener
Description copied from interface:DataContextAdds a listener toDataContext.ChangeEvent.- Specified by:
addChangeListenerin interfaceDataContext
-
fireChangeListener
-
find
Description copied from interface:DataContextReturns an entity instance by its class and id.- Specified by:
findin interfaceDataContext- Returns:
- entity instance or null if there is no such entity in the context
-
find
@Nullable public <T> T find(T entity) Description copied from interface:DataContextReturns the instance of entity with the same id if it exists in this context.- Specified by:
findin interfaceDataContext- Returns:
- entity instance or null if there is no such entity in the context
-
contains
Description copied from interface:DataContextReturns true if the context contains the given entity (distinguished by its class and id).- Specified by:
containsin interfaceDataContext
-
merge
Description copied from interface:DataContextMerge the given entity into the context. The whole object graph with all references will be merged.If an entity with the same identifier already exists in the context, the passed entity state is copied into it and the existing instance is returned. Otherwise, a copy of the passed instance is registered in the context and returned.
If the given instance is new and the context doesn't contain an instance with the same identifier, the context will save the new instance on
DataContext.commit(). Otherwise, even if some attributes of the merged instance are changed as a result of copying the state of the passed instance, the merged instance will not be committed. Such modifications are considered as a result of loading more fresh state from the database.WARNING: use the returned value because it is always a different object instance. The only case when you get the same instance is if the input was previously returned from the same context as a result of
DataContext.find(Class, Object)ormerge().- Specified by:
mergein interfaceDataContext- Parameters:
entity- instance to mergeoptions- merge options- Returns:
- the instance which is tracked by the context
-
merge
public <T> T merge(T entity) Description copied from interface:DataContextSame asDataContext.merge(Object, MergeOptions)with default options.- Specified by:
mergein interfaceDataContext
-
merge
Description copied from interface:DataContextMerge the given entities into the context. The whole object graph for each element of the collection with all references will be merged.Same as
DataContext.merge(Object)but for a collection of instances.- Specified by:
mergein interfaceDataContext- Returns:
- set of instances tracked by the context
-
merge
Description copied from interface:DataContextMerge the given entities into the context. The whole object graph for each element of the collection with all references will be merged.Same as
DataContext.merge(Object, MergeOptions)but for a collection of instances.- Specified by:
mergein interfaceDataContext- Returns:
- set of instances tracked by the context
-
internalMerge
-
makeKey
-
copyEntity
-
mergeState
-
setPropertyValue
-
setPropertyValue
protected void setPropertyValue(Object entity, MetaProperty property, @Nullable Object value, boolean checkEquals) -
copySystemState
-
mergeSystemState
protected void mergeSystemState(Object srcEntity, Object dstEntity, boolean isRoot, MergeOptions options) -
mergeLazyLoadingState
-
mergeList
protected void mergeList(List<Object> list, Object managedEntity, MetaProperty property, boolean replace, MergeOptions options, Map<Object, Object> mergedMap) -
mergeSet
protected void mergeSet(Set<Object> set, Object managedEntity, MetaProperty property, boolean replace, MergeOptions options, Map<Object, Object> mergedMap) -
wrapLazyValueIntoObservableCollection
protected Collection<Object> wrapLazyValueIntoObservableCollection(Collection<Object> collection, Object notifiedEntity) -
createObservableList
-
createObservableList
-
createObservableSet
-
createObservableSet
-
remove
Description copied from interface:DataContextRemoves the entity from the context and registers it as deleted. The entity will be removed from the data store upon subsequent call toDataContext.commit().If the given entity is not in the context, nothing happens.
- Specified by:
removein interfaceDataContext
-
removeFromCollections
-
evict
Description copied from interface:DataContextRemoves the entity from the context so the context stops tracking it.If the given entity is not in the context, nothing happens.
- Specified by:
evictin interfaceDataContext
-
evictModified
public void evictModified()Description copied from interface:DataContextClears the lists of created/modified/deleted entities and evicts these entities.- Specified by:
evictModifiedin interfaceDataContext
-
clear
public void clear()Description copied from interface:DataContextEvicts all tracked entities.- Specified by:
clearin interfaceDataContext- See Also:
-
create
Description copied from interface:DataContextCreates an entity instance and merges it into the context.Same as:
Foo foo = dataContext.merge(metadata.create(Foo.class));
- Specified by:
createin interfaceDataContext- Parameters:
entityClass- entity class- Returns:
- a new instance which is tracked by the context
-
removeListeners
-
hasChanges
public boolean hasChanges()Description copied from interface:DataContextReturns true if the context has detected changes in the tracked entities.- Specified by:
hasChangesin interfaceDataContext
-
isModified
Description copied from interface:DataContextReturns true if the context has detected changes in the given entity.- Specified by:
isModifiedin interfaceDataContext
-
setModified
Description copied from interface:DataContextRegisters or unregisters the given entity as modified.- Specified by:
setModifiedin interfaceDataContext- Parameters:
entity- entity instance which is already merged into the contextmodified- true to register or false to unregister
-
getModified
Description copied from interface:DataContextReturns an immutable set of entities registered as modified.- Specified by:
getModifiedin interfaceDataContext
-
isRemoved
Description copied from interface:DataContextReturns true if the context has registered removal of the given entity.- Specified by:
isRemovedin interfaceDataContext
-
getRemoved
Description copied from interface:DataContextReturns an immutable set of entities registered for removal.- Specified by:
getRemovedin interfaceDataContext
-
commit
Description copied from interface:DataContextCommits changed and removed instances to the middleware. After successful commit, the context contains updated instances returned from the middleware.- Specified by:
commitin interfaceDataContext- Returns:
- set of committed and merged back to the context instances. Does not contain removed instances.
- See Also:
-
addPreCommitListener
Description copied from interface:DataContextAdds a listener toDataContext.PreCommitEvent.You can also add an event listener declaratively using a controller method annotated with
Subscribe:@Subscribe(target = Target.DATA_CONTEXT) protected void onPreCommit(DataContext.PreCommitEvent event) { // handle event here }- Specified by:
addPreCommitListenerin interfaceDataContext- Parameters:
listener- listener- Returns:
- subscription
-
addPostCommitListener
Description copied from interface:DataContextAdds a listener toDataContext.PostCommitEvent.You can also add an event listener declaratively using a controller method annotated with
Subscribe:@Subscribe(target = Target.DATA_CONTEXT) protected void onPostCommit(DataContext.PostCommitEvent event) { // handle event here }- Specified by:
addPostCommitListenerin interfaceDataContext- Parameters:
listener- listener- Returns:
- subscription
-
getCommitDelegate
Description copied from interface:DataContextReturns a function which will be used to commit data instead of standard implementation.- Specified by:
getCommitDelegatein interfaceDataContext
-
setCommitDelegate
Description copied from interface:DataContextSets a function which will be used to commit data instead of standard implementation.- Specified by:
setCommitDelegatein interfaceDataContext
-
performCommit
-
commitToDataManager
-
filterCommittedInstances
-
isolate
-
commitToParentContext
-
cleanupContextAfterRemoveEntity
-
entityHasReference
-
mergeCommitted
-
getAll
-
modified
-
printContent
-
printEntity
-
printObject
-
getModifiedInstances
Description copied from interface:DataContextInternalReturns a mutable set of entities registered as modified.- Specified by:
getModifiedInstancesin interfaceDataContextInternal
-