public static class DataContext.PreCommitEvent
extends java.util.EventObject
In this event listener, you can add arbitrary entity instances to the committed collections returned by
getModifiedInstances()
and getRemovedInstances()
methods, for example:
@Subscribe(target = Target.DATA_CONTEXT) protected void onPreCommit(DataContext.PreCommitEvent event) { event.getModifiedInstances().add(customer); }You can also prevent commit using the
preventCommit()
method of the event, for example:
@Subscribe(target = Target.DATA_CONTEXT) protected void onPreCommit(DataContext.PreCommitEvent event) { if (doNotCommit()) { event.preventCommit(); } }
Constructor and Description |
---|
PreCommitEvent(DataContext dataContext,
java.util.Collection<Entity> modified,
java.util.Collection<Entity> removed) |
Modifier and Type | Method and Description |
---|---|
java.util.Collection<Entity> |
getModifiedInstances()
Returns the collection of modified instances.
|
java.util.Collection<Entity> |
getRemovedInstances()
Returns the collection of removed instances.
|
DataContext |
getSource()
The data context which sent the event.
|
java.util.List<java.lang.Class> |
getValidationGroups() |
CommitContext.ValidationMode |
getValidationMode() |
boolean |
isCommitPrevented()
Returns true if
preventCommit() method was called and commit will be aborted. |
void |
preventCommit()
Invoke this method if you want to abort the commit.
|
void |
setValidationGroups(java.util.List<java.lang.Class> validationGroups)
Sets groups targeted for validation.
|
void |
setValidationMode(CommitContext.ValidationMode validationMode)
Sets
CommitContext.ValidationMode for associated commit. |
public PreCommitEvent(DataContext dataContext, java.util.Collection<Entity> modified, java.util.Collection<Entity> removed)
public DataContext getSource()
getSource
in class java.util.EventObject
public java.util.Collection<Entity> getModifiedInstances()
public java.util.Collection<Entity> getRemovedInstances()
public void preventCommit()
public boolean isCommitPrevented()
preventCommit()
method was called and commit will be aborted.public java.util.List<java.lang.Class> getValidationGroups()
Validator.validate(Object, Class[])
public void setValidationGroups(java.util.List<java.lang.Class> validationGroups)
validationGroups
- Set
of groupsValidator.validate(Object, Class[])
public CommitContext.ValidationMode getValidationMode()
CommitContext.ValidationMode
of associated commit.public void setValidationMode(CommitContext.ValidationMode validationMode)
CommitContext.ValidationMode
for associated commit.
Validation mode affects whether entity bean validation will be applied on DataManager
level.
Note that the validation mode will be ignored for child context.validationMode
- validation typeBeanValidation