Table of Contents
The goal of this module is to capture commit changes and present them to interested parties in an easy-to-process format.
<dependency> <groupId>org.apache.cayenne</groupId> <artifactId>cayenne-commitlog</artifactId> <version>4.0.B2</version> </dependency>
In order to use commitlog
module you need to perform three steps:
Mark all entities which changes you are interested in with @org.apache.cayenne.commitlog.CommitLog
annotation
@CommitLog(ignoredProperties = {"somePrivatePropertyToSkip"}) public class MyEntity extends _MyEntity { // ... }
Implement CommitLogListener
interface.
public class MyCommitLogListener implements CommitLogListener { @Override public void onPostCommit(ObjectContext originatingContext, ChangeMap changes) { // ChangeMap will contain all information about changes happened in performed commit // this particular example will print IDs of all inserted objects changes.getUniqueChanges().stream() .filter(change -> change.getType() == ObjectChangeType.INSERT) .map(ObjectChange::getPostCommitId) .forEach(id -> System.out.println("Inserted new entity with id: " + id)); } }
Inject your listener into ServerRuntime
ServerRuntime.builder()
.addModule(CommitLogModule.extend()
.addListener(MyCommitLogListener.class)
.module())