Skip to content

Commit

Permalink
HHH-11956 Add createCustomLoader() to the NativeQueryInterpreter cont…
Browse files Browse the repository at this point in the history
…ract
  • Loading branch information
gsmet committed Sep 1, 2017
1 parent 9fd9f62 commit 1e25a1a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Expand Up @@ -8,6 +8,8 @@

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;

Expand All @@ -16,6 +18,7 @@
*
* @author Steve Ebersole
* @author Gunnar Morling
* @author Guillaume Smet
*/
public interface NativeQueryInterpreter extends Service {
/**
Expand All @@ -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 );
}
}
Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +108,7 @@ public QueryPlanCache(final SessionFactoryImplementor factory) {
BoundedConcurrentHashMap.Eviction.LIRS
);

nativeQueryInterpreterService = factory.getServiceRegistry().getService( NativeQueryInterpreter.class );
nativeQueryInterpreter = factory.getServiceRegistry().getService( NativeQueryInterpreter.class );
}

/**
Expand All @@ -125,7 +125,7 @@ public ParameterMetadata getSQLParameterMetadata(final String query, boolean isO
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;
Expand Down Expand Up @@ -210,7 +210,7 @@ public NativeSQLQueryPlan getNativeSQLQueryPlan(final NativeSQLQuerySpecificatio
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 {
Expand All @@ -228,6 +228,10 @@ public void cleanup() {
parameterMetadataCache.clear();
}

public NativeQueryInterpreter getNativeQueryInterpreter() {
return nativeQueryInterpreter;
}

private static class ParameterMetadataKey implements Serializable {
private final String query;
private final boolean isOrdinalParameterZeroBased;
Expand Down
Expand Up @@ -422,7 +422,7 @@ public void close() throws HibernateException {
else {
super.close();
}

if ( getFactory().getStatistics().isStatisticsEnabled() ) {
getFactory().getStatistics().closeSession();
}
Expand Down Expand Up @@ -1571,12 +1571,12 @@ public Iterator iterate(String query, QueryParameters queryParameters) throws Hi
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();

HQLQueryPlan plan = queryParameters.getQueryPlan();
if ( plan == null ) {
plan = getQueryPlan( query, false );
}

autoFlushIfRequired( plan.getQuerySpaces() );

dontFlushFromFind++;
Expand Down Expand Up @@ -2128,7 +2128,7 @@ public ScrollableResultsImplementor scrollCustomQuery(CustomQuery customQuery, Q
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() );

Expand All @@ -2152,7 +2152,7 @@ public List listCustomQuery(CustomQuery customQuery, QueryParameters queryParame
log.tracev( "SQL query: {0}", customQuery.getSQL() );
}

CustomLoader loader = new CustomLoader( customQuery, getFactory() );
CustomLoader loader = getFactory().getQueryPlanCache().getNativeQueryInterpreter().createCustomLoader( customQuery, getFactory() );

autoFlushIfRequired( loader.getQuerySpaces() );

Expand Down Expand Up @@ -2467,7 +2467,7 @@ public Blob createBlob(byte[] bytes) {

private LobCreator lobCreator() {
// Always use NonContextualLobCreator. If ContextualLobCreator is
// used both here and in WrapperOptions,
// used both here and in WrapperOptions,
return NonContextualLobCreator.INSTANCE;
}

Expand Down

0 comments on commit 1e25a1a

Please sign in to comment.