public class NoopDataContext extends java.lang.Object implements DataContext
DataContext
used for read-only screens like entity browsers.DataContext.ChangeEvent, DataContext.PostCommitEvent, DataContext.PreCommitEvent
Constructor and Description |
---|
NoopDataContext() |
Modifier and Type | Method and Description |
---|---|
com.haulmont.bali.events.Subscription |
addChangeListener(java.util.function.Consumer<DataContext.ChangeEvent> listener)
Adds a listener to
DataContext.ChangeEvent . |
com.haulmont.bali.events.Subscription |
addPostCommitListener(java.util.function.Consumer<DataContext.PostCommitEvent> listener)
Adds a listener to
DataContext.PostCommitEvent . |
com.haulmont.bali.events.Subscription |
addPreCommitListener(java.util.function.Consumer<DataContext.PreCommitEvent> listener)
Adds a listener to
DataContext.PreCommitEvent . |
void |
commit()
Commits changed and removed instances to the middleware.
|
boolean |
contains(Entity entity)
Returns true if the context contains the given entity (distinguished by its class and id).
|
<T extends Entity> |
create(java.lang.Class<T> entityClass)
Creates an entity instance and merge it into the context.
|
void |
evict(Entity entity)
Removes the entity from the context so the context stops tracking it.
|
<T extends Entity<K>,K> |
find(java.lang.Class<T> entityClass,
K entityId)
Returns an entity instance by its class and id.
|
<T extends Entity> |
find(T entity)
Returns the instance of entity with the same id if it exists in this context.
|
java.util.function.Function<CommitContext,java.util.Set<Entity>> |
getCommitDelegate()
Returns a function which will be used to commit data instead of standard implementation.
|
DataContext |
getParent()
Returns a parent context, if any.
|
boolean |
hasChanges()
Returns true if the context has detected changes in the tracked entities.
|
boolean |
isModified(Entity entity)
Returns true if the context has detected changes in the given entity.
|
boolean |
isRemoved(Entity entity)
Returns true if the context has registered removal of the given entity.
|
EntitySet |
merge(java.util.Collection<? extends Entity> entities)
Merge the given entities into the context.
|
<T extends Entity> |
merge(T entity)
Merge the given entity into the context.
|
void |
remove(Entity entity)
Removes the entity from the context and registers it as deleted.
|
void |
setCommitDelegate(java.util.function.Function<CommitContext,java.util.Set<Entity>> delegate)
Sets a function which will be used to commit data instead of standard implementation.
|
void |
setParent(DataContext parentContext)
Sets the parent context.
|
@Nullable public <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K entityId)
DataContext
find
in interface DataContext
public <T extends Entity> T find(T entity)
DataContext
find
in interface DataContext
public boolean contains(Entity entity)
DataContext
contains
in interface DataContext
public <T extends Entity> T merge(T entity)
DataContext
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 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 DataContext
public EntitySet merge(java.util.Collection<? extends Entity> entities)
DataContext
Same as DataContext.merge(Entity)
but for a collection of instances.
merge
in interface DataContext
DataContext.merge(Entity)
public void remove(Entity entity)
DataContext
DataContext.commit()
.
If the given entity is not in the context, nothing happens.
remove
in interface DataContext
public void evict(Entity entity)
DataContext
If the given entity is not in the context, nothing happens.
evict
in interface DataContext
public <T extends Entity> T create(java.lang.Class<T> entityClass)
DataContext
Same as:
Foo foo = dataContext.merge(metadata.create(Foo.class));
create
in interface DataContext
entityClass
- entity classpublic boolean hasChanges()
DataContext
hasChanges
in interface DataContext
public boolean isModified(Entity entity)
DataContext
isModified
in interface DataContext
public boolean isRemoved(Entity entity)
DataContext
isRemoved
in interface DataContext
public void commit()
DataContext
commit
in interface DataContext
DataContext.setParent(DataContext)
public DataContext getParent()
DataContext
DataContext.commit()
method merges the changed instances
to it instead of sending to the middleware.getParent
in interface DataContext
public void setParent(DataContext parentContext)
DataContext
DataContext.commit()
method merges the changed instances
to it instead of sending to the middleware.setParent
in interface DataContext
public com.haulmont.bali.events.Subscription addChangeListener(java.util.function.Consumer<DataContext.ChangeEvent> listener)
DataContext
DataContext.ChangeEvent
.addChangeListener
in interface DataContext
public com.haulmont.bali.events.Subscription addPreCommitListener(java.util.function.Consumer<DataContext.PreCommitEvent> listener)
DataContext
DataContext.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 DataContext
listener
- listenerpublic com.haulmont.bali.events.Subscription addPostCommitListener(java.util.function.Consumer<DataContext.PostCommitEvent> listener)
DataContext
DataContext.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 DataContext
listener
- listenerpublic java.util.function.Function<CommitContext,java.util.Set<Entity>> getCommitDelegate()
DataContext
getCommitDelegate
in interface DataContext
public void setCommitDelegate(java.util.function.Function<CommitContext,java.util.Set<Entity>> delegate)
DataContext
setCommitDelegate
in interface DataContext