diff --git a/java/query-api.md b/java/query-api.md index 34ad33544..62ed1f906 100644 --- a/java/query-api.md +++ b/java/query-api.md @@ -1212,17 +1212,20 @@ The Query Builder API supports using expressions in many places. Expressions con ### Entity References {#entity-refs} -Entity references specify entity sets. They can be used to define the target entity set of a [CQL](../cds/cql) statement. They can either be defined inline using lambda expressions in the Query Builder (see [Target Entity Sets](#target-entity-sets)) or via the `CQL.entity` method. The following example shows an entity reference describing the set of *authors* that have published books in the year 2020: +Entity references specify entity sets. They can be used to define the target entity set of a [CQL](../cds/cql) statement. They can either be defined inline using lambda expressions in the Query Builder (see [Target Entity Sets](#target-entity-sets)) or via the `CQL.entity` method, which is available in an _untyped_ version as well as in a _typed_ version that uses the generated [model interfaces](../java/advanced#model-interfaces). The following example shows an entity reference describing the set of *authors* that have published books in the year 2020: ```java -import static com.sap.cds.ql.CQL.entity; +import com.sap.cds.ql.CQL; + +// bookshop.Books[year = 2020].author // [!code focus] +Authors_ authors = CQL.entity(Books_.class).filter(b -> b.year().eq(2020)).author(); // [!code focus] -// bookshop.Books[year = 2020].author +// or as untyped entity ref StructuredType authors = - entity("bookshop.Books").filter(b -> b.get("year").eq(2020)).to("author"); + CQL.entity("bookshop.Books").filter(b -> b.get("year").eq(2020)).to("author"); -// SELECT from bookshop.Books[year = 2020].author { name } -Select.from(authors).columns("name"); +// SELECT from bookshop.Books[year = 2020].author { name } // [!code focus] +Select.from(authors).columns("name"); // [!code focus] ``` You can also get [entity references](query-execution#entity-refs) from the result of a CDS QL statement to address an entity via its key values in other statements. diff --git a/java/remote-services.md b/java/remote-services.md index 601d2cff4..2d2f0acc5 100644 --- a/java/remote-services.md +++ b/java/remote-services.md @@ -120,10 +120,6 @@ In this case, the destination with name `s4-business-partner-api` would be obtai Given that this destination holds the URL `https://s4.sap.com`, the resulting service URL for OData requests would be `https://s4.sap.com/sap/opu/odata/sap/API_BUSINESS_PARTNER`. The `type` property defines the protocol used by the remote API. The CAP Java SDK currently supports `odata-v4` (default) or `odata-v2`. -::: warning -When using SAP S/4HANA On-Premise via Cloud Connector with a non-default sap-client, you might observe 401 Unauthorized errors. -This is a known issue and can be avoided by adding an additional property `URL.headers.sap-client` with the value of the sap-client to the destination in the SAP BTP Destination Service's configuration. -::: #### Configuring Destination Strategies @@ -279,36 +275,27 @@ DefaultHttpDestination #### OAuth2 Client Credentials { #oauth2-client-credentials} ```java -DefaultHttpDestination httpDestination = DefaultHttpDestination - .builder("https://example.org") - .name("my-destination").build(); - ClientCredentials clientCredentials = new ClientCredentials("clientid", "clientsecret"); -ClientCredentialsHttpDestination clientCredentialsHttpDestination = - new ClientCredentialsHttpDestination( - httpDestination, - clientCredentials, - URI.create("https://xsuaa.url"), - new XsuaaService() - ); + +OAuth2DestinationBuilder + .forTargetUrl("https://example.org") + .withTokenEndpoint("https://xsuaa.url") + .withClient(clientCredentials, OnBehalfOf.TECHNICAL_USER_CURRENT_TENANT) + .withProperties(Map.of("name", "my-destination")) + .build(); ``` #### User Token Authentication { #user-token-authentication} ```java -DefaultHttpDestination httpDestination = DefaultHttpDestination - .builder("https://example.org") - .name("my-destination").build(); - ClientCredentials clientCredentials = new ClientCredentials("clientid", "clientsecret"); -ClientCredentialsHttpDestination clientCredentialsHttpDestination = - new ClientCredentialsHttpDestination( - httpDestination, - clientCredentials, - ClientCredentialsGrantType.USER_TOKEN, - URI.create("https://xsuaa.url"), - new XsuaaService() - ); + +OAuth2DestinationBuilder + .forTargetUrl("https://example.org") + .withTokenEndpoint("https://xsuaa.url") + .withClient(clientCredentials, OnBehalfOf.NAMED_USER_CURRENT_TENANT) + .withProperties(Map.of("name", "my-destination")) + .build(); ```