very minor cleanups in AbstractEntityPersister

This commit is contained in:
Gavin King 2022-10-19 21:45:41 +02:00
parent 049d151248
commit f7acf4d93c
1 changed files with 41 additions and 29 deletions

View File

@ -2510,6 +2510,13 @@ public abstract class AbstractEntityPersister
return subclassPropertyNameClosure;
}
private static boolean isPrefix(final AttributeMapping attributeMapping, final String currentAttributeName) {
final String attributeName = attributeMapping.getAttributeName();
final int nameLength = attributeName.length();
return currentAttributeName.startsWith( attributeName )
&& ( currentAttributeName.length() == nameLength || currentAttributeName.charAt(nameLength) == '.' );
}
@Override
public int[] resolveAttributeIndexes(String[] attributeNames) {
if ( attributeNames == null || attributeNames.length == 0 ) {
@ -2522,11 +2529,7 @@ public abstract class AbstractEntityPersister
int index = 0;
for ( final AttributeMapping attributeMapping : attributeMappings ) {
final String attributeName = attributeMapping.getAttributeName();
final int nameLength = attributeName.length();
final String currentAttributeName = attributeNames[index];
if ( currentAttributeName.startsWith( attributeName ) && (
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
fields.add( attributeMapping.getStateArrayPosition() );
index++;
if ( index < attributeNames.length ) {
@ -2565,19 +2568,10 @@ public abstract class AbstractEntityPersister
// We have to check the state for "mutable" properties as dirty tracking isn't aware of mutable types
final Type[] propertyTypes = entityMetamodel.getPropertyTypes();
final boolean[] propertyCheckability = entityMetamodel.getPropertyCheckability();
for ( int i = mutablePropertiesIndexes.nextSetBit(0); i >= 0; i = mutablePropertiesIndexes.nextSetBit(i + 1) ) {
for ( int i = mutablePropertiesIndexes.nextSetBit(0); i >= 0;
i = mutablePropertiesIndexes.nextSetBit(i + 1) ) {
// This is kindly borrowed from org.hibernate.type.TypeHelper.findDirty
final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY &&
// Consider mutable properties as dirty if we don't have a previous state
( previousState == null || previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ||
( propertyCheckability[i]
&& propertyTypes[i].isDirty(
previousState[i],
currentState[i],
propertyColumnUpdateable[i],
session
) ) );
if ( dirty ) {
if ( isDirty( currentState, previousState, propertyTypes, propertyCheckability, i, session ) ) {
fields.add( i );
}
}
@ -2591,11 +2585,8 @@ public abstract class AbstractEntityPersister
int index = 0;
for ( final AttributeMapping attributeMapping : attributeMappings ) {
final String attributeName = attributeMapping.getAttributeName();
final int nameLength = attributeName.length();
final String currentAttributeName = attributeNames[index];
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
final int position = attributeMapping.getStateArrayPosition();
if ( currentAttributeName.startsWith( attributeName ) && (
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
if ( propertyUpdateability[position] && !fields.contains( position ) ) {
fields.add( position );
}
@ -2621,6 +2612,27 @@ public abstract class AbstractEntityPersister
return ArrayHelper.toIntArray( fields );
}
private boolean isDirty(
Object[] currentState,
Object[] previousState,
Type[] propertyTypes,
boolean[] propertyCheckability,
int i,
SessionImplementor session) {
return currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
// Consider mutable properties as dirty if we don't have a previous state
&& ( previousState == null
|| previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
|| propertyCheckability[i]
&& propertyTypes[i].isDirty(
previousState[i],
currentState[i],
propertyColumnUpdateable[i],
session
)
);
}
protected String[] getSubclassColumnAliasClosure() {
return subclassColumnAliasClosure;
}
@ -2631,18 +2643,18 @@ public abstract class AbstractEntityPersister
@Override
public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) {
String[] rawAliases = subclassPropertyAliases.get( propertyName );
final String[] rawAliases = subclassPropertyAliases.get( propertyName );
if ( rawAliases == null ) {
return null;
}
String[] result = new String[rawAliases.length];
else {
final String[] result = new String[rawAliases.length];
for ( int i = 0; i < rawAliases.length; i++ ) {
result[i] = new Alias( suffix ).toUnquotedAliasString( rawAliases[i] );
}
return result;
}
}
@Override
public String[] getSubclassPropertyColumnNames(String propertyName) {