Top Description Inners Fields Constructors Methods
org.hibernate.engine.query.spi

public Class QueryPlanCache

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Collection, .Collections, .HashMap, .HashSet, .Map, .Set, java.util.concurrent.TimeUnit, org.hibernate.Filter, .MappingException, .QueryException, org.hibernate.cfg.Environment, org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.internal.CoreLogging, .CoreMessageLogger, .FilterImpl, org.hibernate.internal.util.collections.BoundedConcurrentHashMap, .CollectionHelper, org.hibernate.internal.util.config.ConfigurationHelper, org.hibernate.query.ParameterMetadata, org.hibernate.query.internal.ParameterMetadataImpl, org.hibernate.stat.spi.StatisticsImplementor

Acts as a cache for compiled query plans, as well as query-parameter metadata.
Author
Steve Ebersole
See Also
Environment#QUERY_PLAN_CACHE_PARAMETER_METADATA_MAX_SIZE, Environment#QUERY_PLAN_CACHE_MAX_SIZE

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
public static interface

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_PARAMETER_METADATA_MAX_COUNT

The default strong reference count.

public static final int
DEFAULT_QUERY_PLAN_MAX_COUNT

The default soft reference count.

private final SessionFactoryImplementor
factory

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
private static final CoreMessageLogger
private NativeQueryInterpreter
private final BoundedConcurrentHashMap<QueryPlanCache.ParameterMetadataKey, ParameterMetadataImpl>
parameterMetadataCache

simple cache of param metadata based on query string.

private final BoundedConcurrentHashMap<K, V>
queryPlanCache

the cache of the actual plans...

private QueryPlanCache.QueryPlanCreator

Constructor Summary

AccessConstructor and Description
public
QueryPlanCache(final SessionFactoryImplementor
The SessionFactory
factory
,
QueryPlanCache.QueryPlanCreator queryPlanCreator)

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Constructs the QueryPlanCache to be used by the given SessionFactory

Method Summary

Modifier and TypeMethod and Description
public void
cleanup()

Clean up the caches when the SessionFactory is closed.

public FilterQueryPlan

Returns:

The query plan
getFilterQueryPlan
(String
The HQL filter fragment
filterString
,
String
The collection being filtered
collectionRole
,
boolean
Whether the execution will be shallow
shallow
,
Map<String, Filter>
The filters enabled on the Session
enabledFilters
)

Get the query plan for the given collection HQL filter fragment, creating it and caching it if not already cached

public HQLQueryPlan

Returns:

The query plan
getHQLQueryPlan
(String
The HQL query string
queryString
,
boolean
Whether the execution will be shallow
shallow
,
Map<String, Filter>
The filters enabled on the Session
enabledFilters
)

Get the query plan for the given HQL query, creating it and caching it if not already cached

public NativeQueryInterpreter
public NativeSQLQueryPlan

Returns:

The query plan
getNativeSQLQueryPlan
(final NativeSQLQuerySpecification
The native SQL query specification
spec
)

Get the query plan for a native SQL query, creating it and caching it if not already cached

public ParameterMetadata

Returns:

The parameter metadata
getSQLParameterMetadata
(final String
The query
query
,
boolean isOrdinalParameterZeroBased)

Obtain the parameter metadata for given native-sql query.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_PARAMETER_METADATA_MAX_COUNTback to summary
public static final int DEFAULT_PARAMETER_METADATA_MAX_COUNT

The default strong reference count.

DEFAULT_QUERY_PLAN_MAX_COUNTback to summary
public static final int DEFAULT_QUERY_PLAN_MAX_COUNT

The default soft reference count.

factoryback to summary
private final SessionFactoryImplementor factory

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

LOGback to summary
private static final CoreMessageLogger LOG
nativeQueryInterpreterback to summary
private NativeQueryInterpreter nativeQueryInterpreter
parameterMetadataCacheback to summary
private final BoundedConcurrentHashMap<QueryPlanCache.ParameterMetadataKey, ParameterMetadataImpl> parameterMetadataCache

simple cache of param metadata based on query string. Ideally, the original "user-supplied query" string should be used to obtain this metadata (i.e., not the para-list-expanded query string) to avoid unnecessary cache entries.

Used solely for caching param metadata for native-sql queries, see getSQLParameterMetadata for a discussion as to why...
queryPlanCacheback to summary
private final BoundedConcurrentHashMap<K, V> queryPlanCache

the cache of the actual plans...

queryPlanCreatorback to summary
private QueryPlanCache.QueryPlanCreator queryPlanCreator

Constructor Detail

QueryPlanCacheback to summary
public QueryPlanCache(final SessionFactoryImplementor factory, QueryPlanCache.QueryPlanCreator queryPlanCreator)

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

Constructs the QueryPlanCache to be used by the given SessionFactory

Parameters
factory:SessionFactoryImplementor

The SessionFactory

Annotations
@SuppressWarnings:deprecation

Method Detail

cleanupback to summary
public void cleanup()

Clean up the caches when the SessionFactory is closed.

Note that depending on the cache strategy implementation chosen, clearing the cache might not reclaim all the memory.

Typically, when using LIRS, clearing the cache only invalidates the entries but the outdated entries are kept in memory until they are replaced by others. It is not considered a memory leak as the cache is bounded.

getFilterQueryPlanback to summary
public FilterQueryPlan getFilterQueryPlan(String filterString, String collectionRole, boolean shallow, Map<String, Filter> enabledFilters) throws QueryException, MappingException

Get the query plan for the given collection HQL filter fragment, creating it and caching it if not already cached

Parameters
filterString:String

The HQL filter fragment

collectionRole:String

The collection being filtered

shallow:boolean

Whether the execution will be shallow

enabledFilters:Map<String, Filter>

The filters enabled on the Session

Returns:FilterQueryPlan

The query plan

Annotations
@SuppressWarnings:unchecked
Exceptions
QueryException:
Indicates a problem translating the query
MappingException:
Indicates a problem translating the query
getHQLQueryPlanback to summary
public HQLQueryPlan getHQLQueryPlan(String queryString, boolean shallow, Map<String, Filter> enabledFilters) throws QueryException, MappingException

Get the query plan for the given HQL query, creating it and caching it if not already cached

Parameters
queryString:String

The HQL query string

shallow:boolean

Whether the execution will be shallow

enabledFilters:Map<String, Filter>

The filters enabled on the Session

Returns:HQLQueryPlan

The query plan

Annotations
@SuppressWarnings:unchecked
Exceptions
QueryException:
Indicates a problem translating the query
MappingException:
Indicates a problem translating the query
getNativeQueryInterpreterback to summary
public NativeQueryInterpreter getNativeQueryInterpreter()
getNativeSQLQueryPlanback to summary
public NativeSQLQueryPlan getNativeSQLQueryPlan(final NativeSQLQuerySpecification spec)

Get the query plan for a native SQL query, creating it and caching it if not already cached

Parameters
spec:NativeSQLQuerySpecification

The native SQL query specification

Returns:NativeSQLQueryPlan

The query plan

Annotations
@SuppressWarnings:unchecked
Exceptions
QueryException:
Indicates a problem translating the query
MappingException:
Indicates a problem translating the query
getSQLParameterMetadataback to summary
public ParameterMetadata getSQLParameterMetadata(final String query, boolean isOrdinalParameterZeroBased)

Obtain the parameter metadata for given native-sql query.

for native-sql queries, the param metadata is determined outside any relation to a query plan, because query plan creation and/or retrieval for a native-sql query depends on all of the return types having been set, which might not be the case up-front when param metadata would be most useful

Parameters
query:String

The query

Returns:ParameterMetadata

The parameter metadata

org.hibernate.engine.query.spi back to summary

private Class QueryPlanCache.DynamicFilterKey

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.query.spi.QueryPlanCache.DynamicFilterKey
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final String
private final int
private final Map<String, Integer>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

filterNameback to summary
private final String filterName
hashCodeback to summary
private final int hashCode
parameterMetadataback to summary
private final Map<String, Integer> parameterMetadata

Constructor Detail

DynamicFilterKeyback to summary
private DynamicFilterKey(FilterImpl filter)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.hibernate.engine.query.spi back to summary

private Class QueryPlanCache.FilterQueryPlanKey

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.query.spi.QueryPlanCache.FilterQueryPlanKey
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final String
private final Set<String>
private final int
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
public
FilterQueryPlanKey(String query, String collectionRole, boolean shallow, Map<K, V> enabledFilters)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

collectionRoleback to summary
private final String collectionRole
filterNamesback to summary
private final Set<String> filterNames
hashCodeback to summary
private final int hashCode
queryback to summary
private final String query
shallowback to summary
private final boolean shallow

Constructor Detail

FilterQueryPlanKeyback to summary
public FilterQueryPlanKey(String query, String collectionRole, boolean shallow, Map<K, V> enabledFilters)
Annotations
@SuppressWarnings:unchecked

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.hibernate.engine.query.spi back to summary

private Class QueryPlanCache.HQLQueryPlanKey

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.query.spi.QueryPlanCache.HQLQueryPlanKey
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final Set<QueryPlanCache.DynamicFilterKey>
private final int
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
public
HQLQueryPlanKey(String query, boolean shallow, Map<K, V> enabledFilters)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

filterKeysback to summary
private final Set<QueryPlanCache.DynamicFilterKey> filterKeys
hashCodeback to summary
private final int hashCode
queryback to summary
private final String query
shallowback to summary
private final boolean shallow

Constructor Detail

HQLQueryPlanKeyback to summary
public HQLQueryPlanKey(String query, boolean shallow, Map<K, V> enabledFilters)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.hibernate.engine.query.spi back to summary

private Class QueryPlanCache.ParameterMetadataKey

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.query.spi.QueryPlanCache.ParameterMetadataKey
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final int
private final boolean
private final String

Constructor Summary

AccessConstructor and Description
public
ParameterMetadataKey(String query, boolean isOrdinalParameterZeroBased)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashCodeback to summary
private final int hashCode
isOrdinalParameterZeroBasedback to summary
private final boolean isOrdinalParameterZeroBased
queryback to summary
private final String query

Constructor Detail

ParameterMetadataKeyback to summary
public ParameterMetadataKey(String query, boolean isOrdinalParameterZeroBased)

Method Detail

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
org.hibernate.engine.query.spi back to summary

public Interface QueryPlanCache.QueryPlanCreator

Annotations
@FunctionalInterface

Method Summary

Modifier and TypeMethod and Description
public HQLQueryPlan
createQueryPlan(String queryString, boolean shallow, Map<String, Filter> enabledFilters, SessionFactoryImplementor factory)

Deprecated as a consequence of SessionFactoryImplementor being deprecated.

Method Detail

createQueryPlanback to summary
public HQLQueryPlan createQueryPlan(String queryString, boolean shallow, Map<String, Filter> enabledFilters, SessionFactoryImplementor factory)

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.