From 345b503f21f4f1f7e809598d63f01ce30f1ca749 Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Thu, 29 Oct 2020 17:47:52 +0000 Subject: [PATCH] HHH-14305 Memory optimisations for NamedQueryRepository --- .../query/spi/NamedQueryRepository.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryRepository.java b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryRepository.java index cc8abd6587..72e1f70aae 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryRepository.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/NamedQueryRepository.java @@ -23,6 +23,8 @@ import org.hibernate.procedure.ProcedureCallMemento; import org.jboss.logging.Logger; +import static org.hibernate.internal.util.collections.CollectionHelper.toSmallMap; + /** * @author Steve Ebersole */ @@ -45,21 +47,21 @@ public class NamedQueryRepository { for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) { namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition ); } - this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); + this.namedQueryDefinitionMap = toSmallMap( namedQueryDefinitionMap ); final HashMap namedSqlQueryDefinitionMap = new HashMap(); for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) { namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition ); } - this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); + this.namedSqlQueryDefinitionMap = toSmallMap( namedSqlQueryDefinitionMap ); final HashMap namedSqlResultSetMappingMap = new HashMap(); for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) { namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); } - this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); - this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCalls ); + this.namedSqlResultSetMappingMap = toSmallMap( namedSqlResultSetMappingMap ); + this.procedureCallMementoMap = toSmallMap( namedProcedureCalls ); } public NamedQueryRepository( @@ -67,10 +69,10 @@ public class NamedQueryRepository { Map namedSqlQueryDefinitionMap, Map namedSqlResultSetMappingMap, Map namedProcedureCallMap) { - this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); - this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); - this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); - this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCallMap ); + this.namedQueryDefinitionMap = toSmallMap( namedQueryDefinitionMap ); + this.namedSqlQueryDefinitionMap = toSmallMap( namedSqlQueryDefinitionMap ); + this.namedSqlResultSetMappingMap = toSmallMap( namedSqlResultSetMappingMap ); + this.procedureCallMementoMap = toSmallMap( namedProcedureCallMap ); } @@ -109,7 +111,7 @@ public class NamedQueryRepository { ); } - this.namedQueryDefinitionMap = Collections.unmodifiableMap( copy ); + this.namedQueryDefinitionMap = toSmallMap( copy ); } public synchronized void registerNamedSQLQueryDefinition(String name, NamedSQLQueryDefinition definition) { @@ -127,7 +129,7 @@ public class NamedQueryRepository { ); } - this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( copy ); + this.namedSqlQueryDefinitionMap = toSmallMap( copy ); } public synchronized void registerNamedProcedureCallMemento(String name, ProcedureCallMemento memento) { @@ -141,7 +143,7 @@ public class NamedQueryRepository { ); } - this.procedureCallMementoMap = Collections.unmodifiableMap( copy ); + this.procedureCallMementoMap = toSmallMap( copy ); } public Map checkNamedQueries(QueryPlanCache queryPlanCache) { @@ -159,8 +161,6 @@ public class NamedQueryRepository { catch ( HibernateException e ) { errors.put( namedQueryDefinition.getName(), e ); } - - } // Check native-sql queries @@ -199,4 +199,5 @@ public class NamedQueryRepository { return errors; } + }