Package org.hibernate.engine.query.spi
Class QueryPlanCache
- java.lang.Object
-
- org.hibernate.engine.query.spi.QueryPlanCache
-
- All Implemented Interfaces:
Serializable
public class QueryPlanCache extends Object implements Serializable
Acts as a cache for compiled query plans, as well as query-parameter metadata.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PARAMETER_METADATA_MAX_COUNT
The default strong reference count.static int
DEFAULT_QUERY_PLAN_MAX_COUNT
The default soft reference count.
-
Constructor Summary
Constructors Constructor Description QueryPlanCache(SessionFactoryImplementor factory)
Constructs the QueryPlanCache to be used by the given SessionFactory
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
Clean up the caches when the SessionFactory is closed.FilterQueryPlan
getFilterQueryPlan(String filterString, String collectionRole, boolean shallow, Map<String,Filter> enabledFilters)
Get the query plan for the given collection HQL filter fragment, creating it and caching it if not already cachedHQLQueryPlan
getHQLQueryPlan(String queryString, boolean shallow, Map<String,Filter> enabledFilters)
Get the query plan for the given HQL query, creating it and caching it if not already cachedNativeQueryInterpreter
getNativeQueryInterpreter()
NativeSQLQueryPlan
getNativeSQLQueryPlan(NativeSQLQuerySpecification spec)
Get the query plan for a native SQL query, creating it and caching it if not already cachedParameterMetadata
getSQLParameterMetadata(String query, boolean isOrdinalParameterZeroBased)
Obtain the parameter metadata for given native-sql query.
-
-
-
Field Detail
-
DEFAULT_PARAMETER_METADATA_MAX_COUNT
public static final int DEFAULT_PARAMETER_METADATA_MAX_COUNT
The default strong reference count.- See Also:
- Constant Field Values
-
DEFAULT_QUERY_PLAN_MAX_COUNT
public static final int DEFAULT_QUERY_PLAN_MAX_COUNT
The default soft reference count.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
QueryPlanCache
public QueryPlanCache(SessionFactoryImplementor factory)
Constructs the QueryPlanCache to be used by the given SessionFactory- Parameters:
factory
- The SessionFactory
-
-
Method Detail
-
getSQLParameterMetadata
public ParameterMetadata getSQLParameterMetadata(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
- The query- Returns:
- The parameter metadata
-
getHQLQueryPlan
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
- The HQL query stringshallow
- Whether the execution will be shallowenabledFilters
- The filters enabled on the Session- Returns:
- The query plan
- Throws:
QueryException
- Indicates a problem translating the queryMappingException
- Indicates a problem translating the query
-
getFilterQueryPlan
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
- The HQL filter fragmentcollectionRole
- The collection being filteredshallow
- Whether the execution will be shallowenabledFilters
- The filters enabled on the Session- Returns:
- The query plan
- Throws:
QueryException
- Indicates a problem translating the queryMappingException
- Indicates a problem translating the query
-
getNativeSQLQueryPlan
public NativeSQLQueryPlan getNativeSQLQueryPlan(NativeSQLQuerySpecification spec)
Get the query plan for a native SQL query, creating it and caching it if not already cached- Parameters:
spec
- The native SQL query specification- Returns:
- The query plan
- Throws:
QueryException
- Indicates a problem translating the queryMappingException
- Indicates a problem translating the query
-
cleanup
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.
-
getNativeQueryInterpreter
public NativeQueryInterpreter getNativeQueryInterpreter()
-
-