very minor cleanups in AbstractEntityPersister
This commit is contained in:
parent
049d151248
commit
f7acf4d93c
|
@ -2510,6 +2510,13 @@ public abstract class AbstractEntityPersister
|
||||||
return subclassPropertyNameClosure;
|
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
|
@Override
|
||||||
public int[] resolveAttributeIndexes(String[] attributeNames) {
|
public int[] resolveAttributeIndexes(String[] attributeNames) {
|
||||||
if ( attributeNames == null || attributeNames.length == 0 ) {
|
if ( attributeNames == null || attributeNames.length == 0 ) {
|
||||||
|
@ -2522,11 +2529,7 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( final AttributeMapping attributeMapping : attributeMappings ) {
|
for ( final AttributeMapping attributeMapping : attributeMappings ) {
|
||||||
final String attributeName = attributeMapping.getAttributeName();
|
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
|
||||||
final int nameLength = attributeName.length();
|
|
||||||
final String currentAttributeName = attributeNames[index];
|
|
||||||
if ( currentAttributeName.startsWith( attributeName ) && (
|
|
||||||
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
|
|
||||||
fields.add( attributeMapping.getStateArrayPosition() );
|
fields.add( attributeMapping.getStateArrayPosition() );
|
||||||
index++;
|
index++;
|
||||||
if ( index < attributeNames.length ) {
|
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
|
// We have to check the state for "mutable" properties as dirty tracking isn't aware of mutable types
|
||||||
final Type[] propertyTypes = entityMetamodel.getPropertyTypes();
|
final Type[] propertyTypes = entityMetamodel.getPropertyTypes();
|
||||||
final boolean[] propertyCheckability = entityMetamodel.getPropertyCheckability();
|
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
|
// This is kindly borrowed from org.hibernate.type.TypeHelper.findDirty
|
||||||
final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY &&
|
if ( isDirty( currentState, previousState, propertyTypes, propertyCheckability, i, session ) ) {
|
||||||
// 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 ) {
|
|
||||||
fields.add( i );
|
fields.add( i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2591,11 +2585,8 @@ public abstract class AbstractEntityPersister
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for ( final AttributeMapping attributeMapping : attributeMappings ) {
|
for ( final AttributeMapping attributeMapping : attributeMappings ) {
|
||||||
final String attributeName = attributeMapping.getAttributeName();
|
final String attributeName = attributeMapping.getAttributeName();
|
||||||
final int nameLength = attributeName.length();
|
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
|
||||||
final String currentAttributeName = attributeNames[index];
|
final int position = attributeMapping.getStateArrayPosition();
|
||||||
final int position = attributeMapping.getStateArrayPosition();
|
|
||||||
if ( currentAttributeName.startsWith( attributeName ) && (
|
|
||||||
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
|
|
||||||
if ( propertyUpdateability[position] && !fields.contains( position ) ) {
|
if ( propertyUpdateability[position] && !fields.contains( position ) ) {
|
||||||
fields.add( position );
|
fields.add( position );
|
||||||
}
|
}
|
||||||
|
@ -2621,6 +2612,27 @@ public abstract class AbstractEntityPersister
|
||||||
return ArrayHelper.toIntArray( fields );
|
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() {
|
protected String[] getSubclassColumnAliasClosure() {
|
||||||
return subclassColumnAliasClosure;
|
return subclassColumnAliasClosure;
|
||||||
}
|
}
|
||||||
|
@ -2631,17 +2643,17 @@ public abstract class AbstractEntityPersister
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) {
|
public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) {
|
||||||
String[] rawAliases = subclassPropertyAliases.get( propertyName );
|
final String[] rawAliases = subclassPropertyAliases.get( propertyName );
|
||||||
|
|
||||||
if ( rawAliases == null ) {
|
if ( rawAliases == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
String[] result = new String[rawAliases.length];
|
final String[] result = new String[rawAliases.length];
|
||||||
for ( int i = 0; i < rawAliases.length; i++ ) {
|
for ( int i = 0; i < rawAliases.length; i++ ) {
|
||||||
result[i] = new Alias( suffix ).toUnquotedAliasString( rawAliases[i] );
|
result[i] = new Alias( suffix ).toUnquotedAliasString( rawAliases[i] );
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue