Skip to content

Commit f7acf4d

Browse files
committed
very minor cleanups in AbstractEntityPersister
1 parent 049d151 commit f7acf4d

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

+41-29
Original file line numberDiff line numberDiff line change
@@ -2510,6 +2510,13 @@ protected String[] getSubclassPropertyNameClosure() {
25102510
return subclassPropertyNameClosure;
25112511
}
25122512

2513+
private static boolean isPrefix(final AttributeMapping attributeMapping, final String currentAttributeName) {
2514+
final String attributeName = attributeMapping.getAttributeName();
2515+
final int nameLength = attributeName.length();
2516+
return currentAttributeName.startsWith( attributeName )
2517+
&& ( currentAttributeName.length() == nameLength || currentAttributeName.charAt(nameLength) == '.' );
2518+
}
2519+
25132520
@Override
25142521
public int[] resolveAttributeIndexes(String[] attributeNames) {
25152522
if ( attributeNames == null || attributeNames.length == 0 ) {
@@ -2522,11 +2529,7 @@ public int[] resolveAttributeIndexes(String[] attributeNames) {
25222529

25232530
int index = 0;
25242531
for ( final AttributeMapping attributeMapping : attributeMappings ) {
2525-
final String attributeName = attributeMapping.getAttributeName();
2526-
final int nameLength = attributeName.length();
2527-
final String currentAttributeName = attributeNames[index];
2528-
if ( currentAttributeName.startsWith( attributeName ) && (
2529-
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
2532+
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
25302533
fields.add( attributeMapping.getStateArrayPosition() );
25312534
index++;
25322535
if ( index < attributeNames.length ) {
@@ -2565,19 +2568,10 @@ public int[] resolveDirtyAttributeIndexes(
25652568
// We have to check the state for "mutable" properties as dirty tracking isn't aware of mutable types
25662569
final Type[] propertyTypes = entityMetamodel.getPropertyTypes();
25672570
final boolean[] propertyCheckability = entityMetamodel.getPropertyCheckability();
2568-
for ( int i = mutablePropertiesIndexes.nextSetBit(0); i >= 0; i = mutablePropertiesIndexes.nextSetBit(i + 1) ) {
2571+
for ( int i = mutablePropertiesIndexes.nextSetBit(0); i >= 0;
2572+
i = mutablePropertiesIndexes.nextSetBit(i + 1) ) {
25692573
// This is kindly borrowed from org.hibernate.type.TypeHelper.findDirty
2570-
final boolean dirty = currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY &&
2571-
// Consider mutable properties as dirty if we don't have a previous state
2572-
( previousState == null || previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY ||
2573-
( propertyCheckability[i]
2574-
&& propertyTypes[i].isDirty(
2575-
previousState[i],
2576-
currentState[i],
2577-
propertyColumnUpdateable[i],
2578-
session
2579-
) ) );
2580-
if ( dirty ) {
2574+
if ( isDirty( currentState, previousState, propertyTypes, propertyCheckability, i, session ) ) {
25812575
fields.add( i );
25822576
}
25832577
}
@@ -2591,11 +2585,8 @@ public int[] resolveDirtyAttributeIndexes(
25912585
int index = 0;
25922586
for ( final AttributeMapping attributeMapping : attributeMappings ) {
25932587
final String attributeName = attributeMapping.getAttributeName();
2594-
final int nameLength = attributeName.length();
2595-
final String currentAttributeName = attributeNames[index];
2596-
final int position = attributeMapping.getStateArrayPosition();
2597-
if ( currentAttributeName.startsWith( attributeName ) && (
2598-
( currentAttributeName.length() == nameLength || currentAttributeName.charAt( nameLength ) == '.' ) ) ) {
2588+
if ( isPrefix( attributeMapping, attributeNames[index] ) ) {
2589+
final int position = attributeMapping.getStateArrayPosition();
25992590
if ( propertyUpdateability[position] && !fields.contains( position ) ) {
26002591
fields.add( position );
26012592
}
@@ -2621,6 +2612,27 @@ public int[] resolveDirtyAttributeIndexes(
26212612
return ArrayHelper.toIntArray( fields );
26222613
}
26232614

2615+
private boolean isDirty(
2616+
Object[] currentState,
2617+
Object[] previousState,
2618+
Type[] propertyTypes,
2619+
boolean[] propertyCheckability,
2620+
int i,
2621+
SessionImplementor session) {
2622+
return currentState[i] != LazyPropertyInitializer.UNFETCHED_PROPERTY
2623+
// Consider mutable properties as dirty if we don't have a previous state
2624+
&& ( previousState == null
2625+
|| previousState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
2626+
|| propertyCheckability[i]
2627+
&& propertyTypes[i].isDirty(
2628+
previousState[i],
2629+
currentState[i],
2630+
propertyColumnUpdateable[i],
2631+
session
2632+
)
2633+
);
2634+
}
2635+
26242636
protected String[] getSubclassColumnAliasClosure() {
26252637
return subclassColumnAliasClosure;
26262638
}
@@ -2631,17 +2643,17 @@ protected String[] getSubclassFormulaAliasClosure() {
26312643

26322644
@Override
26332645
public String[] getSubclassPropertyColumnAliases(String propertyName, String suffix) {
2634-
String[] rawAliases = subclassPropertyAliases.get( propertyName );
2635-
2646+
final String[] rawAliases = subclassPropertyAliases.get( propertyName );
26362647
if ( rawAliases == null ) {
26372648
return null;
26382649
}
2639-
2640-
String[] result = new String[rawAliases.length];
2641-
for ( int i = 0; i < rawAliases.length; i++ ) {
2642-
result[i] = new Alias( suffix ).toUnquotedAliasString( rawAliases[i] );
2650+
else {
2651+
final String[] result = new String[rawAliases.length];
2652+
for ( int i = 0; i < rawAliases.length; i++ ) {
2653+
result[i] = new Alias( suffix ).toUnquotedAliasString( rawAliases[i] );
2654+
}
2655+
return result;
26432656
}
2644-
return result;
26452657
}
26462658

26472659
@Override

0 commit comments

Comments
 (0)