15
15
import java .util .Map ;
16
16
import java .util .Set ;
17
17
18
- import org .hibernate .CacheMode ;
19
18
import org .hibernate .FlushMode ;
20
19
import org .hibernate .query .QueryFlushMode ;
21
20
import org .hibernate .HibernateException ;
40
39
import org .hibernate .query .CommonQueryContract ;
41
40
import org .hibernate .query .QueryLogging ;
42
41
import org .hibernate .query .QueryParameter ;
43
- import org .hibernate .query .ResultListTransformer ;
44
- import org .hibernate .query .TupleTransformer ;
45
42
import org .hibernate .query .TypedParameterValue ;
46
43
import org .hibernate .query .criteria .JpaExpression ;
47
44
import org .hibernate .query .internal .QueryOptionsImpl ;
56
53
import jakarta .persistence .CacheRetrieveMode ;
57
54
import jakarta .persistence .CacheStoreMode ;
58
55
import jakarta .persistence .EntityGraph ;
59
- import jakarta .persistence .FlushModeType ;
60
56
import jakarta .persistence .LockModeType ;
61
57
import jakarta .persistence .Parameter ;
62
58
import jakarta .persistence .TemporalType ;
@@ -145,15 +141,11 @@ else if ( expression instanceof SqmParameter<?> ) {
145
141
throw new IllegalArgumentException ( "Can't get max rows value from: " + expression );
146
142
}
147
143
// 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
+ };
157
149
}
158
150
159
151
@@ -244,13 +236,14 @@ protected void putIfNotNull(Map<String, Object> hints, String hintName, Object h
244
236
245
237
@ Override
246
238
public CommonQueryContract setHint (String hintName , Object value ) {
247
- applyHint ( hintName , value );
239
+ if ( !applyHint ( hintName , value ) ) {
240
+ QueryLogging .QUERY_MESSAGE_LOGGER .ignoringUnrecognizedQueryHint ( hintName );
241
+ }
248
242
return this ;
249
243
}
250
244
251
245
public final boolean applyHint (String hintName , Object value ) {
252
246
getSession ().checkOpen ( true );
253
-
254
247
try {
255
248
switch ( hintName ) {
256
249
case HINT_FLUSH_MODE :
@@ -277,13 +270,7 @@ public final boolean applyHint(String hintName, Object value) {
277
270
applyDatabaseHint ( (String ) value );
278
271
return true ;
279
272
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 );
287
274
}
288
275
}
289
276
catch ( ClassCastException e ) {
@@ -300,36 +287,41 @@ protected final boolean applySelectionHint(String hintName, Object value) {
300
287
return true ;
301
288
}
302
289
else {
290
+ final MutableQueryOptions queryOptions = getQueryOptions ();
303
291
switch ( hintName ) {
304
292
case HINT_READONLY :
305
- applyReadOnlyHint ( getBoolean ( value ) );
293
+ queryOptions . setReadOnly ( getBoolean ( value ) );
306
294
return true ;
307
295
case HINT_FETCH_SIZE :
308
- applyFetchSizeHint ( getInteger ( value ) );
296
+ queryOptions . setFetchSize ( getInteger ( value ) );
309
297
return true ;
310
298
case HINT_QUERY_PLAN_CACHEABLE :
311
- applyQueryPlanCacheableHint ( getBoolean ( value ) );
299
+ queryOptions . setQueryPlanCachingEnabled ( getBoolean ( value ) );
312
300
return true ;
313
301
case HINT_CACHEABLE :
314
- applyCacheableHint ( getBoolean ( value ) );
302
+ queryOptions . setResultCachingEnabled ( getBoolean ( value ) );
315
303
return true ;
316
304
case HINT_CACHE_REGION :
317
- applyCacheRegionHint ( (String ) value );
305
+ queryOptions . setResultCacheRegionName ( (String ) value );
318
306
return true ;
319
307
case HINT_CACHE_MODE :
320
- applyCacheModeHint ( getCacheMode ( value ) );
308
+ queryOptions . setCacheMode ( getCacheMode ( value ) );
321
309
return true ;
322
310
case HINT_JAVAEE_CACHE_RETRIEVE_MODE :
323
311
DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_CACHE_RETRIEVE_MODE , HINT_SPEC_CACHE_RETRIEVE_MODE );
324
312
//fall through to:
325
313
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 );
327
317
return true ;
328
318
case HINT_JAVAEE_CACHE_STORE_MODE :
329
319
DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_CACHE_STORE_MODE , HINT_SPEC_CACHE_STORE_MODE );
330
320
//fall through to:
331
321
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 );
333
325
return true ;
334
326
case HINT_JAVAEE_FETCH_GRAPH :
335
327
DEPRECATION_LOGGER .deprecatedSetting ( HINT_JAVAEE_FETCH_GRAPH , HINT_SPEC_FETCH_GRAPH );
@@ -350,37 +342,13 @@ protected final boolean applySelectionHint(String hintName, Object value) {
350
342
}
351
343
}
352
344
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
-
377
345
protected void applyEntityGraphHint (String hintName , Object value ) {
378
346
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 );
381
349
}
382
- else if ( value instanceof String ) {
383
- applyGraph ( ( String ) value , graphSemantic );
350
+ else if ( value instanceof String string ) {
351
+ applyGraph ( string , graphSemantic );
384
352
}
385
353
else {
386
354
throw new IllegalArgumentException ( "The value of the hint '" + hintName
@@ -465,11 +433,11 @@ protected void applyLockModeType(LockModeType value) {
465
433
}
466
434
467
435
protected final void applyLockModeHint (Object value ) {
468
- if ( value instanceof LockMode ) {
469
- applyHibernateLockMode ( ( LockMode ) value );
436
+ if ( value instanceof LockMode lockMode ) {
437
+ applyHibernateLockMode ( lockMode );
470
438
}
471
- else if ( value instanceof LockModeType ) {
472
- applyLockModeType ( ( LockModeType ) value );
439
+ else if ( value instanceof LockModeType lockModeType ) {
440
+ applyLockModeType ( lockModeType );
473
441
}
474
442
else if ( value instanceof String ) {
475
443
applyHibernateLockMode ( interpretLockMode ( value ) );
@@ -503,10 +471,6 @@ protected void applyFollowOnLockingHint(Boolean followOnLocking) {
503
471
getQueryOptions ().getLockOptions ().setFollowOnLocking ( followOnLocking );
504
472
}
505
473
506
- protected boolean applyAdditionalPossibleHints (String hintName , Object value ) {
507
- return false ;
508
- }
509
-
510
474
511
475
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
512
476
// Options
@@ -543,16 +507,6 @@ public CommonQueryContract setQueryFlushMode(QueryFlushMode queryFlushMode) {
543
507
return this ;
544
508
}
545
509
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
-
556
510
protected void applyTimeoutHint (int timeout ) {
557
511
setTimeout ( timeout );
558
512
}
@@ -593,51 +547,11 @@ public int getMaxResults() {
593
547
return getQueryOptions ().getLimit ().getMaxRowsJpa ();
594
548
}
595
549
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
-
604
550
public int getFirstResult () {
605
551
getSession ().checkOpen ();
606
552
return getQueryOptions ().getLimit ().getFirstRowJpa ();
607
553
}
608
554
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
-
641
555
642
556
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
643
557
// Parameter handling
0 commit comments