HHH-15887 Avoid megamorphic calls on JdbcValuesSourceProcessingState#getSession

This commit is contained in:
Sanne Grinovero 2022-12-15 19:23:27 +00:00 committed by Sanne Grinovero
parent 7c068e5be4
commit c21fef3a66
27 changed files with 582 additions and 818 deletions

View File

@ -44,10 +44,10 @@ import org.hibernate.sql.ast.tree.from.TableReference;
import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBinding;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
@ -203,35 +203,7 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
final List<L> results = session.getFactory().getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParamBindings,
new ExecutionContext() {
private final Callback callback = new CallbackImpl();
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return queryOptions;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return callback;
}
},
new NaturalIdLoaderWithOptionsExecutionContext( session, queryOptions ),
row -> (L) row[0],
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -362,33 +334,7 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
final List<Object> results = session.getFactory().getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParamBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
throw new UnsupportedOperationException( "Follow-on locking not supported yet" );
}
},
new NoCallbackExecutionContext( session ),
(row) -> {
// because we select the natural-id we want to "reduce" the result
assert row.length == 1;
@ -435,4 +381,26 @@ public abstract class AbstractNaturalIdLoader<T> implements NaturalIdLoader<T> {
}
return fetches.build();
}
private static class NaturalIdLoaderWithOptionsExecutionContext extends BaseExecutionContext {
private final Callback callback;
private final QueryOptions queryOptions;
public NaturalIdLoaderWithOptionsExecutionContext(SharedSessionContractImplementor session, QueryOptions queryOptions) {
super( session );
this.queryOptions = queryOptions;
callback = new CallbackImpl();
}
@Override
public QueryOptions getQueryOptions() {
return queryOptions;
}
@Override
public Callback getCallback() {
return callback;
}
}
}

View File

@ -12,7 +12,6 @@ import java.util.List;
import org.hibernate.LockOptions;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -24,14 +23,12 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.internal.EntityCollectionPart;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
@ -139,38 +136,7 @@ public class CollectionElementLoaderByIndex implements Loader {
List<Object> list = jdbcServices.getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public CollectionKey getCollectionKey() {
return null;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
},
new BaseExecutionContext( session ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -187,4 +153,5 @@ public class CollectionElementLoaderByIndex implements Loader {
}
return index;
}
}

View File

@ -15,7 +15,6 @@ import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -24,17 +23,13 @@ import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.loader.ast.spi.CollectionLoader;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
import org.hibernate.sql.results.spi.ListResultsConsumer;
@ -201,38 +196,7 @@ public class CollectionLoaderBatchKey implements CollectionLoader {
jdbcServices.getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
},
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);

View File

@ -27,9 +27,8 @@ import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
@ -121,47 +120,36 @@ public class CollectionLoaderSingleKey implements CollectionLoader {
jdbcServices.getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public CollectionKey getCollectionKey() {
return collectionKey;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
},
new CollectionLoaderSingleKeyExecutionContext( session, collectionKey, subSelectFetchableKeysHandler ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);
return session.getPersistenceContext().getCollection( collectionKey );
}
private static class CollectionLoaderSingleKeyExecutionContext extends BaseExecutionContext {
private final CollectionKey collectionKey;
private final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler;
CollectionLoaderSingleKeyExecutionContext(
SharedSessionContractImplementor session,
CollectionKey collectionKey,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler) {
super( session );
this.collectionKey = collectionKey;
this.subSelectFetchableKeysHandler = subSelectFetchableKeysHandler;
}
@Override
public CollectionKey getCollectionKey() {
return collectionKey;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
}
}

View File

@ -25,14 +25,10 @@ import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.loader.ast.spi.CollectionLoader;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.ResultsHelper;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
import org.hibernate.sql.results.spi.ListResultsConsumer;
@ -134,38 +130,7 @@ public class CollectionLoaderSubSelectFetch implements CollectionLoader {
jdbcServices.getJdbcSelectExecutor().list(
jdbcSelect,
this.subselect.getLoadingJdbcParameterBindings(),
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
},
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -193,4 +158,5 @@ public class CollectionLoaderSubSelectFetch implements CollectionLoader {
return collection;
}
}

View File

@ -7,7 +7,6 @@
package org.hibernate.loader.ast.internal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.hibernate.LockOptions;
@ -34,10 +33,9 @@ import org.hibernate.sql.ast.tree.from.TableReference;
import org.hibernate.sql.ast.tree.predicate.ComparisonPredicate;
import org.hibernate.sql.ast.tree.select.QuerySpec;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.internal.JdbcParameterImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.graph.DomainResult;
@ -177,33 +175,7 @@ class DatabaseSnapshotExecutor {
final List<?> list = session.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
},
new BaseExecutionContext( session ),
RowTransformerDatabaseSnapshotImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.loader.ast.internal;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
class ExecutionContextWithSubselectFetchHandler extends BaseExecutionContext {
private final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler;
public ExecutionContextWithSubselectFetchHandler(
SharedSessionContractImplementor session,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler) {
super( session );
this.subSelectFetchableKeysHandler = subSelectFetchableKeysHandler;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
if ( subSelectFetchableKeysHandler != null ) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
}
}

View File

@ -36,17 +36,13 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
import org.hibernate.sql.results.spi.ListResultsConsumer;
@ -298,39 +294,7 @@ public class MultiIdLoaderStandard<T> implements MultiIdEntityLoader<T> {
return session.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
if ( subSelectFetchableKeysHandler != null ) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
}
},
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -482,4 +446,5 @@ public class MultiIdLoaderStandard<T> implements MultiIdEntityLoader<T> {
}
return readOnly;
}
}

View File

@ -12,7 +12,6 @@ import java.util.List;
import org.hibernate.LockOptions;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@ -22,17 +21,13 @@ import org.hibernate.loader.ast.spi.MultiNaturalIdLoadOptions;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
import org.hibernate.sql.results.spi.ListResultsConsumer;
@ -164,41 +159,10 @@ public class MultiNaturalIdLoadingBatcher {
return session.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParamBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
if ( subSelectFetchableKeysHandler != null ) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
}
},
new ExecutionContextWithSubselectFetchHandler( session, subSelectFetchableKeysHandler ),
RowTransformerStandardImpl.instance(),
ListResultsConsumer.UniqueSemantic.FILTER
);
}
}

View File

@ -0,0 +1,25 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.loader.ast.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.spi.Callback;
public class NoCallbackExecutionContext extends BaseExecutionContext {
public NoCallbackExecutionContext(SharedSessionContractImplementor session) {
super( session );
}
@Override
public Callback getCallback() {
throw new UnsupportedOperationException( "Follow-on locking not supported yet" );
}
}

View File

@ -26,8 +26,8 @@ import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
@ -165,7 +165,6 @@ public class SingleIdEntityLoaderDynamicBatch<T> extends SingleIdEntityLoaderSup
final EntityKey entityKey = session.generateEntityKey( pkValue, getLoadable().getEntityPersister() );
//noinspection unchecked
return (T) session.getPersistenceContext().getEntity( entityKey );
}
private ExecutionContext getExecutionContext(
@ -175,58 +174,13 @@ public class SingleIdEntityLoaderDynamicBatch<T> extends SingleIdEntityLoaderSup
LockOptions lockOptions,
SharedSessionContractImplementor session,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler) {
return new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public Object getEntityInstance() {
return entityInstance;
}
@Override
public Object getEntityId() {
return entityId;
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return readOnly;
}
@Override
public LockOptions getLockOptions() {
return lockOptions;
}
};
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return null;
}
};
return new SingleIdExecutionContext( session,
entityInstance,
entityId,
readOnly,
lockOptions,
subSelectFetchableKeysHandler
);
}
private void initializeSingleIdLoaderIfNeeded(SharedSessionContractImplementor session) {
@ -235,4 +189,58 @@ public class SingleIdEntityLoaderDynamicBatch<T> extends SingleIdEntityLoaderSup
singleIdLoader.prepare();
}
}
private static class SingleIdExecutionContext extends BaseExecutionContext {
private final Object entityInstance;
private final Object entityId;
private final Boolean readOnly;
private final LockOptions lockOptions;
private final SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler;
public SingleIdExecutionContext(
SharedSessionContractImplementor session,
Object entityInstance,
Object entityId,
Boolean readOnly,
LockOptions lockOptions,
SubselectFetch.RegistrationHandler subSelectFetchableKeysHandler) {
super( session );
this.entityInstance = entityInstance;
this.entityId = entityId;
this.readOnly = readOnly;
this.lockOptions = lockOptions;
this.subSelectFetchableKeysHandler = subSelectFetchableKeysHandler;
}
@Override
public Object getEntityInstance() {
return entityInstance;
}
@Override
public Object getEntityId() {
return entityId;
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return readOnly;
}
@Override
public LockOptions getLockOptions() {
return lockOptions;
}
};
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchableKeysHandler.addKey( entityKey, entry );
}
}
}

View File

@ -23,10 +23,10 @@ import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.internal.RowTransformerStandardImpl;
@ -148,43 +148,7 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
final List<T> list = session.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public Object getEntityInstance() {
return entityInstance;
}
@Override
public Object getEntityId() {
return restrictedValue;
}
@Override
public QueryOptions getQueryOptions() {
return queryOptions;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return callback;
}
},
new SingleIdExecutionContext( session, entityInstance, restrictedValue, queryOptions, callback ),
getRowTransformer(),
singleResultExpected ? ListResultsConsumer.UniqueSemantic.ASSERT : ListResultsConsumer.UniqueSemantic.FILTER
);
@ -199,4 +163,45 @@ public class SingleIdLoadPlan<T> implements SingleEntityLoadPlan {
}
return entity;
}
private static class SingleIdExecutionContext extends BaseExecutionContext {
private final Object entityInstance;
private final Object restrictedValue;
private final QueryOptions queryOptions;
private final Callback callback;
public SingleIdExecutionContext(
SharedSessionContractImplementor session,
Object entityInstance,
Object restrictedValue,
QueryOptions queryOptions,
Callback callback) {
super( session );
this.entityInstance = entityInstance;
this.restrictedValue = restrictedValue;
this.queryOptions = queryOptions;
this.callback = callback;
}
@Override
public Object getEntityInstance() {
return entityInstance;
}
@Override
public Object getEntityId() {
return restrictedValue;
}
@Override
public QueryOptions getQueryOptions() {
return queryOptions;
}
@Override
public Callback getCallback() {
return callback;
}
}
}

View File

@ -23,16 +23,14 @@ import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.SingularAttributeMapping;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryOptionsAdapter;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
import org.hibernate.sql.results.spi.ListResultsConsumer;
@ -102,39 +100,7 @@ public class SingleUniqueKeyEntityLoaderStandard<T> implements SingleUniqueKeyEn
final List<Object> list = sessionFactory.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
private final Callback callback = new CallbackImpl();
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return readOnly;
}
};
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return callback;
}
},
new SingleUKEntityLoaderExecutionContext( session, readOnly ),
row -> row[0],
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -191,33 +157,7 @@ public class SingleUniqueKeyEntityLoaderStandard<T> implements SingleUniqueKeyEn
final List<Object> list = sessionFactory.getJdbcServices().getJdbcSelectExecutor().list(
jdbcSelect,
jdbcParameterBindings,
new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
throw new UnsupportedOperationException( "Follow-on locking not supported yet" );
}
},
new NoCallbackExecutionContext( session ),
row -> row[0],
ListResultsConsumer.UniqueSemantic.FILTER
);
@ -226,4 +166,28 @@ public class SingleUniqueKeyEntityLoaderStandard<T> implements SingleUniqueKeyEn
return list.get( 0 );
}
private static class SingleUKEntityLoaderExecutionContext extends BaseExecutionContext {
private final Callback callback;
private final QueryOptions queryOptions;
public SingleUKEntityLoaderExecutionContext(SharedSessionContractImplementor session, Boolean readOnly) {
super( session );
//Careful, readOnly is possibly null
this.queryOptions = readOnly == null ? QueryOptions.NONE : readOnly ? QueryOptions.READ_ONLY : QueryOptions.READ_WRITE;
callback = new CallbackImpl();
}
@Override
public QueryOptions getQueryOptions() {
return queryOptions;
}
@Override
public Callback getCallback() {
return callback;
}
}
}

View File

@ -17,18 +17,16 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.EventType;
import org.hibernate.generator.InDatabaseGenerator;
import org.hibernate.loader.ast.internal.LoaderSelectBuilder;
import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.loader.ast.internal.NoCallbackExecutionContext;
import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.GeneratedValueResolver;
import org.hibernate.metamodel.mapping.InDatabaseGeneratedValueResolver;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.ast.tree.select.SelectStatement;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import org.hibernate.sql.exec.spi.JdbcParameterBindings;
@ -161,32 +159,7 @@ public class GeneratedValuesProcessor {
}
private static ExecutionContext createExecutionContext(SharedSessionContractImplementor session) {
return new ExecutionContext() {
@Override
public SharedSessionContractImplementor getSession() {
return session;
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
throw new UnsupportedMappingException("Follow-on locking not supported yet");
}
};
return new NoCallbackExecutionContext( session );
}
private static class GeneratedValueDescriptor {
@ -198,4 +171,5 @@ public class GeneratedValuesProcessor {
this.attribute = attribute;
}
}
}

View File

@ -55,8 +55,6 @@ import org.hibernate.query.results.ResultSetMappingImpl;
import org.hibernate.query.spi.AbstractQuery;
import org.hibernate.query.spi.MutableQueryOptions;
import org.hibernate.query.spi.QueryImplementor;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryOptionsAdapter;
import org.hibernate.query.spi.QueryParameterBinding;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.query.spi.ScrollableResultsImplementor;
@ -65,13 +63,12 @@ import org.hibernate.result.NoMoreReturnsException;
import org.hibernate.result.Output;
import org.hibernate.result.ResultSetOutput;
import org.hibernate.result.UpdateCountOutput;
import org.hibernate.result.internal.OutputsExecutionContext;
import org.hibernate.result.spi.ResultContext;
import org.hibernate.sql.ast.tree.expression.JdbcParameter;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.internal.JdbcCallRefCursorExtractorImpl;
import org.hibernate.sql.exec.internal.JdbcParameterBindingImpl;
import org.hibernate.sql.exec.internal.JdbcParameterBindingsImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcCallParameterRegistration;
import org.hibernate.sql.exec.spi.JdbcCallRefCursorExtractor;
@ -683,40 +680,7 @@ public class ProcedureCallImpl<R>
}
}
final ExecutionContext executionContext = new ExecutionContext() {
private final Callback callback = new CallbackImpl();
@Override
public SharedSessionContractImplementor getSession() {
return ProcedureCallImpl.this.getSession();
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return false;
}
};
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return callback;
}
};
final ExecutionContext executionContext = new OutputsExecutionContext( getSession() );
// Note that this should actually happen in an executor
@ -1251,4 +1215,5 @@ public class ProcedureCallImpl<R>
public ResultSetMapping getResultSetMapping() {
return resultSetMapping;
}
}

View File

@ -175,9 +175,25 @@ public interface QueryOptions {
default ListResultsConsumer.UniqueSemantic getUniqueSemantic(){
return null;
}
/**
* Singleton access
* Provide singleton access for frequently needed options:
*/
QueryOptions NONE = new QueryOptionsAdapter() {
};
QueryOptions READ_WRITE = new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return Boolean.FALSE;
}
};
QueryOptions READ_ONLY = new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return Boolean.TRUE;
}
};
}

View File

@ -166,25 +166,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
DomainQueryExecutionContext executionContext,
JdbcOperationQuerySelect jdbcSelect,
SubselectFetch.RegistrationHandler subSelectFetchKeyHandler) {
return new SqmJdbcExecutionContextAdapter( executionContext, jdbcSelect ) {
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchKeyHandler.addKey( entityKey, entry );
}
@Override
public String getQueryIdentifier(String sql) {
if ( CRITERIA_HQL_STRING.equals( hql ) ) {
return "[CRITERIA] " + sql;
}
return hql;
}
@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return true;
}
};
return new MySqmJdbcExecutionContextAdapter( executionContext, jdbcSelect, subSelectFetchKeyHandler, hql );
}
private static boolean containsCollectionFetches(QueryOptions queryOptions) {
@ -483,4 +465,33 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
this.firstParameterBindings = firstParameterBindings;
}
}
private static class MySqmJdbcExecutionContextAdapter extends SqmJdbcExecutionContextAdapter {
private final SubselectFetch.RegistrationHandler subSelectFetchKeyHandler;
private final String hql;
public MySqmJdbcExecutionContextAdapter(
DomainQueryExecutionContext executionContext,
JdbcOperationQuerySelect jdbcSelect,
SubselectFetch.RegistrationHandler subSelectFetchKeyHandler,
String hql) {
super( executionContext, jdbcSelect );
this.subSelectFetchKeyHandler = subSelectFetchKeyHandler;
this.hql = hql;
}
@Override
public void registerLoadingEntityEntry(EntityKey entityKey, LoadingEntityEntry entry) {
subSelectFetchKeyHandler.addKey( entityKey, entry );
}
@Override
public String getQueryIdentifier(String sql) {
if ( CRITERIA_HQL_STRING.equals( hql ) ) {
return "[CRITERIA] " + sql;
}
return hql;
}
}
}

View File

@ -6,12 +6,11 @@
*/
package org.hibernate.query.sqm.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.exec.spi.JdbcOperationQuerySelect;
import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOptions;
@ -19,7 +18,7 @@ import static org.hibernate.query.spi.SqlOmittingQueryOptions.omitSqlQueryOption
/**
* ExecutionContext adapter delegating to a DomainQueryExecutionContext
*/
public class SqmJdbcExecutionContextAdapter implements ExecutionContext {
public class SqmJdbcExecutionContextAdapter extends BaseExecutionContext {
/**
* Creates an adapter which drops any locking or paging details from the query options
*/
@ -42,6 +41,7 @@ public class SqmJdbcExecutionContextAdapter implements ExecutionContext {
}
private SqmJdbcExecutionContextAdapter(DomainQueryExecutionContext sqmExecutionContext, QueryOptions queryOptions) {
super( sqmExecutionContext.getSession() );
this.sqmExecutionContext = sqmExecutionContext;
this.queryOptions = queryOptions;
}
@ -49,10 +49,6 @@ public class SqmJdbcExecutionContextAdapter implements ExecutionContext {
public SqmJdbcExecutionContextAdapter(DomainQueryExecutionContext sqmExecutionContext, JdbcOperationQuerySelect jdbcSelect) {
this( sqmExecutionContext, omitSqlQueryOptions( sqmExecutionContext.getQueryOptions(), jdbcSelect ) );
}
@Override
public SharedSessionContractImplementor getSession() {
return sqmExecutionContext.getSession();
}
@Override
public QueryOptions getQueryOptions() {
@ -74,8 +70,4 @@ public class SqmJdbcExecutionContextAdapter implements ExecutionContext {
return true;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
}

View File

@ -0,0 +1,33 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.result.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.spi.Callback;
public class OutputsExecutionContext extends BaseExecutionContext {
private final Callback callback = new CallbackImpl();
public OutputsExecutionContext(SharedSessionContractImplementor session) {
super( session );
}
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.READ_WRITE;
}
@Override
public Callback getCallback() {
return callback;
}
}

View File

@ -21,21 +21,14 @@ import jakarta.persistence.ParameterMode;
import org.hibernate.JDBCException;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.CoreLogging;
import org.hibernate.procedure.internal.ProcedureCallImpl;
import org.hibernate.procedure.internal.ScalarDomainResultBuilder;
import org.hibernate.procedure.spi.FunctionReturnImplementor;
import org.hibernate.query.procedure.ProcedureParameter;
import org.hibernate.query.results.ResultSetMapping;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryOptionsAdapter;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.result.Output;
import org.hibernate.result.Outputs;
import org.hibernate.result.spi.ResultContext;
import org.hibernate.sql.exec.internal.CallbackImpl;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.results.NoMoreOutputsException;
import org.hibernate.sql.results.internal.ResultsHelper;
@ -182,40 +175,7 @@ public class OutputsImpl implements Outputs {
}
);
final ExecutionContext executionContext = new ExecutionContext() {
private final Callback callback = new CallbackImpl();
@Override
public SharedSessionContractImplementor getSession() {
return OutputsImpl.this.context.getSession();
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptionsAdapter() {
@Override
public Boolean isReadOnly() {
return false;
}
};
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
@Override
public Callback getCallback() {
return callback;
}
};
final ExecutionContext executionContext = new OutputsExecutionContext( context.getSession() );
final JdbcValues jdbcValues = new JdbcValuesResultSetImpl(
resultSetAccess,

View File

@ -0,0 +1,59 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.sql.exec.internal;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
public class BaseExecutionContext implements ExecutionContext {
private final SharedSessionContractImplementor session;
public BaseExecutionContext(SharedSessionContractImplementor session) {
this.session = session;
}
// Optimization: mark this as final so to avoid a megamorphic call on this
// as it will never need to be implemented differently.
@Override
public final SharedSessionContractImplementor getSession() {
return session;
}
// Also marked as final for the same reason
@Override
public final LoadQueryInfluencers getLoadQueryInfluencers() {
return session.getLoadQueryInfluencers();
}
// Unable to avoid the megamorphic calls in this case, but at least
// let's reduce this to the most common case.
@Override
public QueryOptions getQueryOptions() {
return QueryOptions.NONE;
}
@Override
public String getQueryIdentifier(String sql) {
return sql;
}
@Override
public Callback getCallback() {
return null;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
}

View File

@ -1,88 +0,0 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.sql.exec.internal;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.resource.jdbc.spi.LogicalConnectionImplementor;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.results.graph.entity.LoadingEntityEntry;
/**
* @author Christian Beikov
*/
public class DelegatingExecutionContext implements ExecutionContext {
private final ExecutionContext executionContext;
public DelegatingExecutionContext(ExecutionContext executionContext) {
this.executionContext = executionContext;
}
@Override
public String getQueryIdentifier(String sql) {
return executionContext.getQueryIdentifier( sql );
}
@Override
public SharedSessionContractImplementor getSession() {
return executionContext.getSession();
}
@Override
public QueryOptions getQueryOptions() {
return executionContext.getQueryOptions();
}
@Override
public LoadQueryInfluencers getLoadQueryInfluencers() {
return executionContext.getLoadQueryInfluencers();
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return executionContext.getQueryParameterBindings();
}
@Override
public Callback getCallback() {
return executionContext.getCallback();
}
@Override
public CollectionKey getCollectionKey() {
return executionContext.getCollectionKey();
}
@Override
public Object getEntityInstance() {
return executionContext.getEntityInstance();
}
@Override
public Object getEntityId() {
return executionContext.getEntityId();
}
@Override
public void registerLoadingEntityEntry(
EntityKey entityKey,
LoadingEntityEntry entry) {
executionContext.registerLoadingEntityEntry( entityKey, entry );
}
@Override
public void afterStatement(LogicalConnectionImplementor logicalConnection) {
executionContext.afterStatement( logicalConnection );
}
}

View File

@ -228,109 +228,24 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
final Integer fetchSize = queryOptions.getFetchSize();
final Limit limit = queryOptions.getLimit();
return new ExecutionContext() {
@Override
public boolean isScrollResult() {
return true;
}
@Override
public QueryOptions getQueryOptions() {
return new QueryOptions() {
@Override
public Integer getTimeout() {
return timeout;
}
@Override
public FlushMode getFlushMode() {
return flushMode;
}
@Override
public Boolean isReadOnly() {
return readOnly;
}
@Override
public AppliedGraph getAppliedGraph() {
return appliedGraph;
}
@Override
public TupleTransformer<?> getTupleTransformer() {
return tupleTransformer;
}
@Override
public ResultListTransformer<?> getResultListTransformer() {
return resultListTransformer;
}
@Override
public Boolean isResultCachingEnabled() {
return resultCachingEnabled;
}
@Override
public CacheRetrieveMode getCacheRetrieveMode() {
return cacheRetrieveMode;
}
@Override
public CacheStoreMode getCacheStoreMode() {
return cacheStoreMode;
}
@Override
public String getResultCacheRegionName() {
return resultCacheRegionName;
}
@Override
public LockOptions getLockOptions() {
return lockOptions;
}
@Override
public String getComment() {
return comment;
}
@Override
public List<String> getDatabaseHints() {
return databaseHints;
}
@Override
public Integer getFetchSize() {
return fetchSize;
}
@Override
public Limit getLimit() {
return limit;
}
};
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return context.getQueryParameterBindings();
}
@Override
public Callback getCallback() {
return context.getCallback();
}
@Override
public SharedSessionContractImplementor getSession() {
return context.getSession();
}
};
return new JdbcSelectExecutionContext(
timeout,
flushMode,
readOnly,
appliedGraph,
tupleTransformer,
resultListTransformer,
resultCachingEnabled,
cacheRetrieveMode,
cacheStoreMode,
resultCacheRegionName,
lockOptions,
comment,
databaseHints,
fetchSize,
limit,
context
);
}
private <T, R> T doExecuteQuery(
@ -725,4 +640,156 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
}
}
private static class JdbcSelectExecutionContext extends BaseExecutionContext implements QueryOptions {
private final Integer timeout;
private final FlushMode flushMode;
private final Boolean readOnly;
private final AppliedGraph appliedGraph;
private final TupleTransformer<?> tupleTransformer;
private final ResultListTransformer<?> resultListTransformer;
private final Boolean resultCachingEnabled;
private final CacheRetrieveMode cacheRetrieveMode;
private final CacheStoreMode cacheStoreMode;
private final String resultCacheRegionName;
private final LockOptions lockOptions;
private final String comment;
private final List<String> databaseHints;
private final Integer fetchSize;
private final Limit limit;
private final ExecutionContext context;
public JdbcSelectExecutionContext(
Integer timeout,
FlushMode flushMode,
Boolean readOnly,
AppliedGraph appliedGraph,
TupleTransformer<?> tupleTransformer,
ResultListTransformer<?> resultListTransformer,
Boolean resultCachingEnabled,
CacheRetrieveMode cacheRetrieveMode,
CacheStoreMode cacheStoreMode,
String resultCacheRegionName,
LockOptions lockOptions,
String comment,
List<String> databaseHints,
Integer fetchSize,
Limit limit,
ExecutionContext context) {
super( context.getSession() );
this.timeout = timeout;
this.flushMode = flushMode;
this.readOnly = readOnly;
this.appliedGraph = appliedGraph;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.resultCachingEnabled = resultCachingEnabled;
this.cacheRetrieveMode = cacheRetrieveMode;
this.cacheStoreMode = cacheStoreMode;
this.resultCacheRegionName = resultCacheRegionName;
this.lockOptions = lockOptions;
this.comment = comment;
this.databaseHints = databaseHints;
this.fetchSize = fetchSize;
this.limit = limit;
this.context = context;
}
@Override
public boolean isScrollResult() {
return true;
}
@Override
public QueryOptions getQueryOptions() {
return this;
}
@Override
public Integer getTimeout() {
return timeout;
}
@Override
public FlushMode getFlushMode() {
return flushMode;
}
@Override
public Boolean isReadOnly() {
return readOnly;
}
@Override
public AppliedGraph getAppliedGraph() {
return appliedGraph;
}
@Override
public TupleTransformer<?> getTupleTransformer() {
return tupleTransformer;
}
@Override
public ResultListTransformer<?> getResultListTransformer() {
return resultListTransformer;
}
@Override
public Boolean isResultCachingEnabled() {
return resultCachingEnabled;
}
@Override
public CacheRetrieveMode getCacheRetrieveMode() {
return cacheRetrieveMode;
}
@Override
public CacheStoreMode getCacheStoreMode() {
return cacheStoreMode;
}
@Override
public String getResultCacheRegionName() {
return resultCacheRegionName;
}
@Override
public LockOptions getLockOptions() {
return lockOptions;
}
@Override
public String getComment() {
return comment;
}
@Override
public List<String> getDatabaseHints() {
return databaseHints;
}
@Override
public Integer getFetchSize() {
return fetchSize;
}
@Override
public Limit getLimit() {
return limit;
}
@Override
public QueryParameterBindings getQueryParameterBindings() {
return context.getQueryParameterBindings();
}
@Override
public Callback getCallback() {
return context.getCallback();
}
}
}

View File

@ -29,17 +29,13 @@ public interface ExecutionContext {
QueryOptions getQueryOptions();
default LoadQueryInfluencers getLoadQueryInfluencers() {
return getSession().getLoadQueryInfluencers();
}
LoadQueryInfluencers getLoadQueryInfluencers();
QueryParameterBindings getQueryParameterBindings();
Callback getCallback();
default String getQueryIdentifier(String sql) {
return null;
}
String getQueryIdentifier(String sql);
/**
* Get the collection key for the collection which is to be loaded immediately.

View File

@ -6,10 +6,10 @@
*/
package org.hibernate.sql.results.graph.embeddable.internal;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.results.graph.Initializer;
import org.hibernate.sql.results.graph.entity.EntityFetch;
@ -17,13 +17,14 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
import org.hibernate.sql.results.jdbc.spi.RowProcessingState;
import org.hibernate.sql.results.spi.RowReader;
public class NestedRowProcessingState implements RowProcessingState {
public class NestedRowProcessingState extends BaseExecutionContext implements RowProcessingState {
private final AggregateEmbeddableInitializer aggregateEmbeddableInitializer;
final RowProcessingState processingState;
public NestedRowProcessingState(
AggregateEmbeddableInitializer aggregateEmbeddableInitializer,
RowProcessingState processingState) {
super( processingState.getSession() );
this.aggregateEmbeddableInitializer = aggregateEmbeddableInitializer;
this.processingState = processingState;
}
@ -78,11 +79,6 @@ public class NestedRowProcessingState implements RowProcessingState {
return processingState.resolveInitializer( path );
}
@Override
public SharedSessionContractImplementor getSession() {
return processingState.getSession();
}
@Override
public QueryOptions getQueryOptions() {
return processingState.getQueryOptions();

View File

@ -9,10 +9,10 @@ package org.hibernate.sql.results.internal;
import java.util.List;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterBindings;
import org.hibernate.sql.exec.internal.BaseExecutionContext;
import org.hibernate.sql.exec.spi.Callback;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.results.graph.Initializer;
@ -27,7 +27,7 @@ import org.hibernate.sql.results.spi.RowReader;
/**
* Standard RowProcessingState implementation
*/
public class RowProcessingStateStandardImpl implements RowProcessingState {
public class RowProcessingStateStandardImpl extends BaseExecutionContext implements RowProcessingState {
private static final Initializer[] NO_INITIALIZERS = new Initializer[0];
private final JdbcValuesSourceProcessingStateStandardImpl resultSetProcessingState;
@ -44,6 +44,7 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
ExecutionContext executionContext,
RowReader<?> rowReader,
JdbcValues jdbcValues) {
super( resultSetProcessingState.getSession() );
this.resultSetProcessingState = resultSetProcessingState;
this.executionContext = executionContext;
this.rowReader = rowReader;
@ -154,11 +155,6 @@ public class RowProcessingStateStandardImpl implements RowProcessingState {
public void finishRowProcessing() {
}
@Override
public SharedSessionContractImplementor getSession() {
return getJdbcValuesSourceProcessingState().getExecutionContext().getSession();
}
@Override
public QueryOptions getQueryOptions() {
return executionContext.getQueryOptions();

View File

@ -30,9 +30,7 @@ import org.hibernate.sql.exec.spi.ExecutionContext;
public interface JdbcValuesSourceProcessingState {
ExecutionContext getExecutionContext();
default SharedSessionContractImplementor getSession() {
return getExecutionContext().getSession();
}
SharedSessionContractImplementor getSession();
default QueryOptions getQueryOptions() {
return getExecutionContext().getQueryOptions();