HHH-11956 Add createCustomLoader() to the NativeQueryInterpreter contract
This commit is contained in:
parent
9fd9f623cb
commit
1e25a1a99b
|
@ -8,6 +8,8 @@ package org.hibernate.engine.query.spi;
|
|||
|
||||
import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.loader.custom.CustomLoader;
|
||||
import org.hibernate.loader.custom.CustomQuery;
|
||||
import org.hibernate.query.internal.ParameterMetadataImpl;
|
||||
import org.hibernate.service.Service;
|
||||
|
||||
|
@ -16,6 +18,7 @@ import org.hibernate.service.Service;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gunnar Morling
|
||||
* @author Guillaume Smet
|
||||
*/
|
||||
public interface NativeQueryInterpreter extends Service {
|
||||
/**
|
||||
|
@ -38,4 +41,17 @@ public interface NativeQueryInterpreter extends Service {
|
|||
* @return A query plan for the specified native query.
|
||||
*/
|
||||
NativeSQLQueryPlan createQueryPlan(NativeSQLQuerySpecification specification, SessionFactoryImplementor sessionFactory);
|
||||
|
||||
/**
|
||||
* Creates a {@link CustomLoader} for the given {@link CustomQuery}.
|
||||
*
|
||||
* @param customQuery The CustomQuery to create a loader for
|
||||
* @param sessionFactory The current session factory
|
||||
*
|
||||
* @deprecated This method will be removed in 6.
|
||||
*/
|
||||
@Deprecated
|
||||
default CustomLoader createCustomLoader(CustomQuery customQuery, SessionFactoryImplementor sessionFactory) {
|
||||
return new CustomLoader( customQuery, sessionFactory );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class QueryPlanCache implements Serializable {
|
|||
private final BoundedConcurrentHashMap<ParameterMetadataKey,ParameterMetadataImpl> parameterMetadataCache;
|
||||
|
||||
|
||||
private NativeQueryInterpreter nativeQueryInterpreterService;
|
||||
private NativeQueryInterpreter nativeQueryInterpreter;
|
||||
|
||||
/**
|
||||
* Constructs the QueryPlanCache to be used by the given SessionFactory
|
||||
|
@ -108,7 +108,7 @@ public class QueryPlanCache implements Serializable {
|
|||
BoundedConcurrentHashMap.Eviction.LIRS
|
||||
);
|
||||
|
||||
nativeQueryInterpreterService = factory.getServiceRegistry().getService( NativeQueryInterpreter.class );
|
||||
nativeQueryInterpreter = factory.getServiceRegistry().getService( NativeQueryInterpreter.class );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -125,7 +125,7 @@ public class QueryPlanCache implements Serializable {
|
|||
final ParameterMetadataKey key = new ParameterMetadataKey( query, isOrdinalParameterZeroBased );
|
||||
ParameterMetadataImpl value = parameterMetadataCache.get( key );
|
||||
if ( value == null ) {
|
||||
value = nativeQueryInterpreterService.getParameterMetadata( query );
|
||||
value = nativeQueryInterpreter.getParameterMetadata( query );
|
||||
parameterMetadataCache.putIfAbsent( key, value );
|
||||
}
|
||||
return value;
|
||||
|
@ -210,7 +210,7 @@ public class QueryPlanCache implements Serializable {
|
|||
NativeSQLQueryPlan value = (NativeSQLQueryPlan) queryPlanCache.get( spec );
|
||||
if ( value == null ) {
|
||||
LOG.tracev( "Unable to locate native-sql query plan in cache; generating ({0})", spec.getQueryString() );
|
||||
value = nativeQueryInterpreterService.createQueryPlan( spec, factory );
|
||||
value = nativeQueryInterpreter.createQueryPlan( spec, factory );
|
||||
queryPlanCache.putIfAbsent( spec, value );
|
||||
}
|
||||
else {
|
||||
|
@ -228,6 +228,10 @@ public class QueryPlanCache implements Serializable {
|
|||
parameterMetadataCache.clear();
|
||||
}
|
||||
|
||||
public NativeQueryInterpreter getNativeQueryInterpreter() {
|
||||
return nativeQueryInterpreter;
|
||||
}
|
||||
|
||||
private static class ParameterMetadataKey implements Serializable {
|
||||
private final String query;
|
||||
private final boolean isOrdinalParameterZeroBased;
|
||||
|
|
|
@ -2128,7 +2128,7 @@ public final class SessionImpl
|
|||
log.tracev( "Scroll SQL query: {0}", customQuery.getSQL() );
|
||||
}
|
||||
|
||||
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
|
||||
CustomLoader loader = getFactory().getQueryPlanCache().getNativeQueryInterpreter().createCustomLoader( customQuery, getFactory() );
|
||||
|
||||
autoFlushIfRequired( loader.getQuerySpaces() );
|
||||
|
||||
|
@ -2152,7 +2152,7 @@ public final class SessionImpl
|
|||
log.tracev( "SQL query: {0}", customQuery.getSQL() );
|
||||
}
|
||||
|
||||
CustomLoader loader = new CustomLoader( customQuery, getFactory() );
|
||||
CustomLoader loader = getFactory().getQueryPlanCache().getNativeQueryInterpreter().createCustomLoader( customQuery, getFactory() );
|
||||
|
||||
autoFlushIfRequired( loader.getQuerySpaces() );
|
||||
|
||||
|
|
Loading…
Reference in New Issue