-
Notifications
You must be signed in to change notification settings - Fork 132
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -219,7 +219,7 @@ In CAP Java data is represented in maps. To simplify data access in custom code, | |||||
|
||||||
 | ||||||
|
||||||
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`: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```java | ||||||
Map<String, Object> map = new HashMap<>(); | ||||||
|
@@ -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 -> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||
CQL.cosineSimilarity(b.embedding(), v).gt(0.9)) | ||||||
); | ||||||
``` | ||||||
|
@@ -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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||
``` | ||||||
|
||||||
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: | ||||||
|
@@ -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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
run(CqnSelect) -> Result; Result.single() -> Row |
||||||
|
||||||
Integer authorId = row.getPath("author.ID"); | ||||||
``` | ||||||
|
@@ -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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
``` | ||||||
|
||||||
## Typed Access | ||||||
|
@@ -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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
processor.process(result); | ||||||
``` | ||||||
|
@@ -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()); | ||||||
``` | ||||||
|
@@ -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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())); | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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")); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// book with title "The Raven" and a stock quantity of > 111 | ||||||
Books book = result.single(Books.class); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```java | ||||||
@On(entity = Books_.CDS_NAME) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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(() -> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return runner.run(threadContext -> { | ||||||
return persistenceService.run(Select.from(Books_.class)); | ||||||
}); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return remoteS4.run(context.getCqn()); | ||||||
} | ||||||
``` | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Object authorId = book.get("author.Id"); // path access | ||||||
``` | ||||||
|
||||||
|
@@ -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)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
run(CqnUpdate) -> Result |
||||||
``` | ||||||
|
||||||
## Delete | ||||||
|
@@ -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: | ||||||
|
||||||
|
There was a problem hiding this comment.
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.