HHH-14305 Memory optimisations for NamedQueryRepository

This commit is contained in:
Sanne Grinovero 2020-10-29 17:47:52 +00:00
parent ad5bec0a54
commit 345b503f21
1 changed files with 14 additions and 13 deletions

View File

@ -23,6 +23,8 @@ import org.hibernate.procedure.ProcedureCallMemento;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import static org.hibernate.internal.util.collections.CollectionHelper.toSmallMap;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -45,21 +47,21 @@ public class NamedQueryRepository {
for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) { for ( NamedQueryDefinition namedQueryDefinition : namedQueryDefinitions ) {
namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition ); namedQueryDefinitionMap.put( namedQueryDefinition.getName(), namedQueryDefinition );
} }
this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); this.namedQueryDefinitionMap = toSmallMap( namedQueryDefinitionMap );
final HashMap<String, NamedSQLQueryDefinition> namedSqlQueryDefinitionMap = new HashMap<String, NamedSQLQueryDefinition>(); final HashMap<String, NamedSQLQueryDefinition> namedSqlQueryDefinitionMap = new HashMap<String, NamedSQLQueryDefinition>();
for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) { for ( NamedSQLQueryDefinition namedSqlQueryDefinition : namedSqlQueryDefinitions ) {
namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition ); namedSqlQueryDefinitionMap.put( namedSqlQueryDefinition.getName(), namedSqlQueryDefinition );
} }
this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); this.namedSqlQueryDefinitionMap = toSmallMap( namedSqlQueryDefinitionMap );
final HashMap<String, ResultSetMappingDefinition> namedSqlResultSetMappingMap = new HashMap<String, ResultSetMappingDefinition>(); final HashMap<String, ResultSetMappingDefinition> namedSqlResultSetMappingMap = new HashMap<String, ResultSetMappingDefinition>();
for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) { for ( ResultSetMappingDefinition resultSetMappingDefinition : namedSqlResultSetMappings ) {
namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition ); namedSqlResultSetMappingMap.put( resultSetMappingDefinition.getName(), resultSetMappingDefinition );
} }
this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); this.namedSqlResultSetMappingMap = toSmallMap( namedSqlResultSetMappingMap );
this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCalls ); this.procedureCallMementoMap = toSmallMap( namedProcedureCalls );
} }
public NamedQueryRepository( public NamedQueryRepository(
@ -67,10 +69,10 @@ public class NamedQueryRepository {
Map<String,NamedSQLQueryDefinition> namedSqlQueryDefinitionMap, Map<String,NamedSQLQueryDefinition> namedSqlQueryDefinitionMap,
Map<String,ResultSetMappingDefinition> namedSqlResultSetMappingMap, Map<String,ResultSetMappingDefinition> namedSqlResultSetMappingMap,
Map<String, ProcedureCallMemento> namedProcedureCallMap) { Map<String, ProcedureCallMemento> namedProcedureCallMap) {
this.namedQueryDefinitionMap = Collections.unmodifiableMap( namedQueryDefinitionMap ); this.namedQueryDefinitionMap = toSmallMap( namedQueryDefinitionMap );
this.namedSqlQueryDefinitionMap = Collections.unmodifiableMap( namedSqlQueryDefinitionMap ); this.namedSqlQueryDefinitionMap = toSmallMap( namedSqlQueryDefinitionMap );
this.namedSqlResultSetMappingMap = Collections.unmodifiableMap( namedSqlResultSetMappingMap ); this.namedSqlResultSetMappingMap = toSmallMap( namedSqlResultSetMappingMap );
this.procedureCallMementoMap = Collections.unmodifiableMap( namedProcedureCallMap ); 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) { 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) { 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<String,HibernateException> checkNamedQueries(QueryPlanCache queryPlanCache) { public Map<String,HibernateException> checkNamedQueries(QueryPlanCache queryPlanCache) {
@ -159,8 +161,6 @@ public class NamedQueryRepository {
catch ( HibernateException e ) { catch ( HibernateException e ) {
errors.put( namedQueryDefinition.getName(), e ); errors.put( namedQueryDefinition.getName(), e );
} }
} }
// Check native-sql queries // Check native-sql queries
@ -199,4 +199,5 @@ public class NamedQueryRepository {
return errors; return errors;
} }
} }