HHH-10020 - Improvements to org.hibernate.bytecode.enhance.internal.AttributeTypeDescriptor#buildInLineDirtyCheckingBodyFragment
(cherry picked from commit 1c70e0df0c
)
This commit is contained in:
parent
74bfdd9c4d
commit
9d2b106024
|
@ -8,6 +8,7 @@ package org.hibernate.bytecode.enhance.internal;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import javax.persistence.EmbeddedId;
|
||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
import javassist.CtClass;
|
import javassist.CtClass;
|
||||||
|
@ -34,24 +35,15 @@ public abstract class AttributeTypeDescriptor {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
// should ignore primary keys
|
// should ignore primary keys
|
||||||
if (PersistentAttributesHelper.hasAnnotation( currentValue, Id.class ) ) {
|
if ( PersistentAttributesHelper.hasAnnotation( currentValue, Id.class )
|
||||||
|
|| PersistentAttributesHelper.hasAnnotation( currentValue, EmbeddedId.class ) ) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// primitives || enums
|
|
||||||
if ( currentValue.getType().isPrimitive() || currentValue.getType().isEnum() ) {
|
if ( currentValue.getType().isPrimitive() || currentValue.getType().isEnum() ) {
|
||||||
|
// primitives || enums
|
||||||
builder.append( String.format( " if (%s != $1)", currentValue.getName() ) );
|
builder.append( String.format( " if (%s != $1)", currentValue.getName() ) );
|
||||||
}
|
}
|
||||||
// simple data types
|
|
||||||
else if ( currentValue.getType().getName().startsWith( "java.lang" )
|
|
||||||
|| currentValue.getType().getName().startsWith( "java.math.Big" )
|
|
||||||
|| currentValue.getType().getName().startsWith( "java.sql.Time" )
|
|
||||||
|| currentValue.getType().getName().startsWith( "java.sql.Date" )
|
|
||||||
|| currentValue.getType().getName().startsWith( "java.util.Date" )
|
|
||||||
|| currentValue.getType().getName().startsWith( "java.util.Calendar" ) ) {
|
|
||||||
builder.append( String.format( " if (%s == null || !%<s.equals($1))", currentValue.getName() ) );
|
|
||||||
}
|
|
||||||
// all other objects
|
|
||||||
else {
|
else {
|
||||||
// if the field is a collection we return since we handle that in a separate method
|
// if the field is a collection we return since we handle that in a separate method
|
||||||
for ( CtClass ctClass : currentValue.getType().getInterfaces() ) {
|
for ( CtClass ctClass : currentValue.getType().getInterfaces() ) {
|
||||||
|
@ -62,9 +54,13 @@ public abstract class AttributeTypeDescriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
builder.append( String.format( " if (%1$s == null || !%2$s.equals(%1$s, $1))",
|
builder.append(
|
||||||
currentValue.getName(),
|
String.format(
|
||||||
EqualsHelper.class.getName() ) );
|
" if ( !%s.areEqual( %s, $1 ) )",
|
||||||
|
EqualsHelper.class.getName(),
|
||||||
|
currentValue.getName()
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
builder.append( String.format( " { %s(\"%s\"); }", EnhancerConstants.TRACKER_CHANGER_NAME, currentValue.getName() ) );
|
builder.append( String.format( " { %s(\"%s\"); }", EnhancerConstants.TRACKER_CHANGER_NAME, currentValue.getName() ) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue