Improved consistency in writing Util classes and removed raw types to make types more stable #3408
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello.
I've been putting your
Spring Data JPA
to good use in my practice.I've modified & improved the code of a few classes to create a PR and upload it.
Below are the classes I worked on and the reasons for the changes.
PageableUtils.java
The abstract keyword is used to emphasize that the utility class does not need to be instantiated.
Meta.java
We changed values in the Meta class because it is a private field that is only used internally and it is better to initialize it with a LinkedHashMap beforehand instead of checking if the element is empty every time setValue is called and initializing it with a LinkedHashMap.
NamedQuery.java
Since EntityManager implements the AutoCloseable interface, it is better to use try-with-resources rather than explicitly calling close in the finally block after using resources, so we modified the code.
JsqlParserUtils.java
Since the JSqlPaserUtils class is also a Util class, we clarified the semantics with the abstract keyword and modified the private constructor to throw the same exception to be consistent with PageableUtils.
The getJsqlCount and getJsqlLower methods are using ExpressionList as a raw type, but ExpressionList only allows classes that implement the Expression interface, and the withParameters method of Function class is only used by JsqlParserUtils, so we changed it to a type-safe code that uses Generic.