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

Migrate UserType implementations to hibernate 6 #40

Merged
merged 26 commits into from
Oct 8, 2024
Merged

Migrate UserType implementations to hibernate 6 #40

merged 26 commits into from
Oct 8, 2024

Conversation

Laurens-W
Copy link
Contributor

Anything in particular you'd like reviewers to focus on?

Test coverage

Anyone you would like to review specifically?

@timtebeek

Any additional context

https://docs.jboss.org/hibernate/orm/5.6/javadocs/org/hibernate/usertype/UserType.html
https://docs.jboss.org/hibernate/orm/6.0/javadocs/org/hibernate/usertype/UserType.html

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@Laurens-W Laurens-W self-assigned this Oct 3, 2024
@Laurens-W Laurens-W added the enhancement New feature or request label Oct 3, 2024
Laurens-W and others added 3 commits October 3, 2024 17:08
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment on lines 55 to 56
@Nullable
private static J.FieldAccess parameterizedType = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Mutable static fields in a recipe are not ideal; can we move this field into the visitor instead? As each call the getVisitor returns a new isolated instance, whereas the Recipe instance can be shared.

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
@Nullable
private static J.FieldAccess parameterizedType = null;

Choose a reason for hiding this comment

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

Maybe we should check if we have any legitimate cases of this. If not, we can add a best practice recipe, maybe?

Order methodmatchers alphabetically
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/hibernate/EmptyInterceptorToInterface.java
    • lines 28-29

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/hibernate/EmptyInterceptorToInterface.java
    • lines 28-28
  • src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java
    • lines 29-29

private static final MethodMatcher REPLACE = new MethodMatcher("* replace(java.lang.Object, java.lang.Object, java.lang.Object)");
private static final MethodMatcher RESULT_SET_STRING_PARAM = new MethodMatcher("java.sql.ResultSet *(java.lang.String)");
private static final MethodMatcher RETURNED_CLASS = new MethodMatcher("* returnedClass()");
private static final MethodMatcher SQL_TYPES = new MethodMatcher("* sqlTypes()");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we equally use org.hibernate.usertype.UserType here instead of *?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I'm using them to match method declarations it seems you can only really use a wildcard pattern or the type of the enclosing J.ClassDeclaration

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Some suggestions could not be made:

  • src/main/java/org/openrewrite/hibernate/EmptyInterceptorToInterface.java
    • lines 28-28
  • src/main/java/org/openrewrite/hibernate/ReplaceLazyCollectionAnnotation.java
    • lines 29-29

return maybeAutoFormat(method, md, ctx);
}

private J.MethodDeclaration changeParameterTypes(J.MethodDeclaration md, List<String> paramNames) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Matching on parameter names isn't safe here, as folks might have named their variables differently; I suggest you change this to use the parameter index instead, or another way of ensuring only the correct types are changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied parameter index instead of name

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

The paramNames variable isn't safe; let's change that first.

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

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

Great to see! I've applied some simplifications and best practices; let's see how this holds up against older code bases. 🤞🏻

@timtebeek timtebeek merged commit 1b924b0 into main Oct 8, 2024
2 checks passed
@timtebeek timtebeek deleted the usertype branch October 8, 2024 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants