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

remove requirement that JD providers init user-written metamodel #567

Merged
merged 2 commits into from
Mar 22, 2024

Conversation

gavinking
Copy link
Contributor

As discussed on today's call, in the interest of quickly delivering compatible implementations, this PR removes a requirement on providers that we don't think is really that needed.

(at least for now)

this makes JD slightly easier to implement
Copy link
Contributor

@njr-11 njr-11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why some language for volatile and initialization by Jakarta Data providers was left around. Otherwise, the approach of the user-defined classes making use of the built-in attribute classes works well. The impl classes could potentially even be collapsed with the interface into a single class for simplicity.

Comment on lines +96 to +101
* <p>Alternatively, an annotation processor might generate static metamodel classes
* for entities at compile time. The generated classes must be annotated with the
* {@link jakarta.annotation.Generated @Generated} annotation. The fields may be
* statically initialized, or they may be initialized by the provider during system
* initialization. In the first case, the fields are declared {@code final}. In the
* second case, the fields are declared non-{@code final} and {@code volatile}.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the point of this pull was to remove having providers initialize the static metamodel, but the middle of this paragraph creates the expectation that they will still do that.

Suggested change
* <p>Alternatively, an annotation processor might generate static metamodel classes
* for entities at compile time. The generated classes must be annotated with the
* {@link jakarta.annotation.Generated @Generated} annotation. The fields may be
* statically initialized, or they may be initialized by the provider during system
* initialization. In the first case, the fields are declared {@code final}. In the
* second case, the fields are declared non-{@code final} and {@code volatile}.</p>
* <p>Alternatively, an annotation processor might generate static metamodel classes
* for entities at compile time. The generated classes must be annotated with the
* {@link jakarta.annotation.Generated @Generated} annotation. The fields must be
* statically initialized and must be declared {@code final}.</p>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph is dealing with provider-generated models, not user-written models. The idea of the pull is to relax the requirement that the provider initialize user-written models.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize we were offering the deferred initialization pattern to provider-generated models prior to this pull. I suppose we never explicitly said they could not do it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed we allowed it as an option I guess partly because that's how it works in JPA.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I don't see a reason to disallow it.)

Comment on lines 102 to 103
*
* <p>In cases where multiple Jakarta Data providers provide repositories for the same
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer applies

Suggested change
*
* <p>In cases where multiple Jakarta Data providers provide repositories for the same

Comment on lines +104 to +106
* entity type, no guarantees are made of the order in which the Jakarta Data providers
* attempt to initialize the fields of the static metamodel class for that entity.</p>
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer applies because Jakarta Data providers don't initialize the static metamodel anymore

Suggested change
* entity type, no guarantees are made of the order in which the Jakarta Data providers
* attempt to initialize the fields of the static metamodel class for that entity.</p>
*


For each entity class for which the application wishes to request the metamodel,
- The metamodel class must be annotated with `@StaticMetamodel`, specifying the entity class as its `value`.
- The metamodel class contains one or more `public static` fields corresponding to persistent fields of the entity class.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- The metamodel class contains one or more `public static` fields corresponding to persistent fields of the entity class.
- The metamodel class contains one or more `public static final` fields corresponding to persistent fields of the entity class.

Comment on lines +609 to +610
- each field corresponding to a persistent field of an entity must have modifiers `public`, `static`, and either `final` or `volatile`,
- the name of each field, ignoring case, must match the name of an entity attribute, according to the conventions specified below in <<Conventions for Metamodel Fields>>, and with the `_` character in the field name delimiting the attribute names of hierarchical structures or relationships, such as embedded classes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- each field corresponding to a persistent field of an entity must have modifiers `public`, `static`, and either `final` or `volatile`,
- the name of each field, ignoring case, must match the name of an entity attribute, according to the conventions specified below in <<Conventions for Metamodel Fields>>, and with the `_` character in the field name delimiting the attribute names of hierarchical structures or relationships, such as embedded classes.
- each field corresponding to a persistent field of an entity must have modifiers `public`, `static`, and `final`,
- the name of each field, ignoring case, must match the name of an entity attribute, according to the conventions specified below in <<Conventions for Metamodel Fields>>, and with the `_` character in the field name delimiting the attribute names of hierarchical structures or relationships, such as embedded classes.


The Jakarta Data provider observes classes that are annotated with the `@StaticMetamodel` annotation where the `jakarta.annotation.Generated` is not also present. If the `value` of the `@StaticMetamodel` annotation is an entity class for which the Jakarta Data provides a repository implementation, then the Jakarta Data provider must initialize the value of each uninitialized (`null` valued) field that meets the criteria that is defined in the "Application Requirements for a Metamodel Class" above.
The fields may be statically initialized, or they may be initialized by the provider during system initialization.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The fields may be statically initialized, or they may be initialized by the provider during system initialization.
The fields must be statically initialized.

spec/src/main/asciidoc/repository.asciidoc Outdated Show resolved Hide resolved
spec/src/main/asciidoc/repository.asciidoc Outdated Show resolved Hide resolved
@gavinking
Copy link
Contributor Author

I don't see why some language for volatile and initialization by Jakarta Data providers was left around.

I was trying to leave open the possibility that a Jakarta Data provider be permitted to initialize an annotation processor-generated model at runtime, without requiring that a provider be able to do that.

It's not for user-written models.

@otaviojava
Copy link
Contributor

I don't see why some language for volatile and initialization by Jakarta Data providers was left around.

I was trying to leave open the possibility that a Jakarta Data provider be permitted to initialize an annotation processor-generated model at runtime, without requiring that a provider be able to do that.

It's not for user-written models.

As you know, I am not a relational database person, but I have never seen a user doing it manually. Thus, it is fine to not allow users to write it by bare hand.

BTW: Can Jakarta Persistence do it manually?

@gavinking
Copy link
Contributor Author

I have never seen a user doing it manually.

Nor have I.

Thus, it is fine to not allow users to write it by bare hand.

That is also perfectly fine by me, FTR, though it wasn't the goal of this PR.

Can Jakarta Persistence do it manually?

Yes, JPA in principle lets the user write it.

@gavinking
Copy link
Contributor Author

@otaviojava?

@otaviojava otaviojava merged commit d376ef3 into jakartaee:main Mar 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants