1515import java .util .Map ;
1616import java .util .Set ;
1717
18- import org .hibernate .CacheMode ;
1918import org .hibernate .FlushMode ;
2019import org .hibernate .query .QueryFlushMode ;
2120import org .hibernate .HibernateException ;
4039import org .hibernate .query .CommonQueryContract ;
4140import org .hibernate .query .QueryLogging ;
4241import org .hibernate .query .QueryParameter ;
43- import org .hibernate .query .ResultListTransformer ;
44- import org .hibernate .query .TupleTransformer ;
4542import org .hibernate .query .TypedParameterValue ;
4643import org .hibernate .query .criteria .JpaExpression ;
4744import org .hibernate .query .internal .QueryOptionsImpl ;
5653import jakarta .persistence .CacheRetrieveMode ;
5754import jakarta .persistence .CacheStoreMode ;
5855import jakarta .persistence .EntityGraph ;
59- import jakarta .persistence .FlushModeType ;
6056import jakarta .persistence .LockModeType ;
6157import jakarta .persistence .Parameter ;
6258import jakarta .persistence .TemporalType ;
@@ -145,15 +141,11 @@ else if ( expression instanceof SqmParameter<?> ) {
145141 throw new IllegalArgumentException ( "Can't get max rows value from: " + expression );
146142 }
147143 // Note that we can never have ties because this is only used when we de-duplicate results
148- switch ( selectStatement .getFetchClauseType () ) {
149- case ROWS_ONLY :
150- case ROWS_WITH_TIES :
151- return fetchValue .intValue ();
152- case PERCENT_ONLY :
153- case PERCENT_WITH_TIES :
154- return (int ) Math .ceil ( ( ( (double ) size ) * fetchValue .doubleValue () ) / 100d );
155- }
156- throw new UnsupportedOperationException ( "Unsupported fetch clause type: " + selectStatement .getFetchClauseType () );
144+ return switch ( selectStatement .getFetchClauseType () ) {
145+ case ROWS_ONLY , ROWS_WITH_TIES -> fetchValue .intValue ();
146+ case PERCENT_ONLY , PERCENT_WITH_TIES ->
147+ (int ) Math .ceil ( ( ((double ) size ) * fetchValue .doubleValue () ) / 100d );
148+ };
157149 }
158150
159151
@@ -244,13 +236,14 @@ protected void putIfNotNull(Map<String, Object> hints, String hintName, Object h
244236
245237 @ Override
246238 public CommonQueryContract setHint (String hintName , Object value ) {
247- applyHint ( hintName , value );
239+ if ( !applyHint ( hintName , value ) ) {
240+ QueryLogging .QUERY_MESSAGE_LOGGER .ignoringUnrecognizedQueryHint ( hintName );
241+ }
248242 return this ;
249243 }
250244
251245 public final boolean applyHint (String hintName , Object value ) {
252246 getSession ().checkOpen ( true );
253-
254247 try {
255248 switch ( hintName ) {
256249 case HINT_FLUSH_MODE :
@@ -277,13 +270,7 @@ public final boolean applyHint(String hintName, Object value) {
277270 applyDatabaseHint ( (String ) value );
278271 return true ;
279272 default :
280- if ( applySelectionHint ( hintName , value ) || applyAdditionalPossibleHints ( hintName , value ) ) {
281- return true ;
282- }
283- else {
284- QueryLogging .QUERY_MESSAGE_LOGGER .ignoringUnrecognizedQueryHint ( hintName );
285- return false ;
286- }
273+ return applySelectionHint ( hintName , value );
287274 }
288275 }
289276 catch ( ClassCastException e ) {
@@ -300,36 +287,41 @@ protected final boolean applySelectionHint(String hintName, Object value) {
300287 return true ;
301288 }
302289 else {
290+ final MutableQueryOptions queryOptions = getQueryOptions ();
303291 switch ( hintName ) {
304292 case HINT_READONLY :
305- applyReadOnlyHint ( getBoolean ( value ) );
293+ queryOptions . setReadOnly ( getBoolean ( value ) );
306294 return true ;
307295 case HINT_FETCH_SIZE :
308- applyFetchSizeHint ( getInteger ( value ) );
296+ queryOptions . setFetchSize ( getInteger ( value ) );
309297 return true ;
310298 case HINT_QUERY_PLAN_CACHEABLE :
311- applyQueryPlanCacheableHint ( getBoolean ( value ) );
299+ queryOptions . setQueryPlanCachingEnabled ( getBoolean ( value ) );
312300 return true ;
313301 case HINT_CACHEABLE :
314- applyCacheableHint ( getBoolean ( value ) );
302+ queryOptions . setResultCachingEnabled ( getBoolean ( value ) );
315303 return true ;
316304 case HINT_CACHE_REGION :
317- applyCacheRegionHint ( (String ) value );
305+ queryOptions . setResultCacheRegionName ( (String ) value );
318306 return true ;
319307 case HINT_CACHE_MODE :
320- applyCacheModeHint ( getCacheMode ( value ) );
308+ queryOptions . setCacheMode ( getCacheMode ( value ) );
321309 return true ;
322310 case HINT_JAVAEE_CACHE_RETRIEVE_MODE :
323311 DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_CACHE_RETRIEVE_MODE , HINT_SPEC_CACHE_RETRIEVE_MODE );
324312 //fall through to:
325313 case HINT_SPEC_CACHE_RETRIEVE_MODE :
326- applyJpaCacheRetrieveModeHint ( value != null ? CacheRetrieveMode .valueOf ( value .toString () ) : null );
314+ final CacheRetrieveMode retrieveMode =
315+ value == null ? null : CacheRetrieveMode .valueOf ( value .toString () );
316+ queryOptions .setCacheRetrieveMode ( retrieveMode );
327317 return true ;
328318 case HINT_JAVAEE_CACHE_STORE_MODE :
329319 DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_CACHE_STORE_MODE , HINT_SPEC_CACHE_STORE_MODE );
330320 //fall through to:
331321 case HINT_SPEC_CACHE_STORE_MODE :
332- applyJpaCacheStoreModeHint ( value != null ? CacheStoreMode .valueOf ( value .toString () ) : null );
322+ final CacheStoreMode storeMode =
323+ value == null ? null : CacheStoreMode .valueOf ( value .toString () );
324+ queryOptions .setCacheStoreMode ( storeMode );
333325 return true ;
334326 case HINT_JAVAEE_FETCH_GRAPH :
335327 DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_FETCH_GRAPH , HINT_SPEC_FETCH_GRAPH );
@@ -350,37 +342,13 @@ protected final boolean applySelectionHint(String hintName, Object value) {
350342 }
351343 }
352344
353- protected void applyFetchSizeHint (int fetchSize ) {
354- getQueryOptions ().setFetchSize ( fetchSize );
355- }
356-
357- protected void applyQueryPlanCacheableHint (boolean isCacheable ) {
358- getQueryOptions ().setQueryPlanCachingEnabled ( isCacheable );
359- }
360-
361- protected void applyCacheModeHint (CacheMode cacheMode ) {
362- getQueryOptions ().setCacheMode ( cacheMode );
363- }
364-
365- protected void applyCacheableHint (boolean isCacheable ) {
366- getQueryOptions ().setResultCachingEnabled ( isCacheable );
367- }
368-
369- protected void applyCacheRegionHint (String regionName ) {
370- getQueryOptions ().setResultCacheRegionName ( regionName );
371- }
372-
373- private void applyReadOnlyHint (Boolean readOnly ) {
374- getQueryOptions ().setReadOnly ( readOnly );
375- }
376-
377345 protected void applyEntityGraphHint (String hintName , Object value ) {
378346 final GraphSemantic graphSemantic = GraphSemantic .fromHintName ( hintName );
379- if ( value instanceof RootGraphImplementor ) {
380- applyGraph ( ( RootGraphImplementor <?>) value , graphSemantic );
347+ if ( value instanceof RootGraphImplementor <?> rootGraphImplementor ) {
348+ applyGraph ( rootGraphImplementor , graphSemantic );
381349 }
382- else if ( value instanceof String ) {
383- applyGraph ( ( String ) value , graphSemantic );
350+ else if ( value instanceof String string ) {
351+ applyGraph ( string , graphSemantic );
384352 }
385353 else {
386354 throw new IllegalArgumentException ( "The value of the hint '" + hintName
@@ -465,11 +433,11 @@ protected void applyLockModeType(LockModeType value) {
465433 }
466434
467435 protected final void applyLockModeHint (Object value ) {
468- if ( value instanceof LockMode ) {
469- applyHibernateLockMode ( ( LockMode ) value );
436+ if ( value instanceof LockMode lockMode ) {
437+ applyHibernateLockMode ( lockMode );
470438 }
471- else if ( value instanceof LockModeType ) {
472- applyLockModeType ( ( LockModeType ) value );
439+ else if ( value instanceof LockModeType lockModeType ) {
440+ applyLockModeType ( lockModeType );
473441 }
474442 else if ( value instanceof String ) {
475443 applyHibernateLockMode ( interpretLockMode ( value ) );
@@ -503,10 +471,6 @@ protected void applyFollowOnLockingHint(Boolean followOnLocking) {
503471 getQueryOptions ().getLockOptions ().setFollowOnLocking ( followOnLocking );
504472 }
505473
506- protected boolean applyAdditionalPossibleHints (String hintName , Object value ) {
507- return false ;
508- }
509-
510474
511475 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
512476 // Options
@@ -543,16 +507,6 @@ public CommonQueryContract setQueryFlushMode(QueryFlushMode queryFlushMode) {
543507 return this ;
544508 }
545509
546- protected boolean applyJpaCacheRetrieveModeHint (CacheRetrieveMode retrieveMode ) {
547- getQueryOptions ().setCacheRetrieveMode ( retrieveMode );
548- return true ;
549- }
550-
551- protected boolean applyJpaCacheStoreModeHint (CacheStoreMode storeMode ) {
552- getQueryOptions ().setCacheStoreMode ( storeMode );
553- return true ;
554- }
555-
556510 protected void applyTimeoutHint (int timeout ) {
557511 setTimeout ( timeout );
558512 }
@@ -593,51 +547,11 @@ public int getMaxResults() {
593547 return getQueryOptions ().getLimit ().getMaxRowsJpa ();
594548 }
595549
596- public void applyMaxResults (int maxResult ) {
597- if ( maxResult < 0 ) {
598- throw new IllegalArgumentException ( "max-results cannot be negative" );
599- }
600- getSession ().checkOpen ();
601- getQueryOptions ().getLimit ().setMaxRows ( maxResult );
602- }
603-
604550 public int getFirstResult () {
605551 getSession ().checkOpen ();
606552 return getQueryOptions ().getLimit ().getFirstRowJpa ();
607553 }
608554
609- public void applyFirstResult (int startPosition ) {
610- if ( startPosition < 0 ) {
611- throw new IllegalArgumentException ( "first-result value cannot be negative : " + startPosition );
612- }
613-
614- getSession ().checkOpen ();
615- getQueryOptions ().getLimit ().setFirstRow ( startPosition );
616- }
617-
618- protected FlushModeType getJpaFlushMode () {
619- getSession ().checkOpen ();
620- final FlushMode flushMode = getQueryOptions ().getFlushMode () == null
621- ? getSession ().getHibernateFlushMode ()
622- : getQueryOptions ().getFlushMode ();
623- return FlushModeTypeHelper .getFlushModeType ( flushMode );
624- }
625-
626- protected void applyJpaFlushMode (FlushModeType flushModeType ) {
627- getSession ().checkOpen ();
628- setHibernateFlushMode ( FlushModeTypeHelper .getFlushMode ( flushModeType ) );
629- }
630-
631- public boolean applyTupleTransformer (TupleTransformer <?> transformer ) {
632- getQueryOptions ().setTupleTransformer ( transformer );
633- return true ;
634- }
635-
636- public boolean applyResultListTransformer (ResultListTransformer <?> transformer ) {
637- getQueryOptions ().setResultListTransformer ( transformer );
638- return true ;
639- }
640-
641555
642556 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
643557 // Parameter handling
0 commit comments