-
Notifications
You must be signed in to change notification settings - Fork 166
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
Conversation
@@ -991,21 +990,18 @@ public void registerIdGenerationStrategy(IdStrategy strategy) { | |||
} | |||
} | |||
|
|||
public MethodInfo postLoadMethodOrNull() { | |||
public synchronized MethodInfo postLoadMethodOrNull() { | |||
if (isPostLoadMethodMapped) { |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
13f8fa4
to
5c65222
Compare
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.
5c65222
to
27b3123
Compare
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
@PostLoad
s semantics identical to@PostConstruct
from JSR-250.