HHH-14305 Memory savings in SingleTableEntityPersister

This commit is contained in:
Sanne Grinovero 2020-10-29 09:36:53 +00:00
parent 0dedcd05db
commit 820fe56aa4
2 changed files with 21 additions and 7 deletions

View File

@ -7,6 +7,7 @@
package org.hibernate.metamodel.model.domain.internal;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;
@ -207,6 +208,11 @@ public abstract class AbstractIdentifiableType<J>
@SuppressWarnings("unchecked")
public void collectIdClassAttributes(Set<SingularPersistentAttribute<? super J,?>> attributes) {
if ( idClassAttributes != null ) {
//Make it writeable, if it was using the EMPTY_SET marker.
// This is because there's a semantic difference in this class between a null and an empty Set.
if ( idClassAttributes == Collections.EMPTY_SET ) {
idClassAttributes = new HashSet<>();
}
attributes.addAll( idClassAttributes );
}
else if ( getSuperType() != null ) {
@ -305,14 +311,19 @@ public abstract class AbstractIdentifiableType<J>
@Override
public void applyIdClassAttributes(Set<SingularPersistentAttribute<? super J,?>> idClassAttributes) {
for ( SingularAttribute<? super J,?> idClassAttribute : idClassAttributes ) {
if ( AbstractIdentifiableType.this == idClassAttribute.getDeclaringType() ) {
@SuppressWarnings({ "unchecked" })
SingularPersistentAttribute<J,?> declaredAttribute = (SingularPersistentAttribute) idClassAttribute;
addAttribute( declaredAttribute );
}
if ( idClassAttributes.isEmpty() ) {
AbstractIdentifiableType.this.idClassAttributes = Collections.EMPTY_SET;
}
else {
for ( SingularAttribute<? super J,?> idClassAttribute : idClassAttributes ) {
if ( AbstractIdentifiableType.this == idClassAttribute.getDeclaringType() ) {
@SuppressWarnings({ "unchecked" })
SingularPersistentAttribute<J,?> declaredAttribute = (SingularPersistentAttribute) idClassAttribute;
addAttribute( declaredAttribute );
}
}
AbstractIdentifiableType.this.idClassAttributes = idClassAttributes;
}
AbstractIdentifiableType.this.idClassAttributes = idClassAttributes;
}
@Override

View File

@ -8,6 +8,7 @@ package org.hibernate.persister.entity;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -277,6 +278,8 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
isNullableSubclassTable = ArrayHelper.toBooleanArray( isNullables );
hasSequentialSelects = hasDeferred;
this.sequentialSelectStringsByEntityName = hasSequentialSelects ? new HashMap<>() : Collections.EMPTY_MAP;
// DISCRIMINATOR
if ( persistentClass.isPolymorphic() ) {