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

Typeful Metadata #2258

Open
homedirectory opened this issue May 13, 2024 · 0 comments
Open

Typeful Metadata #2258

homedirectory opened this issue May 13, 2024 · 0 comments

Comments

@homedirectory
Copy link
Contributor

Description

Completing the transition from EQL2 metadata to EQL3 metadata has posed some challenges due to
structural differences between the two. In particular, EQL3 metadata is less rich than its
predecessor, which requires its users to perform ad-hoc computations to retrieve the needed
information (e.g., to check whether a property represents a composite key), ultimately decreasing
the usefulness of the abstraction.

Historically, EQL metadata has been modelled with a simple abstraction -- a bag of attributes, i.e.,
a single Java class with multiple null-able fields.
For example, metadata for entity properties has been modelled with a single class that has both
column and expressionModel fields with the former indicating a persistent nature and the latter
-- a calculated one. Since a property may have only one nature, only one of these fields may have a
non-null value in any given instance.

While such a simple abstraction may have been sufficient previously, the evolution of TG and its
modelling capabilities requires a more powerful abstraction to tackle the growing complexity.
Therefore, a typeful model for EQL metadata is proposed. Such model is based on the use of type
information, and provides stronger guarantees in the form of static properties of the program.
This model heavily relies on typechecking, which the Java compiler provides. Some of the
advantageous features supported by Java 21 are: sealed classes (can be used to model ADTs) and
pattern matching.

In a typeful model, types are used to represent domain concepts. In this case the primary concepts
are entities and their properties, which can be classified into several categories and modelled with
types accordingly (consult the TG Wiki for details).

Expected outcome

Typeful metadata abstraction is introduced to assist with completing the migration to EQL3 metadata.

Implementation

Inspiration can be drawn from the mirror-based API for Java annotation processing (javax.lang.model),
which has separated types into 2 levels: elements (TypeElement) and types (TypeMirror). The
same could be applied to TG metadata: elements -- entity and composite type definitions, types -- property types.
The latter (types) use the former (elements) and optionally include annotations for the purpose of
refinement. For example, numeric types can be refined by specifying their precision and scale.

@homedirectory homedirectory self-assigned this May 13, 2024
@homedirectory homedirectory changed the title Typeful metadata Typeful Metadata May 13, 2024
homedirectory added a commit that referenced this issue May 14, 2024
homedirectory added a commit that referenced this issue May 14, 2024
These predicates are preferred over "instanceof" statements.
homedirectory added a commit that referenced this issue May 14, 2024
homedirectory added a commit that referenced this issue May 14, 2024
…data

Injection of the metadata service is yet to be implemented.
homedirectory added a commit that referenced this issue May 15, 2024
homedirectory added a commit that referenced this issue May 15, 2024
This change has the following effects:
1. Types become more concise, thus code becomes more readable.
2. Pattern matching with switch can be used, because type parameters
   were replaced by subinterfaces.
3. The type of data() is now known when the type of nature() is.
4. Temporarily disable nature-specific keys for property metadata.
   They haven't been used yet, so this doesn't break anything.
homedirectory added a commit that referenced this issue May 15, 2024
In the same fasion as PropertyMetadata had been refactored.
homedirectory added a commit that referenced this issue May 16, 2024
homedirectory added a commit that referenced this issue May 31, 2024
The semantics of method `otherwise` are that of "default value" but that
requires it to always be implemented even when all other visiting
methods are implemented as well -- not nice.

This visitor is not currently used at all, so this change is OK, and
another visitor with "default value" method can be introduced any time.
homedirectory added a commit that referenced this issue May 31, 2024
IDE showed no usages at the platform level so I deleted it, but there
are usages in TG applications.
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
…oxied entity types

Since Typeful Metadata is generated for a larger set of properties than
EQL3 metadata, more exhaustive filters are required.
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
…ies to generate metadata for property "version"

It is not clear why a more specific predicate (targeting only the
superclass) had been used, but the incosistencies it could result in
don't make a lot of sense (e.g., generated types based on
synthetic-based-on-persistent would lack metadata for "version").
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
homedirectory added a commit that referenced this issue Jun 5, 2024
…-on-persistent entity types

Consider the whole type hierarchy, not just the superclass.
homedirectory added a commit that referenced this issue Jun 5, 2024
…ut a DB table

During migration to Typeful Metadata the algorithm has been incorrecly
understood and table name existence became a strict constraint.
homedirectory added a commit that referenced this issue Jun 6, 2024
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