-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
src/test/java/org/openrewrite/hibernate/MigrateUserTypeTest.java
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
void shouldMigrateUserType() { | ||
//language=java | ||
rewriteRun( | ||
spec -> spec.expectedCyclesThatMakeChanges(2), |
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.
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?
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.*; |
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.
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; |
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."; |
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.
Be careful when you join strings; this would look odd in the docs without .
in between.
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."; |
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)"); |
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.
The order of these fields feels random; could you clean that up such that it's easier to understand & extend?
@Nullable | ||
private static J.FieldAccess parameterizedType = 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.
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.
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.
@Nullable | |
private static J.FieldAccess parameterizedType = 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.
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"; |
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.
Lets pay closer attention to how this would look in the docs.
return "Migrate UserType to hibernate 6"; | |
return "Migrate `UserType` to Hibernate 6"; |
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