Skip to content

Commit f4da8aa

Browse files
committed
lots of cleanups in the Query hierarchy
1 parent bc3e83f commit f4da8aa

File tree

8 files changed

+581
-580
lines changed

8 files changed

+581
-580
lines changed

hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java

Lines changed: 160 additions & 138 deletions
Large diffs are not rendered by default.

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractCommonQueryContract.java

Lines changed: 96 additions & 91 deletions
Large diffs are not rendered by default.

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -337,32 +337,35 @@ public Set<String> getSupportedHints() {
337337

338338
@Override
339339
protected void collectHints(Map<String, Object> hints) {
340-
if ( getQueryOptions().getTimeout() != null ) {
341-
hints.put( HINT_TIMEOUT, getQueryOptions().getTimeout() );
342-
hints.put( HINT_SPEC_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
343-
hints.put( HINT_JAVAEE_QUERY_TIMEOUT, getQueryOptions().getTimeout() * 1000 );
340+
final var queryOptions = getQueryOptions();
341+
final var lockOptions = getLockOptions();
342+
343+
if ( queryOptions.getTimeout() != null ) {
344+
hints.put( HINT_TIMEOUT, queryOptions.getTimeout() );
345+
hints.put( HINT_SPEC_QUERY_TIMEOUT, queryOptions.getTimeout() * 1000 );
346+
hints.put( HINT_JAVAEE_QUERY_TIMEOUT, queryOptions.getTimeout() * 1000 );
344347
}
345348

346-
if ( getLockOptions().getTimeout().milliseconds() != Timeouts.WAIT_FOREVER_MILLI ) {
347-
hints.put( HINT_SPEC_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
348-
hints.put( HINT_JAVAEE_LOCK_TIMEOUT, getLockOptions().getTimeOut() );
349+
if ( lockOptions.getTimeout().milliseconds() != Timeouts.WAIT_FOREVER_MILLI ) {
350+
hints.put( HINT_SPEC_LOCK_TIMEOUT, lockOptions.getTimeOut() );
351+
hints.put( HINT_JAVAEE_LOCK_TIMEOUT, lockOptions.getTimeOut() );
349352
}
350353

351-
if ( getLockOptions().getLockScope() == PessimisticLockScope.EXTENDED ) {
352-
hints.put( HINT_SPEC_LOCK_SCOPE, getLockOptions().getLockScope() );
353-
hints.put( HINT_JAVAEE_LOCK_SCOPE, getLockOptions().getLockScope() );
354+
if ( lockOptions.getLockScope() == PessimisticLockScope.EXTENDED ) {
355+
hints.put( HINT_SPEC_LOCK_SCOPE, lockOptions.getLockScope() );
356+
hints.put( HINT_JAVAEE_LOCK_SCOPE, lockOptions.getLockScope() );
354357
}
355358

356359
putIfNotNull( hints, HINT_COMMENT, getComment() );
357-
putIfNotNull( hints, HINT_FETCH_SIZE, getQueryOptions().getFetchSize() );
358-
putIfNotNull( hints, HINT_FLUSH_MODE, getQueryOptions().getFlushMode() );
360+
putIfNotNull( hints, HINT_FETCH_SIZE, queryOptions.getFetchSize() );
361+
putIfNotNull( hints, HINT_FLUSH_MODE, queryOptions.getFlushMode() );
359362

360363
if ( getCacheMode() != null ) {
361364
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
362-
putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
363-
putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
364-
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
365-
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
365+
putIfNotNull( hints, HINT_SPEC_CACHE_RETRIEVE_MODE, queryOptions.getCacheRetrieveMode() );
366+
putIfNotNull( hints, HINT_SPEC_CACHE_STORE_MODE, queryOptions.getCacheStoreMode() );
367+
putIfNotNull( hints, HINT_JAVAEE_CACHE_RETRIEVE_MODE, queryOptions.getCacheRetrieveMode() );
368+
putIfNotNull( hints, HINT_JAVAEE_CACHE_STORE_MODE, queryOptions.getCacheStoreMode() );
366369
}
367370

368371
if ( isCacheable() ) {

hibernate-core/src/main/java/org/hibernate/query/spi/AbstractSelectionQuery.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.List;
1313
import java.util.Map;
1414
import java.util.Optional;
15-
import java.util.Spliterator;
1615
import java.util.stream.Stream;
1716
import java.util.stream.StreamSupport;
1817

@@ -33,7 +32,6 @@
3332
import org.hibernate.UnknownProfileException;
3433
import org.hibernate.engine.spi.SharedSessionContractImplementor;
3534
import org.hibernate.graph.GraphSemantic;
36-
import org.hibernate.graph.spi.AppliedGraph;
3735
import org.hibernate.graph.spi.RootGraphImplementor;
3836
import org.hibernate.jpa.internal.util.FlushModeTypeHelper;
3937
import org.hibernate.jpa.internal.util.LockModeTypeHelper;
@@ -55,6 +53,7 @@
5553
import jakarta.persistence.TemporalType;
5654
import jakarta.persistence.metamodel.Type;
5755

56+
import static java.util.Spliterator.NONNULL;
5857
import static java.util.Spliterators.spliteratorUnknownSize;
5958
import static org.hibernate.CacheMode.fromJpaModes;
6059
import static org.hibernate.cfg.AvailableSettings.JAKARTA_SHARED_CACHE_RETRIEVE_MODE;
@@ -168,30 +167,30 @@ public List<R> list() {
168167

169168
protected HashSet<String> beforeQueryHandlingFetchProfiles() {
170169
beforeQuery();
171-
final MutableQueryOptions options = getQueryOptions();
170+
final var options = getQueryOptions();
172171
return getSession().getLoadQueryInfluencers()
173172
.adjustFetchProfiles( options.getDisabledFetchProfiles(), options.getEnabledFetchProfiles() );
174173
}
175174

176175
protected void beforeQuery() {
177176
getQueryParameterBindings().validate();
178177

179-
final SharedSessionContractImplementor session = getSession();
180-
final MutableQueryOptions options = getQueryOptions();
178+
final var session = getSession();
179+
final var options = getQueryOptions();
181180

182181
session.prepareForQueryExecution( requiresTxn( options.getLockOptions().getLockMode() ) );
183182
prepareForExecution();
184183

185184
assert sessionFlushMode == null;
186185
assert sessionCacheMode == null;
187186

188-
final FlushMode effectiveFlushMode = getQueryOptions().getFlushMode();
187+
final var effectiveFlushMode = getQueryOptions().getFlushMode();
189188
if ( effectiveFlushMode != null && session instanceof SessionImplementor statefulSession ) {
190189
sessionFlushMode = statefulSession.getHibernateFlushMode();
191190
statefulSession.setHibernateFlushMode( effectiveFlushMode );
192191
}
193192

194-
final CacheMode effectiveCacheMode = getCacheMode();
193+
final var effectiveCacheMode = getCacheMode();
195194
if ( effectiveCacheMode != null ) {
196195
sessionCacheMode = session.getCacheMode();
197196
session.setCacheMode( effectiveCacheMode );
@@ -217,7 +216,7 @@ private void resetFetchProfiles(HashSet<String> fetchProfiles) {
217216
protected void afterQuery(boolean success) {
218217
afterQuery();
219218

220-
final SharedSessionContractImplementor session = getSession();
219+
final var session = getSession();
221220
if ( !session.isTransactionInProgress() ) {
222221
session.getJdbcCoordinator().getLogicalConnection().afterTransaction();
223222
}
@@ -249,7 +248,7 @@ public ScrollableResultsImplementor<R> scroll() {
249248

250249
@Override
251250
public ScrollableResultsImplementor<R> scroll(ScrollMode scrollMode) {
252-
final HashSet<String> fetchProfiles = beforeQueryHandlingFetchProfiles();
251+
final var fetchProfiles = beforeQueryHandlingFetchProfiles();
253252
try {
254253
return doScroll( scrollMode );
255254
}
@@ -268,8 +267,7 @@ public Stream<R> getResultStream() {
268267
@Override
269268
public Stream<R> stream() {
270269
final ScrollableResults<R> results = scroll( ScrollMode.FORWARD_ONLY );
271-
final Spliterator<R> spliterator =
272-
spliteratorUnknownSize( new ScrollableResultsIterator<>( results ), Spliterator.NONNULL );
270+
final var spliterator = spliteratorUnknownSize( new ScrollableResultsIterator<>( results ), NONNULL );
273271
return StreamSupport.stream( spliterator, false ).onClose( results::close );
274272
}
275273

@@ -392,7 +390,7 @@ public SelectionQuery<R> setEntityGraph(EntityGraph<? super R> graph, GraphSeman
392390

393391
@Override
394392
public SelectionQuery<R> enableFetchProfile(String profileName) {
395-
if ( this.getSessionFactory().containsFetchProfileDefinition( profileName ) ) {
393+
if ( getSessionFactory().containsFetchProfileDefinition( profileName ) ) {
396394
getQueryOptions().enableFetchProfile( profileName );
397395
return this;
398396
}
@@ -491,27 +489,32 @@ protected void collectHints(Map<String, Object> hints) {
491489

492490
putIfNotNull( hints, HINT_FETCH_SIZE, getFetchSize() );
493491

492+
final var queryOptions = getQueryOptions();
493+
494494
if ( isCacheable() ) {
495495
hints.put( HINT_CACHEABLE, true );
496496
putIfNotNull( hints, HINT_CACHE_REGION, getCacheRegion() );
497-
498497
putIfNotNull( hints, HINT_CACHE_MODE, getCacheMode() );
499-
putIfNotNull( hints, JAKARTA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
500-
putIfNotNull( hints, JAKARTA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
498+
putIfNotNull( hints, JAKARTA_SHARED_CACHE_RETRIEVE_MODE, queryOptions.getCacheRetrieveMode() );
499+
putIfNotNull( hints, JAKARTA_SHARED_CACHE_STORE_MODE, queryOptions.getCacheStoreMode() );
501500
//noinspection deprecation
502-
putIfNotNull( hints, JPA_SHARED_CACHE_RETRIEVE_MODE, getQueryOptions().getCacheRetrieveMode() );
501+
putIfNotNull( hints, JPA_SHARED_CACHE_RETRIEVE_MODE, queryOptions.getCacheRetrieveMode() );
503502
//noinspection deprecation
504-
putIfNotNull( hints, JPA_SHARED_CACHE_STORE_MODE, getQueryOptions().getCacheStoreMode() );
503+
putIfNotNull( hints, JPA_SHARED_CACHE_STORE_MODE, queryOptions.getCacheStoreMode() );
505504
}
506505

507-
final AppliedGraph appliedGraph = getQueryOptions().getAppliedGraph();
508-
if ( appliedGraph != null && appliedGraph.getSemantic() != null ) {
509-
hints.put( appliedGraph.getSemantic().getJakartaHintName(), appliedGraph );
510-
hints.put( appliedGraph.getSemantic().getJpaHintName(), appliedGraph );
506+
final var appliedGraph = queryOptions.getAppliedGraph();
507+
if ( appliedGraph != null ) {
508+
final var semantic = appliedGraph.getSemantic();
509+
if ( semantic != null ) {
510+
hints.put( semantic.getJakartaHintName(), appliedGraph );
511+
hints.put( semantic.getJpaHintName(), appliedGraph );
512+
}
511513
}
512514

513-
putIfNotNull( hints, HINT_FOLLOW_ON_LOCKING, getQueryOptions().getLockOptions().getFollowOnLocking() );
514-
putIfNotNull( hints, HINT_FOLLOW_ON_STRATEGY, getQueryOptions().getLockOptions().getFollowOnStrategy() );
515+
final var lockOptions = queryOptions.getLockOptions();
516+
putIfNotNull( hints, HINT_FOLLOW_ON_LOCKING, lockOptions.getFollowOnLocking() );
517+
putIfNotNull( hints, HINT_FOLLOW_ON_STRATEGY, lockOptions.getFollowOnStrategy() );
515518
}
516519

517520
@Override

0 commit comments

Comments
 (0)