You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: cds/cdl.md
+44Lines changed: 44 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -856,7 +856,51 @@ Result result = service.run(Select.from("UsingView"), params);
856
856
[Learn more about how to expose views with parameters in **Services - Exposed Entities**.](#exposed-entities){ .learn-more}
857
857
[Learn more about views with parameters for existing HANA artifacts in **Native SAP HANA Artifacts**.](../advanced/hana){ .learn-more}
858
858
859
+
### Runtime Views { #runtimeviews }
859
860
861
+
To add or update CDS views without redeploying the database schema, annotate them with [@cds.persistence.skip](../guides/databases#cds-persistence-skip). This advises the CDS compiler to skip generating database views for these CDS views. Instead, CAP resolves them *at runtime* on each request.
862
+
863
+
Runtime views must be simple [projections](#as-projection-on), not using *aggregations*, *join*, *union* or *subqueries* in the *from* clause, but may have a *where* condition if they are only used to read.
864
+
865
+
In CAP Java, runtime views are enabled by default, in Node.js enable them via <Config>cds.features.runtime_views: true</Config>.
866
+
867
+
[Learn more about runtime views in CAP Java.](../java/working-with-cql/query-execution#runtimeviews) {.learn-more}
868
+
869
+
By default, runtime views are translated into _Common Table Expressions_ (CTEs) and sent with the query to the database.
870
+
871
+
For example, given the following CDS model and query:
872
+
873
+
```cds
874
+
entity Books {
875
+
key ID : UUID;
876
+
title : String;
877
+
stock : Integer;
878
+
author : Association to one Authors;
879
+
}
880
+
@cds.persistence.skip
881
+
entity BooksWithLowStock as projection on Books {
882
+
ID, title, author.name as author
883
+
} where stock < 10; // makes the view read only
884
+
```
885
+
```sql
886
+
SELECTfrom BooksWithLowStock where author ='Kafka'
887
+
```
888
+
889
+
The runtime translates the view definition into a _Common Table Expression_ (CTE) and sends it with the query to the database.
Copy file name to clipboardExpand all lines: java/working-with-cql/query-execution.md
+7-39Lines changed: 7 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -321,13 +321,12 @@ The delete operation is resolved to the underlying `Order` entity with ID *42* a
321
321
322
322
### Runtime Views { #runtimeviews }
323
323
324
-
To add or update CDS views without redeploying the database schema, annotate them with [@cds.persistence.skip](../../guides/databases#cds-persistence-skip). This advises the CDS compiler to skip generating database views for these CDS views. Instead, CAP Java resolves them *at runtime* on each request.
325
324
326
-
Runtime views must be simple [projections](../../cds/cdl#as-projection-on), not using *aggregations*, *join*, *union* or *subqueries* in the *from* clause, but may have a *where* condition if they are only used to read. On write, the restrictions for [write through views](#updatable-views) apply in the same way as for standard CDS views. However, if a runtime view cannot be resolved, a fallback to database views is not possible, and the statement fails with an error.
325
+
CAP Java provides two modes for resolving [runtime views](../cds/cdl#runtimeviews) during read operations: [cte](#rtview-cte)and [resolve](#rtview-resolve).
327
326
328
-
CAP Java provides two modes for resolving runtime views during read operations: [cte](#rtview-cte)and [resolve](#rtview-resolve).
327
+
On write, the restrictions for [write through views](#updatable-views) apply in the same way as for standard CDS views. However, if a runtime view cannot be resolved, a fallback to database views is not possible, and the statement fails with an error.
329
328
330
-
::: details Changing the runtime view mode
329
+
::: details Changing the runtime view read mode
331
330
To globally set the runtime view mode, use the property `cds.sql.runtimeView.mode` with value `cte` (the default) or `resolve` in the *application.yml*. To set the mode for a specific runtime view, annotate it with `@cds.java.runtimeView.mode: cte|resolve`.
332
331
333
332
To set the mode for a specific query, use a [hint](#hana-hints):
The next two sections introduce both modes using the following CDS model and query:
341
-
342
-
```cds
343
-
entity Books {
344
-
key ID : UUID;
345
-
title : String;
346
-
stock : Integer;
347
-
author : Association to one Authors;
348
-
}
349
-
@cds.persistence.skip
350
-
entity BooksWithLowStock as projection on Books {
351
-
ID, title, author.name as author
352
-
} where stock < 10; // makes the view read only
353
-
```
354
-
```sql
355
-
SELECTfrom BooksWithLowStock where author ='Kafka'
356
-
```
357
-
358
-
359
339
#### Read in `cte` mode { #rtview-cte }
360
340
361
-
This is the default mode since CAP Java `4.x`. The runtime translates the [view definition](#runtimeviews) into a _Common Table Expression_ (CTE) and sends it with the query to the database.
362
-
363
-
```sql
364
-
WITH BOOKSWITHLOWSTOCK_CTE AS (
365
-
SELECTB.ID,
366
-
B.TITLE,
367
-
A.NAMEAS"AUTHOR"
368
-
FROM BOOKS B
369
-
LEFT OUTER JOIN AUTHOR A ONB.AUTHOR_ID=A.ID
370
-
WHEREB.STOCK<10
371
-
)
372
-
SELECT ID, TITLE, AUTHOR AS"author"
373
-
FROM BOOKSWITHLOWSTOCK_CTE
374
-
WHEREA.NAME= ?
375
-
```
341
+
In [cte mode](../cds/cdl#runtimeviews), the runtime translates the view definition into a _Common Table Expression_ (CTE) and sends it with the query to the database. This is the default mode since CAP Java `4.x`.
376
342
377
343
::: tip CAP Java 3.10
378
344
Enable *cte* mode with *cds.sql.runtimeView.mode: cte*
379
345
:::
380
346
381
347
#### Read in `resolve` mode { #rtview-resolve }
382
348
383
-
The runtime _resolves_ the [view definition](#runtimeviews) to the underlying persistence entities and executes the query directly against the corresponding tables.
349
+
In `resolve` mode, the runtime _resolves_ the view definition to the underlying persistence entities and executes the query directly against the corresponding tables.
350
+
351
+
For example, the [view definition](../cds/cdl#runtimeviews) is resolved into the following SQL statement:
0 commit comments