Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update docs on how to access public change tracking interfaces #1612

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions java/change-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,28 @@ If you change the values of the `OrderItems` entity directly via an OData reques
You can write an event handler to observe the change log entries. Keep in mind, that the change log entries
are created for each statement and this event will not be bound to any kind of transaction or a batch operation.

```java
import cds.gen.sap.changelog.Changes;
First, update the dependency's scope to `compile` in the `srv/pom.xml` file of your service:

```xml
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-change-tracking</artifactId>
<scope>compile</scope>
</dependency>
```

Second, add a handler to access the changes:

```java
@Component
@ServiceName("ChangeTrackingService$Default")
@ServiceName(ChangeTrackingService.DEFAULT_NAME)
public class ChangeTrackingHandler implements EventHandler {

@After(event = "createChanges")
void afterCreate(EventContext context) {
Result result = (Result) context.get("result");
result.listOf(Changes.class).forEach(c -> {
@After(event = ChangeTrackingService.CREATE_CHANGES)
void afterCreate(CreateChangesEventContext context) {
context.getChanges().forEach(c -> {
// Do something with the change log entry
});
});
}
}
```
Expand Down