Java: Views and Projections#1916
Conversation
|
Overall, LGTM. It is nice that we explain this stuff. |
|
@MattSchur Are all comments addressed and can we review and merge? |
| ::: tip Prefer simple views | ||
| Prefer creating multiple simple views, each tailored to a specific use case, rather than a single complex view that tries to address multiple use cases simultaneously. | ||
| ::: |
There was a problem hiding this comment.
I think this rather belongs to the best practices
|
|
||
| To add or update CDS views without redeploying the database schema, annotate them with [@cds.persistence.skip](../../guides/databases#cds-persistence-skip). This tells the CDS compiler to skip generating database views for these CDS views, and the CAP Java runtime resolves them dynamically on each request. | ||
|
|
||
| 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. |
There was a problem hiding this comment.
Runtime views may use only CDS QL, which is supported by the CAP Java runtime. Joins and unions are not supported. We have more restrictions in the "resolve" mode. The "cte" mode is more powerful.
|
Maybe an overview table would be helpful to list which "features" can be used with
|
Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
| ::: warning Avoid selecting to-many Associations | ||
| Do not use [*to-many associations*](../../cds/cdl#to-many-associations) in the select clause of CDS views. This blocks write operations and may cause performance issues due to record duplication on read. | ||
| ::: tip Prefer simple views | ||
| Prefer creating multiple simple views, each tailored to a specific use case, rather than a single complex view that tries to address multiple use cases simultaneously. |
There was a problem hiding this comment.
agoerler
left a comment
There was a problem hiding this comment.
Looks good to me. Please consider to add some suggestions to https://pages.github.tools.sap/cap/docs/about/best-practices#best-practices-by-cap
(in a different PR)
@renejeglinsky Yes, please review and merge |
| ::: warning Avoid Composition Definitions in Views | ||
| Avoid [defining](../../cds/cql#association-definitions) new *compositions* in CDS views and prefer *associations* instead, as [deep write](#updatable-views) and [cascading delete](#delete-via-view) are only supported for compositions in persistence entities. |
There was a problem hiding this comment.
| ::: warning Avoid Composition Definitions in Views | |
| Avoid [defining](../../cds/cql#association-definitions) new *compositions* in CDS views and prefer *associations* instead, as [deep write](#updatable-views) and [cascading delete](#delete-via-view) are only supported for compositions in persistence entities. | |
| ::: warning Avoid composition definitions in views | |
| Do not [define](../../cds/cql#association-definitions) *compositions* in CDS views and prefer *associations* instead, to avoid [cascading over associations](#cascading-over-associations). |
There was a problem hiding this comment.
It's not about avoiding cascading over associations but deep write and cascade delete are not supported by the runtime for such compositions and would need to be handled by custom code.
…into write-through-views
Introduces "Views and Projections" section with
and documents some rules for write via path expressions in views.
Also shortens some headers to improve the readability in the navigation bar.