some very minor cleanups

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-08-21 12:26:41 +02:00
parent afca93158e
commit d4740a9bc8
2 changed files with 30 additions and 90 deletions

View File

@ -41,30 +41,6 @@ import jakarta.persistence.CacheStoreMode;
@Incubating
public interface JdbcSelectExecutor {
/**
* @since 6.4
* @deprecated Use {@link #executeQuery(JdbcOperationQuerySelect, JdbcParameterBindings, ExecutionContext, RowTransformer, Class, StatementCreator, ResultsConsumer)} instead
*/
@Deprecated(forRemoval = true, since = "6.6")
default <T, R> T executeQuery(
JdbcOperationQuerySelect jdbcSelect,
JdbcParameterBindings jdbcParameterBindings,
ExecutionContext executionContext,
RowTransformer<R> rowTransformer,
Class<R> domainResultType,
Function<String, PreparedStatement> statementCreator,
ResultsConsumer<T, R> resultsConsumer) {
return executeQuery(
jdbcSelect,
jdbcParameterBindings,
executionContext,
rowTransformer,
domainResultType,
(executionContext1, sql) -> statementCreator.apply( sql ),
resultsConsumer
);
}
/**
* @since 6.6
*/
@ -213,8 +189,9 @@ public interface JdbcSelectExecutor {
}
/*
When `Query#scroll()` is call the query is not executed immediately, a new ExecutionContext with the values of the `persistenceContext.isDefaultReadOnly()` and of the `queryOptions.isReadOnly()`
set at the moment of the Query#scroll() call is created in order to use it when the query will be executed.
When `Query#scroll()` is call the query is not executed immediately, a new ExecutionContext with the values
of the `persistenceContext.isDefaultReadOnly()` and of the `queryOptions.isReadOnly()` set at the moment of
the Query#scroll() call is created in order to use it when the query will be executed.
*/
private ExecutionContext getScrollContext(ExecutionContext context) {
class ScrollableExecutionContext extends BaseExecutionContext implements QueryOptions {
@ -388,45 +365,25 @@ public interface JdbcSelectExecutor {
}
}
final QueryOptions queryOptions = context.getQueryOptions();
final Boolean readOnly;
if ( queryOptions.isReadOnly() == null ) {
readOnly = context.getSession().getPersistenceContext().isDefaultReadOnly();
}
else {
readOnly = queryOptions.isReadOnly();
}
final Integer timeout = queryOptions.getTimeout();
final FlushMode flushMode = queryOptions.getFlushMode();
final AppliedGraph appliedGraph = queryOptions.getAppliedGraph();
final TupleTransformer<?> tupleTransformer = queryOptions.getTupleTransformer();
final ResultListTransformer<?> resultListTransformer = queryOptions.getResultListTransformer();
final Boolean resultCachingEnabled = queryOptions.isResultCachingEnabled();
final CacheRetrieveMode cacheRetrieveMode = queryOptions.getCacheRetrieveMode();
final CacheStoreMode cacheStoreMode = queryOptions.getCacheStoreMode();
final String resultCacheRegionName = queryOptions.getResultCacheRegionName();
final LockOptions lockOptions = queryOptions.getLockOptions();
final String comment = queryOptions.getComment();
final List<String> databaseHints = queryOptions.getDatabaseHints();
final Integer fetchSize = queryOptions.getFetchSize();
final Limit limit = queryOptions.getLimit();
final QueryOptions options = context.getQueryOptions();
return new ScrollableExecutionContext(
timeout,
flushMode,
readOnly,
appliedGraph,
tupleTransformer,
resultListTransformer,
resultCachingEnabled,
cacheRetrieveMode,
cacheStoreMode,
resultCacheRegionName,
lockOptions,
comment,
databaseHints,
fetchSize,
limit,
options.getTimeout(),
options.getFlushMode(),
options.isReadOnly() == null
? context.getSession().getPersistenceContext().isDefaultReadOnly()
: options.isReadOnly(),
options.getAppliedGraph(),
options.getTupleTransformer(),
options.getResultListTransformer(),
options.isResultCachingEnabled(),
options.getCacheRetrieveMode(),
options.getCacheStoreMode(),
options.getResultCacheRegionName(),
options.getLockOptions(),
options.getComment(),
options.getDatabaseHints(),
options.getFetchSize(),
options.getLimit(),
context
);
}

View File

@ -10,7 +10,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.EntityHolder;
@ -18,13 +17,9 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PreLoadEvent;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.query.spi.QueryOptions;
import org.hibernate.sql.exec.spi.ExecutionContext;
import org.hibernate.sql.results.graph.collection.CollectionInitializer;
import org.hibernate.sql.results.graph.collection.LoadingCollectionEntry;
import org.hibernate.sql.results.graph.collection.internal.ArrayInitializer;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingOptions;
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
@ -33,8 +28,6 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
*/
public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSourceProcessingState {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( JdbcValuesSourceProcessingStateStandardImpl.class );
private final ExecutionContext executionContext;
private final JdbcValuesSourceProcessingOptions processingOptions;
@ -115,11 +108,7 @@ public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSo
@Override
public LoadingCollectionEntry findLoadingCollectionLocally(CollectionKey key) {
if ( loadingCollectionMap == null ) {
return null;
}
return loadingCollectionMap.get( key );
return loadingCollectionMap == null ? null : loadingCollectionMap.get( key );
}
@Override
@ -141,28 +130,22 @@ public class JdbcValuesSourceProcessingStateStandardImpl implements JdbcValuesSo
// now we can finalize loading collections
finishLoadingCollections();
final Consumer<EntityHolder> holderConsumer;
if ( registerSubselects ) {
holderConsumer = executionContext::registerLoadingEntityHolder;
}
else {
holderConsumer = null;
}
executionContext.getSession().getPersistenceContextInternal().postLoad( this, holderConsumer );
getSession().getPersistenceContextInternal()
.postLoad( this,
registerSubselects ? executionContext::registerLoadingEntityHolder : null );
}
@SuppressWarnings("SimplifiableIfStatement")
private boolean isReadOnly() {
if ( getQueryOptions().isReadOnly() != null ) {
return getQueryOptions().isReadOnly();
}
if ( executionContext.getSession() instanceof EventSource ) {
return executionContext.getSession().isDefaultReadOnly();
else if ( getSession() instanceof EventSource ) {
return getSession().isDefaultReadOnly();
}
else {
return false;
}
}
private void finishLoadingCollections() {