mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-27 22:39:13 +00:00
HHH-18506 Reduce itable stubs during dirty checking
This commit is contained in:
parent
4c124cde38
commit
bf69471d40
@ -3921,7 +3921,7 @@ public boolean isSubclassPropertyNullable(int i) {
|
|||||||
public int[] findDirty(Object[] currentState, Object[] previousState, Object entity, SharedSessionContractImplementor session)
|
public int[] findDirty(Object[] currentState, Object[] previousState, Object entity, SharedSessionContractImplementor session)
|
||||||
throws HibernateException {
|
throws HibernateException {
|
||||||
int[] props = DirtyHelper.findDirty(
|
int[] props = DirtyHelper.findDirty(
|
||||||
entityMetamodel.getProperties(),
|
entityMetamodel.getDirtyCheckablePropertyTypes(),
|
||||||
currentState,
|
currentState,
|
||||||
previousState,
|
previousState,
|
||||||
propertyColumnUpdateable,
|
propertyColumnUpdateable,
|
||||||
|
@ -11,6 +11,14 @@
|
|||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.internal.util.collections.ArrayHelper;
|
import org.hibernate.internal.util.collections.ArrayHelper;
|
||||||
import org.hibernate.tuple.NonIdentifierAttribute;
|
import org.hibernate.tuple.NonIdentifierAttribute;
|
||||||
|
import org.hibernate.type.AnyType;
|
||||||
|
import org.hibernate.type.BasicType;
|
||||||
|
import org.hibernate.type.CollectionType;
|
||||||
|
import org.hibernate.type.ComponentType;
|
||||||
|
import org.hibernate.type.ManyToOneType;
|
||||||
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Operations for searching an array of property values for modified elements.
|
* Operations for searching an array of property values for modified elements.
|
||||||
@ -72,6 +80,62 @@ else if ( previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if any of the given field values are dirty, returning an array containing
|
||||||
|
* indices of the dirty fields.
|
||||||
|
* <p>
|
||||||
|
* If it is determined that no fields are dirty, null is returned.
|
||||||
|
*
|
||||||
|
* @param propertyTypes The property types that are dirty checkable. null entry for non-dirty checkable properties
|
||||||
|
* @param currentState The current state of the entity
|
||||||
|
* @param previousState The baseline state of the entity
|
||||||
|
* @param includeColumns Columns to be included in the dirty checking, per property
|
||||||
|
* @param session The session from which the dirty check request originated.
|
||||||
|
*
|
||||||
|
* @return Array containing indices of the dirty properties, or null if no properties considered dirty.
|
||||||
|
*/
|
||||||
|
public static int[] findDirty(
|
||||||
|
@Nullable Type[] propertyTypes,
|
||||||
|
final Object[] currentState,
|
||||||
|
final Object[] previousState,
|
||||||
|
final boolean[][] includeColumns,
|
||||||
|
final SharedSessionContractImplementor session) {
|
||||||
|
int[] results = null;
|
||||||
|
int count = 0;
|
||||||
|
int span = propertyTypes.length;
|
||||||
|
|
||||||
|
for ( int i = 0; i < span; i++ ) {
|
||||||
|
|
||||||
|
if ( isDirty( propertyTypes, currentState, previousState, includeColumns, session, i ) ) {
|
||||||
|
if ( results == null ) {
|
||||||
|
results = new int[span];
|
||||||
|
}
|
||||||
|
results[count++] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count == 0 ? null : ArrayHelper.trim( results, count );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDirty(
|
||||||
|
@Nullable Type[] propertyTypes,
|
||||||
|
Object[] currentState,
|
||||||
|
Object[] previousState,
|
||||||
|
boolean[][] includeColumns,
|
||||||
|
SharedSessionContractImplementor session, int i) {
|
||||||
|
final Type propertyType;
|
||||||
|
if ( currentState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
|
||||||
|
|| ( propertyType = propertyTypes[i] ) == null ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if ( previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return propertyType.isDirty( previousState[i], currentState[i], includeColumns[i], session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if any of the given field values are modified, returning an array containing
|
* Determine if any of the given field values are modified, returning an array containing
|
||||||
* indices of the modified fields.
|
* indices of the modified fields.
|
||||||
|
@ -55,8 +55,11 @@
|
|||||||
import org.hibernate.type.CompositeType;
|
import org.hibernate.type.CompositeType;
|
||||||
import org.hibernate.type.EntityType;
|
import org.hibernate.type.EntityType;
|
||||||
import org.hibernate.type.ManyToOneType;
|
import org.hibernate.type.ManyToOneType;
|
||||||
|
import org.hibernate.type.OneToOneType;
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import static java.util.Collections.singleton;
|
import static java.util.Collections.singleton;
|
||||||
import static org.hibernate.internal.CoreLogging.messageLogger;
|
import static org.hibernate.internal.CoreLogging.messageLogger;
|
||||||
import static org.hibernate.internal.util.ReflectHelper.isAbstractClass;
|
import static org.hibernate.internal.util.ReflectHelper.isAbstractClass;
|
||||||
@ -95,6 +98,7 @@ public class EntityMetamodel implements Serializable {
|
|||||||
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
private final String[] propertyNames;
|
private final String[] propertyNames;
|
||||||
private final Type[] propertyTypes;
|
private final Type[] propertyTypes;
|
||||||
|
private final @Nullable Type[] dirtyCheckablePropertyTypes;
|
||||||
private final boolean[] propertyLaziness;
|
private final boolean[] propertyLaziness;
|
||||||
private final boolean[] propertyUpdateability;
|
private final boolean[] propertyUpdateability;
|
||||||
private final boolean[] nonlazyPropertyUpdateability;
|
private final boolean[] nonlazyPropertyUpdateability;
|
||||||
@ -217,6 +221,7 @@ public EntityMetamodel(
|
|||||||
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
// temporary ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
propertyNames = new String[propertySpan];
|
propertyNames = new String[propertySpan];
|
||||||
propertyTypes = new Type[propertySpan];
|
propertyTypes = new Type[propertySpan];
|
||||||
|
dirtyCheckablePropertyTypes = new Type[propertySpan];
|
||||||
propertyUpdateability = new boolean[propertySpan];
|
propertyUpdateability = new boolean[propertySpan];
|
||||||
propertyInsertability = new boolean[propertySpan];
|
propertyInsertability = new boolean[propertySpan];
|
||||||
nonlazyPropertyUpdateability = new boolean[propertySpan];
|
nonlazyPropertyUpdateability = new boolean[propertySpan];
|
||||||
@ -306,6 +311,9 @@ public EntityMetamodel(
|
|||||||
propertyNames[i] = attribute.getName();
|
propertyNames[i] = attribute.getName();
|
||||||
final Type propertyType = attribute.getType();
|
final Type propertyType = attribute.getType();
|
||||||
propertyTypes[i] = propertyType;
|
propertyTypes[i] = propertyType;
|
||||||
|
if ( attribute.isDirtyCheckable() && !( propertyType instanceof OneToOneType ) ) {
|
||||||
|
dirtyCheckablePropertyTypes[i] = propertyType;
|
||||||
|
}
|
||||||
propertyNullability[i] = attribute.isNullable();
|
propertyNullability[i] = attribute.isNullable();
|
||||||
propertyUpdateability[i] = attribute.isUpdateable();
|
propertyUpdateability[i] = attribute.isUpdateable();
|
||||||
propertyInsertability[i] = attribute.isInsertable();
|
propertyInsertability[i] = attribute.isInsertable();
|
||||||
@ -794,6 +802,10 @@ public Type[] getPropertyTypes() {
|
|||||||
return propertyTypes;
|
return propertyTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable Type[] getDirtyCheckablePropertyTypes() {
|
||||||
|
return dirtyCheckablePropertyTypes;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean[] getPropertyLaziness() {
|
public boolean[] getPropertyLaziness() {
|
||||||
return propertyLaziness;
|
return propertyLaziness;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user