1212import java .util .List ;
1313import java .util .Map ;
1414import java .util .Optional ;
15- import java .util .Spliterator ;
1615import java .util .stream .Stream ;
1716import java .util .stream .StreamSupport ;
1817
3332import org .hibernate .UnknownProfileException ;
3433import org .hibernate .engine .spi .SharedSessionContractImplementor ;
3534import org .hibernate .graph .GraphSemantic ;
36- import org .hibernate .graph .spi .AppliedGraph ;
3735import org .hibernate .graph .spi .RootGraphImplementor ;
3836import org .hibernate .jpa .internal .util .FlushModeTypeHelper ;
3937import org .hibernate .jpa .internal .util .LockModeTypeHelper ;
5553import jakarta .persistence .TemporalType ;
5654import jakarta .persistence .metamodel .Type ;
5755
56+ import static java .util .Spliterator .NONNULL ;
5857import static java .util .Spliterators .spliteratorUnknownSize ;
5958import static org .hibernate .CacheMode .fromJpaModes ;
6059import 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