Skip to content
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

Formalisation of fetch models #2313

Open
2 tasks done
homedirectory opened this issue Sep 11, 2024 · 0 comments
Open
2 tasks done

Formalisation of fetch models #2313

homedirectory opened this issue Sep 11, 2024 · 0 comments

Comments

@homedirectory
Copy link
Contributor

homedirectory commented Sep 11, 2024

Description

The concept of fetch models in TG is fairly sophisticated, requiring a thorough analysis of the source code to be understood.
The goal of this issue is to create a specification for fetch models, so that they can be understood more easily by both platform and application developers.

  • Document each fetch model category (ua.com.fielden.platform.entity.query.fluent.fetch.FetchCategory).
  • Document any special cases that may occur during fetch model processing.

Expected outcome

Fetch models are properly documented, facilitating informal reasoning for developers.

Technical details

There are 3 core abstractions related to fetch models:

  • ua.com.fielden.platform.entity.query.fluent.fetch - used to specify a fetch model for an EQL query;
  • ua.com.fielden.platform.entity.fetch.IFetchProvider - primarily used by entity companions and Web UI; ultimately gets converted to a fetch via method fetchModel(); was introduced by Entity Fetch Strategy #120 with a goal to have a developer-friendly API;
  • ua.com.fielden.platform.entity.query.IRetrievalModel - implementation-side representation of fetch models, used by the EQL engine.

To maximise visibilty of documentation, it is proposed to attach it to the fetch class, which can be referred to by IFetchProvider. IRetrievalModel is located in a different module, in platform-dao, and can't be referenced by the other two, which are located in platform-pojo-bl, but that is not a problem since IRetrievalModel is not directly visible to developers anyway.

Change overview

  • Documentation for retrieval models (IRetrievalModel and its implementations).
  • Documentation of EQL-specific metadata (QuerySourceInfoProvider).
  • Retrieval model construction now has access to QuerySourceInfoProvider, which enables it to determine whether property id (any property, in general) should be included for any given synthetic entity type. This simplifies the implementation by using a proper abstraction (QuerySourceInfoProvider) instead of having to handle each property by hand.
  • Properties id, key and version are assigned plain nature when generating metadata for synthetic entities. Previously, they could be assigned persistent nature, which doesn't make sense for synthetic entities.
  • Additonal method signature: fetch.with(CharSequence, CharSequence...) for convenience of specifying multiple properties (equivalent change was made for method without).
  • Improved string representation for fetch and EntityRetrievalModel.
  • Removed IRetrievalModel.containsOnlyTotals, since property id doesn't need special handling during yield enhancement in synthetic entities.
  • Introduced utilities for immutable collections (ImmutableCollectionUtil) and maps (ImmutableMapUtils).
  • Documentation for fetch categories (in TG Wiki and javadoc).
  • Stricter validation of synthetic models: it is an error if there is a yield that uses a non-existent property as an alias.
  • Enabled the use of a source query which models its result as EntityAggregates and uses yieldAll. Such queries had not been expected and thus had been unsupported.

Required changes in TG applications

  • Identify and correct synthetic models that yield into non-existing properties.
@homedirectory homedirectory self-assigned this Sep 11, 2024
homedirectory added a commit that referenced this issue Sep 11, 2024
homedirectory added a commit that referenced this issue Sep 11, 2024
* Remove base superclass AbstractRetrievalModel.
* Make classes immutable by using a builder for initialisation.
* As a result of the former, shed some unnecessary fields.
homedirectory added a commit that referenced this issue Sep 11, 2024
The concept of retrievability should be easier to comprehend than its
negation (for some reason named "purity").
@homedirectory homedirectory added this to the 2.0.0 milestone Sep 13, 2024
homedirectory added a commit that referenced this issue Sep 16, 2024
homedirectory added a commit that referenced this issue Sep 16, 2024
homedirectory added a commit that referenced this issue Sep 19, 2024
* Perform lazy instantiation of the parameters map in the builder
* Documentation for all nullable values
* Documentation for methods and classes
homedirectory added a commit that referenced this issue Sep 19, 2024
…nted

This will allow us to better understand if and when such cases occur.
homedirectory added a commit that referenced this issue Sep 19, 2024
QueryExecutionModel is immutable.
homedirectory added a commit that referenced this issue Oct 1, 2024
This predicate is no longer needed as QuerySourceInfo is used for the
same filtering effect.
Semantics of this predicate are replicated in
QuerySourceInfoProvider.generateQuerySourceItems.
homedirectory added a commit that referenced this issue Oct 1, 2024
New tests:
* Fetching of "id" in synthetic entities.
* Fetching of calculated properties.
* Fetching of composite key and its members.

The change to QuerySourceInfoProvider facilitates usage of test entity
types, and also hardens the implementation by generating models on
demand instead of returning null which would lead to NPE.
homedirectory added a commit that referenced this issue Oct 2, 2024
…uring yields enhancement

The FIXME is resovled: retrieval models now recognise presence of ID in
synthetic entities.

As IRetrievalModel.containsOnlyTotals had been introduced only for the
purpose of special handling of ID, it is no longer needed as well.
homedirectory added a commit that referenced this issue Oct 2, 2024
Optional.filter().isPresent() is more efficient than Optional.map()
because it doesn't perform allocation.
homedirectory added a commit that referenced this issue Oct 2, 2024
Introduce method signature with(propName) which explores entities by
default. This change does not affect semantics.

         private void includeAllCompositeKeyMembers() {
             entityMetadataUtils.compositeKeyMembers(entityMetadata)
-                    .forEach(pm -> with(pm.name(), !pm.type().isEntity()));
+                    .forEach(pm -> with(pm.name()));
         }

The above piece is also unaffected, as entity exploration skipping would
have been true only for non-entity typed properties...
homedirectory added a commit that referenced this issue Oct 2, 2024
Optional.filter().isPresent() is more efficient than Optional.map()
because it doesn't perform allocation.
homedirectory added a commit that referenced this issue Oct 3, 2024
homedirectory added a commit that referenced this issue Oct 3, 2024
It had already been effectively immutable due to the use of method
`copy` but still used mutable data structures for internal state, which
was not a strong invariant.
homedirectory added a commit that referenced this issue Oct 8, 2024
homedirectory added a commit that referenced this issue Oct 8, 2024
… property

The main change is in Source1BasedOnQueries.produceQuerySourceInfoForEntityType.

Implementin this required IDomainMetadata to be accessible to
Source1BasedOnQueries. Its `transform` method takes a
TransformationContextFromStage1To2 as an argument, so I considered it
reasonable to enhance that type with a IDomainMetadata component. The
bulk of changes is related to this enhancement.
homedirectory added a commit that referenced this issue Oct 8, 2024
Prior to this change, the following example query would have failed:

select(select(Vehicle.class).yieldAll().modelAsAggregate())
    .yield().prop("id").as("id")
    .modelAsEntity(Vehicle.class)
homedirectory added a commit that referenced this issue Oct 8, 2024
QuerySourceInfoProvider is more suited to contain this method as it is
similar to other methods declared by it - most of them produce instances
of QuerySourceInfo.
homedirectory added a commit that referenced this issue Oct 8, 2024
homedirectory added a commit that referenced this issue Oct 8, 2024
homedirectory added a commit that referenced this issue Oct 8, 2024
And the returned null wasn't being handled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant