HHH-13522 Optimise LoadQueryInfluencers by making maps lazily initialized
This commit is contained in:
parent
d6abbe5124
commit
429cdeff06
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.engine.spi;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
@ -42,9 +43,12 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
private String internalFetchProfile;
|
||||
private final Set<String> enabledFetchProfileNames;
|
||||
|
||||
private final Map<String,Filter> enabledFilters;
|
||||
//Lazily initialized!
|
||||
private HashSet<String> enabledFetchProfileNames;
|
||||
|
||||
//Lazily initialized!
|
||||
private HashMap<String,Filter> enabledFilters;
|
||||
|
||||
private final EffectiveEntityGraph effectiveEntityGraph = new EffectiveEntityGraph();
|
||||
|
||||
|
@ -53,13 +57,7 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
}
|
||||
|
||||
public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory) {
|
||||
this( sessionFactory, new HashMap<>(), new HashSet<>() );
|
||||
}
|
||||
|
||||
private LoadQueryInfluencers(SessionFactoryImplementor sessionFactory, Map<String,Filter> enabledFilters, Set<String> enabledFetchProfileNames) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
this.enabledFilters = enabledFilters;
|
||||
this.enabledFetchProfileNames = enabledFetchProfileNames;
|
||||
}
|
||||
|
||||
public SessionFactoryImplementor getSessionFactory() {
|
||||
|
@ -86,16 +84,21 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
// filter support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public boolean hasEnabledFilters() {
|
||||
return !enabledFilters.isEmpty();
|
||||
return enabledFilters != null && !enabledFilters.isEmpty();
|
||||
}
|
||||
|
||||
public Map<String,Filter> getEnabledFilters() {
|
||||
// First, validate all the enabled filters...
|
||||
//TODO: this implementation has bad performance
|
||||
for ( Filter filter : enabledFilters.values() ) {
|
||||
filter.validate();
|
||||
if ( enabledFilters == null ) {
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
else {
|
||||
// First, validate all the enabled filters...
|
||||
for ( Filter filter : enabledFilters.values() ) {
|
||||
//TODO: this implementation has bad performance
|
||||
filter.validate();
|
||||
}
|
||||
return enabledFilters;
|
||||
}
|
||||
return enabledFilters;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,25 +106,43 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
* @return an unmodifiable Set of enabled filter names.
|
||||
*/
|
||||
public Set<String> getEnabledFilterNames() {
|
||||
return java.util.Collections.unmodifiableSet( enabledFilters.keySet() );
|
||||
if ( enabledFilters == null ) {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
else {
|
||||
return java.util.Collections.unmodifiableSet( enabledFilters.keySet() );
|
||||
}
|
||||
}
|
||||
|
||||
public Filter getEnabledFilter(String filterName) {
|
||||
return enabledFilters.get( filterName );
|
||||
if ( enabledFilters == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return enabledFilters.get( filterName );
|
||||
}
|
||||
}
|
||||
|
||||
public Filter enableFilter(String filterName) {
|
||||
FilterImpl filter = new FilterImpl( sessionFactory.getFilterDefinition( filterName ) );
|
||||
if ( enabledFilters == null ) {
|
||||
this.enabledFilters = new HashMap<>();
|
||||
}
|
||||
enabledFilters.put( filterName, filter );
|
||||
return filter;
|
||||
}
|
||||
|
||||
public void disableFilter(String filterName) {
|
||||
enabledFilters.remove( filterName );
|
||||
if ( enabledFilters != null ) {
|
||||
enabledFilters.remove( filterName );
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFilterParameterValue(String filterParameterName) {
|
||||
final String[] parsed = parseFilterParameterName( filterParameterName );
|
||||
if ( enabledFilters == null ) {
|
||||
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
|
||||
}
|
||||
final FilterImpl filter = (FilterImpl) enabledFilters.get( parsed[0] );
|
||||
if ( filter == null ) {
|
||||
throw new IllegalArgumentException( "Filter [" + parsed[0] + "] currently not enabled" );
|
||||
|
@ -159,11 +180,16 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
// fetch profile support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
public boolean hasEnabledFetchProfiles() {
|
||||
return !enabledFetchProfileNames.isEmpty();
|
||||
return enabledFetchProfileNames != null && !enabledFetchProfileNames.isEmpty();
|
||||
}
|
||||
|
||||
public Set<String> getEnabledFetchProfileNames() {
|
||||
return enabledFetchProfileNames;
|
||||
if ( enabledFetchProfileNames == null ) {
|
||||
return Collections.EMPTY_SET;
|
||||
}
|
||||
else {
|
||||
return enabledFetchProfileNames;
|
||||
}
|
||||
}
|
||||
|
||||
private void checkFetchProfileName(String name) {
|
||||
|
@ -174,17 +200,22 @@ public class LoadQueryInfluencers implements Serializable {
|
|||
|
||||
public boolean isFetchProfileEnabled(String name) throws UnknownProfileException {
|
||||
checkFetchProfileName( name );
|
||||
return enabledFetchProfileNames.contains( name );
|
||||
return enabledFetchProfileNames != null && enabledFetchProfileNames.contains( name );
|
||||
}
|
||||
|
||||
public void enableFetchProfile(String name) throws UnknownProfileException {
|
||||
checkFetchProfileName( name );
|
||||
if ( enabledFetchProfileNames == null ) {
|
||||
this.enabledFetchProfileNames = new HashSet<>();
|
||||
}
|
||||
enabledFetchProfileNames.add( name );
|
||||
}
|
||||
|
||||
public void disableFetchProfile(String name) throws UnknownProfileException {
|
||||
checkFetchProfileName( name );
|
||||
enabledFetchProfileNames.remove( name );
|
||||
if ( enabledFetchProfileNames != null ) {
|
||||
enabledFetchProfileNames.remove( name );
|
||||
}
|
||||
}
|
||||
|
||||
public EffectiveEntityGraph getEffectiveEntityGraph() {
|
||||
|
|
Loading…
Reference in New Issue