Skip to content

Docs for typed result APIs #2006

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cds/cdl.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ SELECT.from({ ref: [{ id: 'UsingView', args: { bar: { val: true }}} ]} )
```
```Java [Java]
var params = Map.of("bar", true);
Result result = service.run(Select.from("UsingView"), params);
CdsResult<?> result = service.run(Select.from("UsingView"), params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not so nice.

```
:::

Expand Down
18 changes: 9 additions & 9 deletions java/cds-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ In CAP Java data is represented in maps. To simplify data access in custom code,

![This graphic is explained in the accompanying text.](./assets/accessor.drawio.svg)

The `Row`s of a [query result](./working-with-cql/query-execution#result) as well as the [generated accessor interfaces](#generated-accessor-interfaces) already extend `CdsData`. Using the helper class [Struct](#struct) you can extend any `Map<String, Object>` with the CdsData `interface`:
The rows of a [query result](./working-with-cql/query-execution#result) as well as the [generated accessor interfaces](#generated-accessor-interfaces) already extend `CdsData`. Using the helper class [Struct](#struct) you can extend any `Map<String, Object>` with the CdsData `interface`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The rows of a [query result](./working-with-cql/query-execution#result) as well as the [generated accessor interfaces](#generated-accessor-interfaces) already extend `CdsData`. Using the helper class [Struct](#struct) you can extend any `Map<String, Object>` with the CdsData `interface`:
The rows of a [query result](./working-with-cql/query-execution#result) as well as the [generated accessor interfaces](#generated-accessor-interfaces) already extend `CdsData`. Using the helper class [Struct](#struct) you can access any `Map<String, Object>` with the CdsData `interface`:


```java
Map<String, Object> map = new HashMap<>();
Expand Down Expand Up @@ -307,7 +307,7 @@ You can use the functions, `CQL.cosineSimilarity` or `CQL.l2Distance` (Euclidean
```Java
CqnVector v = CQL.vector(embedding);

Result similarBooks = service.run(Select.from(BOOKS).where(b ->
CdsResult<?> similarBooks = service.run(Select.from(BOOKS).where(b ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> similarBooks = service.run(Select.from(BOOKS).where(b ->
CdsResult<Books> similarBooks = service.run(Select.from(BOOKS).where(b ->

?

CQL.cosineSimilarity(b.embedding(), v).gt(0.9))
);
```
Expand All @@ -322,7 +322,7 @@ CqnSelect query = Select.from(BOOKS)
.where(b -> b.ID().ne(bookId).and(similarity.gt(0.9)))
.orderBy(b -> b.get("similarity").desc());

Result similarBooks = db.run(select, CdsVector.of(embedding));
CdsResult<?> similarBooks = db.run(select, CdsVector.of(embedding));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> similarBooks = db.run(select, CdsVector.of(embedding));
CdsResult<Books> similarBooks = db.run(select, CdsVector.of(embedding));

?

```

In CDS QL queries, elements of type `cds.Vector` are not included in select _all_ queries. They must be explicitly added to the select list:
Expand Down Expand Up @@ -397,7 +397,7 @@ To select the mapping elements of a managed association, simply add the [associa
CqnSelect select = Select.from(BOOKS).byId(123)
.columns(b -> b.author());

Row row = persistence.run(select).single();
CdsData row = persistence.run(select).single();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsData row = persistence.run(select).single();
Row row = persistence.run(select).single();

run(CqnSelect) -> Result; Result.single() -> Row


Integer authorId = row.getPath("author.ID");
```
Expand All @@ -414,7 +414,7 @@ Map<String, Object> order = new HashMap<>();
order.put("header.status", "canceled");

CqnSelect select = Select.from("bookshop.Orders").matching(order);
Result canceledOrders = persistence.run(select);
CdsResult<?> canceledOrders = persistence.run(select);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> canceledOrders = persistence.run(select);
Result canceledOrders = persistence.run(select);

```

## Typed Access
Expand Down Expand Up @@ -795,7 +795,7 @@ The process method can also be used on CDS.ql results that have a row type:

```java
CqnSelect query; // some query
Result result = service.run(query);
CdsResult<?> result = service.run(query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> result = service.run(query);
Result result = service.run(query);


processor.process(result);
```
Expand Down Expand Up @@ -909,8 +909,8 @@ diff.process(newImage, oldImage, type);
```

```java
Result newImage = service.run(Select.from(...));
Result oldImage = service.run(Select.from(...));
CdsResult<?> newImage = service.run(Select.from(...));
CdsResult<?> oldImage = service.run(Select.from(...));

diff.process(newImage, oldImage, newImage.rowType());
```
Expand Down Expand Up @@ -1373,7 +1373,7 @@ Using a custom `On` handler makes sense if you want to prevent that the default

```java
@On(event = CqnService.EVENT_UPDATE)
public Result processCoverImage(CdsUpdateEventContext context, List<Books> books) {
public CdsResult<?> processCoverImage(CdsUpdateEventContext context, List<Books> books) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the return type and the execution on 1382

books.forEach(book -> {
book.setCoverImage(new CoverImagePreProcessor(book.getCoverImage()));
});
Expand Down
2 changes: 1 addition & 1 deletion java/cqn-services/application-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ If an event handler for an `UPDATE` or `DELETE` event does not specify a result

Event handlers for `INSERT` and `UPSERT` events can return a result representing the data that was inserted/upserted.

A failed insert is indicated by throwing an exception, for example, a `UniqueConstraintException` or a `CdsServiceException` with error status `CONFLICT`.
A failed insert is indicated by throwing an exception, for example, a `UniqueConstraintException` or a `ServiceException` with error status `CONFLICT`.

### Result Builder { #result-builder}

Expand Down
2 changes: 1 addition & 1 deletion java/developing-applications/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class CatalogServiceTest {

@Test
public void discountApplied() {
Result result = catalogService.run(Select.from(Books_.class).byId("51061ce3-ddde-4d70-a2dc-6314afbcc73e"));
CdsResult<?> result = catalogService.run(Select.from(Books_.class).byId("51061ce3-ddde-4d70-a2dc-6314afbcc73e"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> result = catalogService.run(Select.from(Books_.class).byId("51061ce3-ddde-4d70-a2dc-6314afbcc73e"));
CdsResult<Books> result = catalogService.run(Select.from(Books_.class).byId("51061ce3-ddde-4d70-a2dc-6314afbcc73e"));


// book with title "The Raven" and a stock quantity of > 111
Books book = result.single(Books.class);
Expand Down
4 changes: 2 additions & 2 deletions java/event-handlers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,15 +447,15 @@ The return value of an event can be set by returning a value in an event handler

```java
@On(entity = Books_.CDS_NAME)
public Result readBooks(CdsReadEventContext context) {
public CdsResult<?> readBooks(CdsReadEventContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public CdsResult<?> readBooks(CdsReadEventContext context) {
public Result readBooks(CdsReadEventContext context) {

return db.run(context.getCqn());
}
```

In case an event handler method of the `Before` or `On` phase has a return value it automatically [completes the event processing](#eventcompletion), once it's executed.
Event handler methods of the `After` phase that have a return value, replace the return value of the event.

For [CRUD events](../cqn-services/application-services#crudevents) and [draft-specific CRUD events](../fiori-drafts#draftevents), return values that extend `Iterable<? extends Map<String, Object>>` are supported. The `Result` object or a list of entity data (for example `List<Books>`) fulfill this requirement.
For [CRUD events](../cqn-services/application-services#crudevents) and [draft-specific CRUD events](../fiori-drafts#draftevents), return values that extend `Iterable<? extends Map<String, Object>>` are supported. The `Result` and `CdsResult<?` interfaces or a list of entity data (for example `List<Books>`) fulfill this requirement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For [CRUD events](../cqn-services/application-services#crudevents) and [draft-specific CRUD events](../fiori-drafts#draftevents), return values that extend `Iterable<? extends Map<String, Object>>` are supported. The `Result` and `CdsResult<?` interfaces or a list of entity data (for example `List<Books>`) fulfill this requirement.
For [CRUD events](../cqn-services/application-services#crudevents) and [draft-specific CRUD events](../fiori-drafts#draftevents), return values that extend `Iterable<? extends Map<String, Object>>` are supported. The `Result` and `CdsResult<?>` interfaces or a list of entity data (for example `List<Books>`) fulfill this requirement.


```java
@On(entity = Books_.CDS_NAME)
Expand Down
2 changes: 1 addition & 1 deletion java/event-handlers/request-contexts.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ To propagate the parent context, create an instance of `RequestContextRunner` in

```java
RequestContextRunner runner = runtime.requestContext();
Future<Result> result = Executors.newSingleThreadExecutor().submit(() -> {
Future<CdsResult<?>> result = Executors.newSingleThreadExecutor().submit(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Future<CdsResult<?>> result = Executors.newSingleThreadExecutor().submit(() -> {
Future<CdsResult<Books>> result = Executors.newSingleThreadExecutor().submit(() -> {

return runner.run(threadContext -> {
return persistenceService.run(Select.from(Books_.class));
});
Expand Down
2 changes: 1 addition & 1 deletion java/fiori-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ You can then delegate reading of active entities, for example to a remote S/4 sy

```java
@On(entity = MyRemoteDraftEnabledEntity_.CDS_NAME)
public Result delegateToS4(ActiveReadEventContext context) {
public CdsResult<?> delegateToS4(ActiveReadEventContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public CdsResult<?> delegateToS4(ActiveReadEventContext context) {
public Result delegateToS4(ActiveReadEventContext context) {

return remoteS4.run(context.getCqn());
}
```
Expand Down
2 changes: 1 addition & 1 deletion java/reflection-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ FeatureTogglesInfo isbn = FeatureTogglesInfo.create(Collections.singletonMap("is

...

Future<Result> result = Executors.newSingleThreadExecutor().submit(() -> {
Future<CdsResult<?>> result = Executors.newSingleThreadExecutor().submit(() -> {
return runtime.requestContext().featureToggles(isbn).run(rc -> {
return db.run(Select.from(Books_.CDS_NAME));
});
Expand Down
6 changes: 3 additions & 3 deletions java/working-with-cql/query-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ import static bookshop.Bookshop_.BOOKS;
CqnSelect q = Select.from(BOOKS)
.columns(b -> b.author());

Row book = dataStore.execute(q).single();
CdsData book = dataStore.execute(q).single();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsData book = dataStore.execute(q).single();
Row book = dataStore.execute(q).single();

Object authorId = book.get("author.Id"); // path access
```

Expand Down Expand Up @@ -1152,7 +1152,7 @@ Map<String, Object> paramSet2 = new HashMap<>();
paramSet2.put("author.name", "Emily Brontë");
paramSet2.put("title", "Wuthering Heights");

Result result = service.run(update, asList(paramSet1, paramSet2));
CdsResult<?> result = service.run(update, asList(paramSet1, paramSet2));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CdsResult<?> result = service.run(update, asList(paramSet1, paramSet2));
Result result = service.run(update, asList(paramSet1, paramSet2));

run(CqnUpdate) -> Result

```

## Delete
Expand Down Expand Up @@ -1623,7 +1623,7 @@ BETWEEN

#### `IN` Predicate

The `IN` predicate tests if a value is equal to any value in a given list.
The `IN` predicate tests if a value is equal to any value in a given list.

The following example, filters for books written by Poe or Hemingway:

Expand Down
Loading