public class NoopDataContext extends java.lang.Object implements DataContext
DataContext used for read-only screens like entity browsers.DataContext.ChangeEvent, DataContext.PostCommitEvent, DataContext.PreCommitEvent| Modifier and Type | Field and Description |
|---|---|
protected org.springframework.context.ApplicationContext |
applicationContext |
| Constructor and Description |
|---|
NoopDataContext(org.springframework.context.ApplicationContext applicationContext) |
| 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. |
void |
clear()
Evicts all tracked entities.
|
io.jmix.core.EntitySet |
commit()
Commits changed and removed instances to the middleware.
|
boolean |
contains(java.lang.Object entity)
Returns true if the context contains the given entity (distinguished by its class and id).
|
<T> T |
create(java.lang.Class<T> entityClass)
Creates an entity instance and merges it into the context.
|
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.
|
<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.
|
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.
|
boolean |
isModified(java.lang.Object entity)
Returns true if the context has detected changes in the given entity.
|
boolean |
isRemoved(java.lang.Object entity)
Returns true if the context has registered removal of the given 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.
|
void |
remove(java.lang.Object entity)
Removes the entity from the context and registers it as deleted.
|
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 org.springframework.context.ApplicationContext applicationContext
public NoopDataContext(org.springframework.context.ApplicationContext applicationContext)
@Nullable
public <T> T find(java.lang.Class<T> entityClass,
java.lang.Object entityId)
DataContextfind in interface DataContextpublic <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 DataContextpublic void remove(java.lang.Object entity)
DataContextDataContext.commit().
If the given entity is not in the context, nothing happens.
remove in interface DataContextpublic 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 classpublic 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 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 DataContextpublic 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 DataContext