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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

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>
void shouldMigrateUserType() {
//language=java
rewriteRun(
spec -> spec.expectedCyclesThatMakeChanges(2),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we fix the recipe such that we don't need this escape hatch, as we'd love to drop that in a next major version. Did you explore why this was needed in the first place?

Suggested change
spec -> spec.expectedCyclesThatMakeChanges(2),

import org.openrewrite.java.JavaVisitor;
import org.openrewrite.java.MethodMatcher;
import org.openrewrite.java.search.UsesType;
import org.openrewrite.java.tree.*;
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
import org.openrewrite.java.tree.*;
import org.openrewrite.java.tree.Expression;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.ControlParentheses;
import org.openrewrite.java.tree.JRightPadded;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.Space;
import org.openrewrite.java.tree.Statement;
import org.openrewrite.java.tree.TypeTree;
import org.openrewrite.java.tree.TypeUtils;

Comment on lines +65 to +66
return "With hibernate 6 the UserType interface received a type parameter making it more strictly typed" +
"This recipe applies the changes required to adhere to this change.";
Copy link
Contributor

@timtebeek timtebeek Oct 6, 2024

Choose a reason for hiding this comment

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

Be careful when you join strings; this would look odd in the docs without . in between.

Suggested change
return "With hibernate 6 the UserType interface received a type parameter making it more strictly typed" +
"This recipe applies the changes required to adhere to this change.";
return "With Hibernate 6 the `UserType` interface received a type parameter making it more strictly typed. " +
"This recipe applies the changes required to adhere to this change.";

Comment on lines +42 to +53
private static final MethodMatcher SQL_TYPES = new MethodMatcher("* sqlTypes()");
private static final MethodMatcher RETURNED_CLASS = new MethodMatcher("* returnedClass()");
private static final MethodMatcher EQUALS = new MethodMatcher("* equals(java.lang.Object, java.lang.Object)");
private static final MethodMatcher HASHCODE = new MethodMatcher("* hashCode(java.lang.Object)");
private static final MethodMatcher NULL_SAFE_GET_STRING_ARRAY = new MethodMatcher("* nullSafeGet(java.sql.ResultSet, java.lang.String[], org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)");
private static final MethodMatcher NULL_SAFE_GET_INT = new MethodMatcher("* nullSafeGet(java.sql.ResultSet, int, org.hibernate.engine.spi.SharedSessionContractImplementor, java.lang.Object)");
private static final MethodMatcher RESULT_SET_STRING_PARAM = new MethodMatcher("java.sql.ResultSet *(java.lang.String)");
private static final MethodMatcher NULL_SAFE_SET = new MethodMatcher("* nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int, org.hibernate.engine.spi.SharedSessionContractImplementor)");
private static final MethodMatcher DEEP_COPY = new MethodMatcher("* deepCopy(java.lang.Object)");
private static final MethodMatcher DISASSEMBLE = new MethodMatcher("* disassemble(java.lang.Object)");
private static final MethodMatcher ASSEMBLE = new MethodMatcher("* assemble(java.io.Serializable, java.lang.Object)");
private static final MethodMatcher REPLACE = new MethodMatcher("* replace(java.lang.Object, java.lang.Object, java.lang.Object)");
Copy link
Contributor

Choose a reason for hiding this comment

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

The order of these fields feels random; could you clean that up such that it's easier to understand & extend?

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?


@Override
public String getDisplayName() {
return "Migrate UserType to hibernate 6";
Copy link
Contributor

Choose a reason for hiding this comment

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

Lets pay closer attention to how this would look in the docs.

Suggested change
return "Migrate UserType to hibernate 6";
return "Migrate `UserType` to Hibernate 6";

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: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants