HHH-9003 Avoid allocating arrays in most methods of ComponentType
This commit is contained in:
parent
64f6ea7d61
commit
ac16473511
|
@ -677,7 +677,7 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
||||||
? propertyPath.substring( 0, loc )
|
? propertyPath.substring( 0, loc )
|
||||||
: propertyPath;
|
: propertyPath;
|
||||||
final int index = findSubPropertyIndex( type, basePropertyName );
|
final int index = findSubPropertyIndex( type, basePropertyName );
|
||||||
final Object baseValue = type.getPropertyValue( component, index, getEntityMode() );
|
final Object baseValue = type.getPropertyValue( component, index );
|
||||||
if ( loc > 0 ) {
|
if ( loc > 0 ) {
|
||||||
if ( baseValue == null ) {
|
if ( baseValue == null ) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -182,18 +182,15 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEqual(Object x, Object y)
|
public boolean isEqual(final Object x, final Object y) throws HibernateException {
|
||||||
throws HibernateException {
|
|
||||||
if ( x == y ) {
|
if ( x == y ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( x == null || y == null ) {
|
if ( x == null || y == null ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Object[] xvalues = getPropertyValues( x, entityMode );
|
|
||||||
Object[] yvalues = getPropertyValues( y, entityMode );
|
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
if ( !propertyTypes[i].isEqual( xvalues[i], yvalues[i] ) ) {
|
if ( !propertyTypes[i].isEqual( getPropertyValue( x, i ), getPropertyValue( y, i ) ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,18 +198,15 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory)
|
public boolean isEqual(final Object x, final Object y, final SessionFactoryImplementor factory) throws HibernateException {
|
||||||
throws HibernateException {
|
|
||||||
if ( x == y ) {
|
if ( x == y ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ( x == null || y == null ) {
|
if ( x == null || y == null ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Object[] xvalues = getPropertyValues( x, entityMode );
|
|
||||||
Object[] yvalues = getPropertyValues( y, entityMode );
|
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
if ( !propertyTypes[i].isEqual( xvalues[i], yvalues[i], factory ) ) {
|
if ( !propertyTypes[i].isEqual( getPropertyValue( x, i ), getPropertyValue( y, i ), factory ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,14 +214,12 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object x, Object y) {
|
public int compare(final Object x, final Object y) {
|
||||||
if ( x == y ) {
|
if ( x == y ) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Object[] xvalues = getPropertyValues( x, entityMode );
|
|
||||||
Object[] yvalues = getPropertyValues( y, entityMode );
|
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
int propertyCompare = propertyTypes[i].compare( xvalues[i], yvalues[i] );
|
int propertyCompare = propertyTypes[i].compare( getPropertyValue( x, i ), getPropertyValue( y, i ) );
|
||||||
if ( propertyCompare != 0 ) {
|
if ( propertyCompare != 0 ) {
|
||||||
return propertyCompare;
|
return propertyCompare;
|
||||||
}
|
}
|
||||||
|
@ -240,11 +232,10 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHashCode(Object x) {
|
public int getHashCode(final Object x) {
|
||||||
int result = 17;
|
int result = 17;
|
||||||
Object[] values = getPropertyValues( x, entityMode );
|
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
Object y = values[i];
|
Object y = getPropertyValue( x, i );
|
||||||
result *= 37;
|
result *= 37;
|
||||||
if ( y != null ) {
|
if ( y != null ) {
|
||||||
result += propertyTypes[i].getHashCode( y );
|
result += propertyTypes[i].getHashCode( y );
|
||||||
|
@ -254,11 +245,10 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getHashCode(Object x, SessionFactoryImplementor factory) {
|
public int getHashCode(final Object x, final SessionFactoryImplementor factory) {
|
||||||
int result = 17;
|
int result = 17;
|
||||||
Object[] values = getPropertyValues( x, entityMode );
|
|
||||||
for ( int i = 0; i < propertySpan; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
Object y = values[i];
|
Object y = getPropertyValue( x, i );
|
||||||
result *= 37;
|
result *= 37;
|
||||||
if ( y != null ) {
|
if ( y != null ) {
|
||||||
result += propertyTypes[i].getHashCode( y, factory );
|
result += propertyTypes[i].getHashCode( y, factory );
|
||||||
|
@ -268,40 +258,34 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDirty(Object x, Object y, SessionImplementor session)
|
public boolean isDirty(final Object x, final Object y, final SessionImplementor session) throws HibernateException {
|
||||||
throws HibernateException {
|
|
||||||
if ( x == y ) {
|
if ( x == y ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( x == null || y == null ) {
|
if ( x == null || y == null ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Object[] xvalues = getPropertyValues( x, entityMode );
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
Object[] yvalues = getPropertyValues( y, entityMode );
|
if ( propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session ) ) {
|
||||||
for ( int i = 0; i < xvalues.length; i++ ) {
|
|
||||||
if ( propertyTypes[i].isDirty( xvalues[i], yvalues[i], session ) ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirty(Object x, Object y, boolean[] checkable, SessionImplementor session)
|
public boolean isDirty(final Object x, final Object y, final boolean[] checkable, final SessionImplementor session) throws HibernateException {
|
||||||
throws HibernateException {
|
|
||||||
if ( x == y ) {
|
if ( x == y ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( x == null || y == null ) {
|
if ( x == null || y == null ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Object[] xvalues = getPropertyValues( x, entityMode );
|
|
||||||
Object[] yvalues = getPropertyValues( y, entityMode );
|
|
||||||
int loc = 0;
|
int loc = 0;
|
||||||
for ( int i = 0; i < xvalues.length; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
int len = propertyTypes[i].getColumnSpan( session.getFactory() );
|
int len = propertyTypes[i].getColumnSpan( session.getFactory() );
|
||||||
if ( len <= 1 ) {
|
if ( len <= 1 ) {
|
||||||
final boolean dirty = ( len == 0 || checkable[loc] ) &&
|
final boolean dirty = ( len == 0 || checkable[loc] ) &&
|
||||||
propertyTypes[i].isDirty( xvalues[i], yvalues[i], session );
|
propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), session );
|
||||||
if ( dirty ) {
|
if ( dirty ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -309,7 +293,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
else {
|
else {
|
||||||
boolean[] subcheckable = new boolean[len];
|
boolean[] subcheckable = new boolean[len];
|
||||||
System.arraycopy( checkable, loc, subcheckable, 0, len );
|
System.arraycopy( checkable, loc, subcheckable, 0, len );
|
||||||
final boolean dirty = propertyTypes[i].isDirty( xvalues[i], yvalues[i], subcheckable, session );
|
final boolean dirty = propertyTypes[i].isDirty( getPropertyValue( x, i ), getPropertyValue( y, i ), subcheckable, session );
|
||||||
if ( dirty ) {
|
if ( dirty ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -320,23 +304,20 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isModified(Object old, Object current, boolean[] checkable, SessionImplementor session)
|
public boolean isModified(final Object old, final Object current, final boolean[] checkable, final SessionImplementor session) throws HibernateException {
|
||||||
throws HibernateException {
|
|
||||||
|
|
||||||
if ( current == null ) {
|
if ( current == null ) {
|
||||||
return old != null;
|
return old != null;
|
||||||
}
|
}
|
||||||
if ( old == null ) {
|
if ( old == null ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Object[] currentValues = getPropertyValues( current, session );
|
|
||||||
Object[] oldValues = ( Object[] ) old;
|
Object[] oldValues = ( Object[] ) old;
|
||||||
int loc = 0;
|
int loc = 0;
|
||||||
for ( int i = 0; i < currentValues.length; i++ ) {
|
for ( int i = 0; i < propertySpan; i++ ) {
|
||||||
int len = propertyTypes[i].getColumnSpan( session.getFactory() );
|
int len = propertyTypes[i].getColumnSpan( session.getFactory() );
|
||||||
boolean[] subcheckable = new boolean[len];
|
boolean[] subcheckable = new boolean[len];
|
||||||
System.arraycopy( checkable, loc, subcheckable, 0, len );
|
System.arraycopy( checkable, loc, subcheckable, 0, len );
|
||||||
if ( propertyTypes[i].isModified( oldValues[i], currentValues[i], subcheckable, session ) ) {
|
if ( propertyTypes[i].isModified( oldValues[i], getPropertyValue( current, i ), subcheckable, session ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
loc += len;
|
loc += len;
|
||||||
|
@ -410,13 +391,26 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
|
||||||
@Override
|
@Override
|
||||||
public Object getPropertyValue(Object component, int i, SessionImplementor session)
|
public Object getPropertyValue(Object component, int i, SessionImplementor session)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
return getPropertyValue( component, i, entityMode );
|
return getPropertyValue( component, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getPropertyValue(Object component, int i, EntityMode entityMode)
|
public Object getPropertyValue(Object component, int i, EntityMode entityMode)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
return componentTuplizer.getPropertyValue( component, i );
|
return getPropertyValue( component, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getPropertyValue(Object component, int i)
|
||||||
|
throws HibernateException {
|
||||||
|
if ( component instanceof Object[] ) {
|
||||||
|
// A few calls to hashCode pass the property values already in an
|
||||||
|
// Object[] (ex: QueryKey hash codes for cached queries).
|
||||||
|
// It's easiest to just check for the condition here prior to
|
||||||
|
// trying reflection.
|
||||||
|
return (( Object[] ) component)[i];
|
||||||
|
} else {
|
||||||
|
return componentTuplizer.getPropertyValue( component, i );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getPropertyValues(Object component, SessionImplementor session)
|
public Object[] getPropertyValues(Object component, SessionImplementor session)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
|
|
Loading…
Reference in New Issue