CascadeFetch is an OCL operator for ViewModel authors who need to load an object's composite aggregate before an operation such as delete.
What CascadeFetch does
CascadeFetch follows associations marked as composite aggregations and makes sure that the objects in that aggregate are loaded.
The operator returns an integer: the number of objects included in the aggregate.
For example, if an object has composite aggregation associations to related objects, CascadeFetch loads the aggregate reachable through those composite associations and returns the number of included objects. Use the returned number when you need to display or inspect the aggregate size; use the loading effect when a later operation needs the aggregate available.
Use CascadeFetch before deleting an aggregate
Use CascadeFetch when a ViewModel will delete an object with many composite aggregations. Loading the aggregate first lets the query planner fetch the required objects in as few roundtrips as possible.
Without this preparation, a delete action can trigger lazy loading while it runs. When the aggregate contains many related objects, that loading can occur one object at a time.
- Identify the object that the ViewModel will delete.
- Identify the associations from that object that are marked as composite aggregations.
- Add CascadeFetch as an OCL column in the ViewModel for the object before the delete is performed.
- Evaluate the column so that the composite aggregate is loaded.
- Perform the delete action.
Example scenario
Assume a ViewModel deletes an object that owns a large composite aggregate. Add a CascadeFetch OCL column for that object before the delete action. The column evaluates CascadeFetch, loads the objects included through the composite aggregations, and returns their count. The subsequent delete works against the already loaded aggregate instead of causing cold lazy loading during the action.
Return value
| Result | Meaning |
|---|---|
| Integer | The number of objects included in the aggregate followed by CascadeFetch. |
Do not treat the integer as the loaded objects themselves. The purpose of the operator is to ensure loading; the integer reports how many objects are included.
When to use it
Use CascadeFetch when all of the following apply:
- A ViewModel will perform an operation, especially a delete.
- The target object has many related objects through composite aggregations.
- You want the query planner to prepare the aggregate before the operation rather than allow lazy loading during it.
Scope and limitations
CascadeFetch follows associations marked as composite aggregations. It is not described as a general fetch for every association on an object. Ensure that the associations whose objects must be loaded are modeled as composite aggregations before relying on CascadeFetch.
The available sources do not document the exact OCL expression syntax for invoking CascadeFetch. Use the OCL editor to inspect available operators for the relevant class, as described in Documentation:OCL General Operators.
