public class DataContextImpl extends java.lang.Object implements DataContext
DataContext which commits data to DataManager.| Modifier and Type | Class and Description |
|---|---|
protected class |
DataContextImpl.EmbeddedPropertyChangeListener |
protected class |
DataContextImpl.PropertyChangeListener |
DataContext.ChangeEvent, DataContext.PostCommitEvent, DataContext.PreCommitEvent| Modifier and Type | Field and Description |
|---|---|
protected java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> |
commitDelegate |
protected java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Object,java.lang.Object>> |
content |
protected io.jmix.core.DataManager |
dataManager |
protected boolean |
disableListeners |
protected java.util.Map<java.lang.Object,java.util.Map<java.lang.String,DataContextImpl.EmbeddedPropertyChangeListener>> |
embeddedPropertyListeners |
protected io.jmix.core.EntityReferencesNormalizer |
entityReferencesNormalizer |
protected io.jmix.core.EntityStates |
entityStates |
protected io.jmix.core.EntitySystemStateSupport |
entitySystemStateSupport |
protected io.jmix.core.common.event.EventHub |
events |
protected io.jmix.core.Metadata |
metadata |
protected io.jmix.core.MetadataTools |
metadataTools |
protected java.util.Set<java.lang.Object> |
modifiedInstances |
protected java.util.Map<java.lang.Object,java.lang.Object> |
nullIdEntitiesMap |
protected DataContextImpl |
parentContext |
protected DataContextImpl.PropertyChangeListener |
propertyChangeListener |
protected java.util.Set<java.lang.Object> |
removedInstances |
protected io.jmix.core.impl.StandardSerialization |
standardSerialization |
| Constructor and Description |
|---|
DataContextImpl() |
| Modifier and Type | Method and Description |
|---|---|
io.jmix.core.common.event.Subscription |
addChangeListener(java.util.function.Consumer<DataContext.ChangeEvent> listener)
Adds a listener to
DataContext.ChangeEvent. |
io.jmix.core.common.event.Subscription |
addPostCommitListener(java.util.function.Consumer<DataContext.PostCommitEvent> listener)
Adds a listener to
DataContext.PostCommitEvent. |
io.jmix.core.common.event.Subscription |
addPreCommitListener(java.util.function.Consumer<DataContext.PreCommitEvent> listener)
Adds a listener to
DataContext.PreCommitEvent. |
protected void |
cleanupContextAfterRemoveEntity(DataContextImpl context,
java.lang.Object removedEntity) |
void |
clear()
Evicts all tracked entities.
|
io.jmix.core.EntitySet |
commit()
Commits changed and removed instances to the middleware.
|
protected java.util.Set<java.lang.Object> |
commitToDataManager() |
protected java.util.Set<java.lang.Object> |
commitToParentContext() |
boolean |
contains(java.lang.Object entity)
Returns true if the context contains the given entity (distinguished by its class and id).
|
protected java.lang.Object |
copyEntity(java.lang.Object srcEntity) |
protected void |
copySystemState(java.lang.Object srcEntity,
java.lang.Object dstEntity) |
<T> T |
create(java.lang.Class<T> entityClass)
Creates an entity instance and merges it into the context.
|
protected java.util.List<java.lang.Object> |
createObservableList(java.util.List<java.lang.Object> list,
java.lang.Object notifiedEntity) |
protected java.util.List<java.lang.Object> |
createObservableList(java.lang.Object notifiedEntity) |
protected java.util.Set<java.lang.Object> |
createObservableSet(java.lang.Object notifiedEntity) |
protected ObservableSet<java.lang.Object> |
createObservableSet(java.util.Set<java.lang.Object> set,
java.lang.Object notifiedEntity) |
protected boolean |
entityHasReference(java.lang.Object entity,
java.lang.Object refEntity) |
void |
evict(java.lang.Object entity)
Removes the entity from the context so the context stops tracking it.
|
void |
evictModified()
Clears the lists of created/modified/deleted entities and evicts these entities.
|
protected java.util.List |
filterCommittedInstances(java.util.Set<java.lang.Object> instances) |
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object entityId)
Returns an entity instance by its class and id.
|
<T> T |
find(T entity)
Returns the instance of entity with the same id if it exists in this context.
|
protected void |
fireChangeListener(java.lang.Object entity) |
java.util.Collection |
getAll() |
java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> |
getCommitDelegate()
Returns a function which will be used to commit data instead of standard implementation.
|
java.util.Set |
getModified()
Returns an immutable set of entities registered as modified.
|
DataContext |
getParent()
Returns a parent context, if any.
|
java.util.Set |
getRemoved()
Returns an immutable set of entities registered for removal.
|
boolean |
hasChanges()
Returns true if the context has detected changes in the tracked entities.
|
protected java.lang.Object |
internalMerge(java.lang.Object entity,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap,
boolean isRoot,
MergeOptions options) |
boolean |
isModified(java.lang.Object entity)
Returns true if the context has detected changes in the given entity.
|
java.util.Collection<java.lang.Object> |
isolate(java.util.List entities) |
boolean |
isRemoved(java.lang.Object entity)
Returns true if the context has registered removal of the given entity.
|
protected java.lang.Object |
makeKey(java.lang.Object entity) |
io.jmix.core.EntitySet |
merge(java.util.Collection entities)
Merge the given entities into the context.
|
io.jmix.core.EntitySet |
merge(java.util.Collection entities,
MergeOptions options)
Merge the given entities into the context.
|
<T> T |
merge(T entity)
Same as
DataContext.merge(Object, MergeOptions) with default options. |
<T> T |
merge(T entity,
MergeOptions options)
Merge the given entity into the context.
|
protected io.jmix.core.EntitySet |
mergeCommitted(java.util.Set<java.lang.Object> committed) |
protected void |
mergeLazyLoadingState(java.lang.Object srcEntity,
java.lang.Object dstEntity) |
protected void |
mergeList(java.util.List<java.lang.Object> list,
java.lang.Object managedEntity,
io.jmix.core.metamodel.model.MetaProperty property,
boolean replace,
MergeOptions options,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap) |
protected void |
mergeSet(java.util.Set<java.lang.Object> set,
java.lang.Object managedEntity,
io.jmix.core.metamodel.model.MetaProperty property,
boolean replace,
MergeOptions options,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap) |
protected void |
mergeState(java.lang.Object srcEntity,
java.lang.Object dstEntity,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap,
boolean isRoot,
MergeOptions options) |
protected void |
mergeSystemState(java.lang.Object srcEntity,
java.lang.Object dstEntity,
boolean isRoot,
MergeOptions options) |
protected void |
modified(java.lang.Object entity) |
protected java.util.Set<java.lang.Object> |
performCommit() |
java.lang.String |
printContent() |
protected java.lang.String |
printEntity(java.lang.Object entity,
int level,
java.util.Set<java.lang.Object> visited) |
protected java.lang.String |
printObject(java.lang.Object object) |
void |
remove(java.lang.Object entity)
Removes the entity from the context and registers it as deleted.
|
protected void |
removeFromCollections(java.lang.Object entityToRemove) |
protected void |
removeListeners(java.lang.Object entity) |
void |
setCommitDelegate(java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> delegate)
Sets a function which will be used to commit data instead of standard implementation.
|
void |
setModified(java.lang.Object entity,
boolean modified)
Registers or unregisters the given entity as modified.
|
void |
setParent(DataContext parentContext)
Sets the parent context.
|
protected void |
setPropertyValue(java.lang.Object entity,
io.jmix.core.metamodel.model.MetaProperty property,
java.lang.Object value) |
protected void |
setPropertyValue(java.lang.Object entity,
io.jmix.core.metamodel.model.MetaProperty property,
java.lang.Object value,
boolean checkEquals) |
protected java.util.Collection<java.lang.Object> |
wrapLazyValueIntoObservableCollection(java.util.Collection<java.lang.Object> collection,
java.lang.Object notifiedEntity) |
@Autowired protected io.jmix.core.Metadata metadata
@Autowired protected io.jmix.core.MetadataTools metadataTools
@Autowired protected io.jmix.core.EntityStates entityStates
@Autowired protected io.jmix.core.DataManager dataManager
@Autowired protected io.jmix.core.EntitySystemStateSupport entitySystemStateSupport
@Autowired protected io.jmix.core.EntityReferencesNormalizer entityReferencesNormalizer
@Autowired protected io.jmix.core.impl.StandardSerialization standardSerialization
protected io.jmix.core.common.event.EventHub events
protected java.util.Map<java.lang.Class<?>,java.util.Map<java.lang.Object,java.lang.Object>> content
protected java.util.Set<java.lang.Object> modifiedInstances
protected java.util.Set<java.lang.Object> removedInstances
protected DataContextImpl.PropertyChangeListener propertyChangeListener
protected boolean disableListeners
protected DataContextImpl parentContext
protected java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> commitDelegate
protected java.util.Map<java.lang.Object,java.util.Map<java.lang.String,DataContextImpl.EmbeddedPropertyChangeListener>> embeddedPropertyListeners
protected java.util.Map<java.lang.Object,java.lang.Object> nullIdEntitiesMap
@Nullable public DataContext getParent()
DataContextDataContext.commit() method merges the changed instances
to it instead of sending to the middleware.getParent in interface DataContextpublic void setParent(DataContext parentContext)
DataContextDataContext.commit() method merges the changed instances
to it instead of sending to the middleware.setParent in interface DataContextpublic io.jmix.core.common.event.Subscription addChangeListener(java.util.function.Consumer<DataContext.ChangeEvent> listener)
DataContextDataContext.ChangeEvent.addChangeListener in interface DataContextprotected void fireChangeListener(java.lang.Object entity)
@Nullable
public <T> T find(java.lang.Class<T> entityClass,
java.lang.Object entityId)
DataContextfind in interface DataContext@Nullable public <T> T find(T entity)
DataContextfind in interface DataContextpublic boolean contains(java.lang.Object entity)
DataContextcontains in interface DataContextpublic <T> T merge(T entity,
MergeOptions options)
DataContextIf 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) or merge().
merge in interface DataContextentity - instance to mergeoptions - merge optionspublic <T> T merge(T entity)
DataContextDataContext.merge(Object, MergeOptions) with default options.merge in interface DataContextpublic io.jmix.core.EntitySet merge(java.util.Collection entities,
MergeOptions options)
DataContext
Same as DataContext.merge(Object) but for a collection of instances.
merge in interface DataContextpublic io.jmix.core.EntitySet merge(java.util.Collection entities)
DataContext
Same as DataContext.merge(Object, MergeOptions) but for a collection of instances.
merge in interface DataContextprotected java.lang.Object internalMerge(java.lang.Object entity,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap,
boolean isRoot,
MergeOptions options)
protected java.lang.Object makeKey(java.lang.Object entity)
protected java.lang.Object copyEntity(java.lang.Object srcEntity)
protected void mergeState(java.lang.Object srcEntity,
java.lang.Object dstEntity,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap,
boolean isRoot,
MergeOptions options)
protected void setPropertyValue(java.lang.Object entity,
io.jmix.core.metamodel.model.MetaProperty property,
@Nullable
java.lang.Object value)
protected void setPropertyValue(java.lang.Object entity,
io.jmix.core.metamodel.model.MetaProperty property,
@Nullable
java.lang.Object value,
boolean checkEquals)
protected void copySystemState(java.lang.Object srcEntity,
java.lang.Object dstEntity)
protected void mergeSystemState(java.lang.Object srcEntity,
java.lang.Object dstEntity,
boolean isRoot,
MergeOptions options)
protected void mergeLazyLoadingState(java.lang.Object srcEntity,
java.lang.Object dstEntity)
protected void mergeList(java.util.List<java.lang.Object> list,
java.lang.Object managedEntity,
io.jmix.core.metamodel.model.MetaProperty property,
boolean replace,
MergeOptions options,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap)
protected void mergeSet(java.util.Set<java.lang.Object> set,
java.lang.Object managedEntity,
io.jmix.core.metamodel.model.MetaProperty property,
boolean replace,
MergeOptions options,
java.util.Map<java.lang.Object,java.lang.Object> mergedMap)
protected java.util.Collection<java.lang.Object> wrapLazyValueIntoObservableCollection(java.util.Collection<java.lang.Object> collection,
java.lang.Object notifiedEntity)
protected java.util.List<java.lang.Object> createObservableList(java.lang.Object notifiedEntity)
protected java.util.List<java.lang.Object> createObservableList(java.util.List<java.lang.Object> list,
java.lang.Object notifiedEntity)
protected java.util.Set<java.lang.Object> createObservableSet(java.lang.Object notifiedEntity)
protected ObservableSet<java.lang.Object> createObservableSet(java.util.Set<java.lang.Object> set, java.lang.Object notifiedEntity)
public void remove(java.lang.Object entity)
DataContextDataContext.commit().
If the given entity is not in the context, nothing happens.
remove in interface DataContextprotected void removeFromCollections(java.lang.Object entityToRemove)
public void evict(java.lang.Object entity)
DataContextIf the given entity is not in the context, nothing happens.
evict in interface DataContextpublic void evictModified()
DataContextevictModified in interface DataContextpublic void clear()
DataContextclear in interface DataContextDataContext.evict(Object)public <T> T create(java.lang.Class<T> entityClass)
DataContextSame as:
Foo foo = dataContext.merge(metadata.create(Foo.class));
create in interface DataContextentityClass - entity classprotected void removeListeners(java.lang.Object entity)
public boolean hasChanges()
DataContexthasChanges in interface DataContextpublic boolean isModified(java.lang.Object entity)
DataContextisModified in interface DataContextpublic void setModified(java.lang.Object entity,
boolean modified)
DataContextsetModified in interface DataContextentity - entity instance which is already merged into the contextmodified - true to register or false to unregisterpublic java.util.Set getModified()
DataContextgetModified in interface DataContextpublic boolean isRemoved(java.lang.Object entity)
DataContextisRemoved in interface DataContextpublic java.util.Set getRemoved()
DataContextgetRemoved in interface DataContextpublic io.jmix.core.EntitySet commit()
DataContextcommit in interface DataContextDataContext.setParent(DataContext)public io.jmix.core.common.event.Subscription addPreCommitListener(java.util.function.Consumer<DataContext.PreCommitEvent> listener)
DataContextDataContext.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
}
addPreCommitListener in interface DataContextlistener - listenerpublic io.jmix.core.common.event.Subscription addPostCommitListener(java.util.function.Consumer<DataContext.PostCommitEvent> listener)
DataContextDataContext.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
}
addPostCommitListener in interface DataContextlistener - listenerpublic java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> getCommitDelegate()
DataContextgetCommitDelegate in interface DataContextpublic void setCommitDelegate(java.util.function.Function<io.jmix.core.SaveContext,java.util.Set<java.lang.Object>> delegate)
DataContextsetCommitDelegate in interface DataContextprotected java.util.Set<java.lang.Object> performCommit()
protected java.util.Set<java.lang.Object> commitToDataManager()
protected java.util.List filterCommittedInstances(java.util.Set<java.lang.Object> instances)
public java.util.Collection<java.lang.Object> isolate(java.util.List entities)
protected java.util.Set<java.lang.Object> commitToParentContext()
protected void cleanupContextAfterRemoveEntity(DataContextImpl context, java.lang.Object removedEntity)
protected boolean entityHasReference(java.lang.Object entity,
java.lang.Object refEntity)
protected io.jmix.core.EntitySet mergeCommitted(java.util.Set<java.lang.Object> committed)
public java.util.Collection getAll()
protected void modified(java.lang.Object entity)
public java.lang.String printContent()
protected java.lang.String printEntity(java.lang.Object entity,
int level,
java.util.Set<java.lang.Object> visited)
protected java.lang.String printObject(java.lang.Object object)