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

GH-516 - Improve support for @PostLoad annotation. #517

Merged
merged 2 commits into from
Sep 4, 2018
Merged

Conversation

michael-simons
Copy link
Collaborator

@michael-simons michael-simons commented Sep 3, 2018

Please see messages of the two separate commits for the details. I have incorporated @jdorleans PR #485 for #414 and added our discussion to make @PostLoads semantics identical to @PostConstruct from JSR-250.

@@ -991,21 +990,18 @@ public void registerIdGenerationStrategy(IdStrategy strategy) {
}
}

public MethodInfo postLoadMethodOrNull() {
public synchronized MethodInfo postLoadMethodOrNull() {
if (isPostLoadMethodMapped) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will never get true...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤦‍♂️

}
return null;

this.postLoadMethod = possiblePostLoadMethods.stream().findFirst().orElse(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Setting an instance variable and returning it afterwards looks like either the calling part uses this method wrong and/or this method has multiple purposes.
Additionally the mixed usage of this and without it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept the method the way it was (mainly), but indeed, better split it like the other initXXX methods.

return new ObjectAnnotations(annotationInfo);
}

private final Map<String, AnnotationInfo> annotations;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Even if the above is a static method I would, at least, suggest to move this above. The other class that gets the of builder method also keeps it fields on top.

…Construct.

Forcing the PostLoad method to be public and non final leads to poor domain classes:
- often the postload method is also used from the constructor, so they should be at least final so that the class can be safely overwritten
- also postload should usually not be an exposed method to calling code, it’s used to be only internal

Steps taken:
- Include „final“ methods in MethodsInfo.
- When postload is executed, check if the annotated method is accessible. If not, try to make it accessible.
This changes the way `@PostLoad` methods are computed:
- Don’t store MethodInfo by their name but by their method, as the name is not even unique per class
- Traverse class hierarchy for method infos and prioritize lower class methods
- Make sure that no ambigious scenerio can be created with multiple `@PostLoad` methods.
@meistermeier meistermeier merged commit 51ba9fb into master Sep 4, 2018
@meistermeier meistermeier deleted the issue/516 branch September 4, 2018 12:57
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.

2 participants