@@ -162,6 +162,8 @@ public class LockOptions implements Serializable {
162
162
private Timeout timeout ;
163
163
private PessimisticLockScope pessimisticLockScope ;
164
164
private Boolean followOnLocking ;
165
+
166
+
165
167
private Map <String , LockMode > aliasSpecificLockModes ;
166
168
167
169
/**
@@ -302,132 +304,6 @@ public LockOptions setLockMode(LockMode lockMode) {
302
304
return this ;
303
305
}
304
306
305
- /**
306
- * Set of {@link Map.Entry}s, each associating an alias with its
307
- * specified {@linkplain #setAliasSpecificLockMode alias-specific}
308
- * {@link LockMode}.
309
- *
310
- * @return an iterable with the {@link Map.Entry}s
311
- */
312
- public Set <Map .Entry <String ,LockMode >> getAliasSpecificLocks () {
313
- return aliasSpecificLockModes == null ? emptySet () : unmodifiableSet ( aliasSpecificLockModes .entrySet () );
314
- }
315
-
316
- /**
317
- * Specify the {@link LockMode} to be used for the given query alias.
318
- *
319
- * @param alias the query alias to which the lock mode applies
320
- * @param lockMode the lock mode to apply to the given alias
321
- * @return {@code this} for method chaining
322
- *
323
- * @see org.hibernate.query.Query#setLockMode(String, LockMode)
324
- */
325
- public LockOptions setAliasSpecificLockMode (String alias , LockMode lockMode ) {
326
- if ( immutable ) {
327
- throw new UnsupportedOperationException ("immutable global instance of LockOptions" );
328
- }
329
- if ( aliasSpecificLockModes == null ) {
330
- aliasSpecificLockModes = new LinkedHashMap <>();
331
- }
332
- if ( lockMode == null ) {
333
- aliasSpecificLockModes .remove ( alias );
334
- }
335
- else {
336
- aliasSpecificLockModes .put ( alias , lockMode );
337
- }
338
- return this ;
339
- }
340
-
341
- /**
342
- * The number of aliases that have alias-specific lock modes specified.
343
- *
344
- * @return the number of explicitly defined alias lock modes.
345
- */
346
- public int getAliasLockCount () {
347
- return aliasSpecificLockModes == null ? 0 : aliasSpecificLockModes .size ();
348
- }
349
-
350
- /**
351
- * Whether this {@code LockOptions} instance defines alias-specific lock-modes
352
- *
353
- * @return {@code true} if this object defines alias-specific lock modes;
354
- * {@code false} otherwise.
355
- */
356
- public boolean hasAliasSpecificLockModes () {
357
- return aliasSpecificLockModes != null && !aliasSpecificLockModes .isEmpty ();
358
- }
359
-
360
- /**
361
- * Get the {@link LockMode} explicitly specified for the given alias
362
- * via {@link #setAliasSpecificLockMode(String, LockMode)}.
363
- * <p>
364
- * Differs from {@link #getEffectiveLockMode(String)} in that here we
365
- * only return an explicitly specified alias-specific lock mode.
366
- *
367
- * @param alias The alias for which to locate the explicit lock mode.
368
- * @return The explicit lock mode for that alias.
369
- */
370
- public LockMode getAliasSpecificLockMode (String alias ) {
371
- return aliasSpecificLockModes == null ? null : aliasSpecificLockModes .get ( alias );
372
- }
373
-
374
- /**
375
- * Iterator over {@link Map.Entry}s, each containing an alias and its
376
- * {@link LockMode}.
377
- *
378
- * @return an iterator over the {@link Map.Entry}s
379
- * @deprecated use {@link #getAliasSpecificLocks()}
380
- */
381
- @ Deprecated
382
- public Iterator <Map .Entry <String ,LockMode >> getAliasLockIterator () {
383
- return getAliasSpecificLocks ().iterator ();
384
- }
385
-
386
- /**
387
- * Determine the {@link LockMode} to apply to the given alias. If no
388
- * mode was {@linkplain #setAliasSpecificLockMode(String, LockMode)
389
- * explicitly set}, the {@linkplain #getLockMode() overall mode} is
390
- * returned. If the overall lock mode is also {@code null},
391
- * {@link LockMode#NONE} is returned.
392
- * <p>
393
- * Differs from {@link #getAliasSpecificLockMode(String)} in that here
394
- * we fall back to only returning the overall lock mode.
395
- *
396
- * @param alias The alias for which to locate the effective lock mode.
397
- * @return The effective lock mode.
398
- */
399
- public LockMode getEffectiveLockMode (String alias ) {
400
- LockMode lockMode = getAliasSpecificLockMode ( alias );
401
- if ( lockMode == null ) {
402
- lockMode = this .lockMode ;
403
- }
404
- return lockMode == null ? LockMode .NONE : lockMode ;
405
- }
406
-
407
- /**
408
- * Currently needed for follow-on locking.
409
- *
410
- * @return The greatest of all requested lock modes.
411
- */
412
- public LockMode findGreatestLockMode () {
413
- LockMode lockModeToUse = getLockMode ();
414
- if ( lockModeToUse == null ) {
415
- lockModeToUse = LockMode .NONE ;
416
- }
417
-
418
- if ( aliasSpecificLockModes == null ) {
419
- return lockModeToUse ;
420
- }
421
-
422
- for ( LockMode lockMode : aliasSpecificLockModes .values () ) {
423
- if ( lockMode .greaterThan ( lockModeToUse ) ) {
424
- lockModeToUse = lockMode ;
425
- }
426
- }
427
-
428
- return lockModeToUse ;
429
- }
430
-
431
307
/**
432
308
* The timeout associated with {@code this} options, defining a maximum
433
309
* amount of time that the database should wait to obtain a pessimistic
@@ -633,4 +509,160 @@ else if ( !(object instanceof LockOptions that) ) {
633
509
public int hashCode () {
634
510
return Objects .hash ( lockMode , timeout , aliasSpecificLockModes , followOnLocking , pessimisticLockScope );
635
511
}
512
+
513
+
514
+
515
+ /**
516
+ * Set of {@link Map.Entry}s, each associating an alias with its
517
+ * specified {@linkplain #setAliasSpecificLockMode alias-specific}
518
+ * {@link LockMode}.
519
+ *
520
+ * @return an iterable with the {@link Map.Entry}s
521
+ *
522
+ * @apiNote This will be removed in 7.1 and replaced with an extension
523
+ * to JPA's {@linkplain PessimisticLockScope}
524
+ */
525
+ @ Remove
526
+ public Set <Map .Entry <String ,LockMode >> getAliasSpecificLocks () {
527
+ return aliasSpecificLockModes == null ? emptySet () : unmodifiableSet ( aliasSpecificLockModes .entrySet () );
528
+ }
529
+
530
+ /**
531
+ * Specify the {@link LockMode} to be used for the given query alias.
532
+ *
533
+ * @param alias the query alias to which the lock mode applies
534
+ * @param lockMode the lock mode to apply to the given alias
535
+ * @return {@code this} for method chaining
536
+ *
537
+ * @see org.hibernate.query.Query#setLockMode(String, LockMode)
538
+ *
539
+ * @apiNote This will be removed in 7.1 and replaced with an extension
540
+ * to JPA's {@linkplain PessimisticLockScope}
541
+ */
542
+ @ Remove
543
+ public LockOptions setAliasSpecificLockMode (String alias , LockMode lockMode ) {
544
+ if ( immutable ) {
545
+ throw new UnsupportedOperationException ("immutable global instance of LockOptions" );
546
+ }
547
+ if ( aliasSpecificLockModes == null ) {
548
+ aliasSpecificLockModes = new LinkedHashMap <>();
549
+ }
550
+ if ( lockMode == null ) {
551
+ aliasSpecificLockModes .remove ( alias );
552
+ }
553
+ else {
554
+ aliasSpecificLockModes .put ( alias , lockMode );
555
+ }
556
+ return this ;
557
+ }
558
+
559
+ /**
560
+ * The number of aliases that have alias-specific lock modes specified.
561
+ *
562
+ * @return the number of explicitly defined alias lock modes.
563
+ *
564
+ * @apiNote This will be removed in 7.1 and replaced with an extension
565
+ * to JPA's {@linkplain PessimisticLockScope}
566
+ */
567
+ @ Remove
568
+ public int getAliasLockCount () {
569
+ return aliasSpecificLockModes == null ? 0 : aliasSpecificLockModes .size ();
570
+ }
571
+
572
+ /**
573
+ * Whether this {@code LockOptions} instance defines alias-specific lock-modes
574
+ *
575
+ * @return {@code true} if this object defines alias-specific lock modes;
576
+ * {@code false} otherwise.
577
+ *
578
+ * @apiNote This will be removed in 7.1 and replaced with an extension
579
+ * to JPA's {@linkplain PessimisticLockScope}
580
+ */
581
+ @ Remove
582
+ public boolean hasAliasSpecificLockModes () {
583
+ return aliasSpecificLockModes != null && !aliasSpecificLockModes .isEmpty ();
584
+ }
585
+
586
+ /**
587
+ * Get the {@link LockMode} explicitly specified for the given alias
588
+ * via {@link #setAliasSpecificLockMode(String, LockMode)}.
589
+ * <p>
590
+ * Differs from {@link #getEffectiveLockMode(String)} in that here we
591
+ * only return an explicitly specified alias-specific lock mode.
592
+ *
593
+ * @param alias The alias for which to locate the explicit lock mode.
594
+ * @return The explicit lock mode for that alias.
595
+ *
596
+ * @apiNote This will be removed in 7.1 and replaced with an extension
597
+ * to JPA's {@linkplain PessimisticLockScope}
598
+ */
599
+ @ Remove
600
+ public LockMode getAliasSpecificLockMode (String alias ) {
601
+ return aliasSpecificLockModes == null ? null : aliasSpecificLockModes .get ( alias );
602
+ }
603
+
604
+ /**
605
+ * Iterator over {@link Map.Entry}s, each containing an alias and its
606
+ * {@link LockMode}.
607
+ *
608
+ * @return an iterator over the {@link Map.Entry}s
609
+ * @deprecated use {@link #getAliasSpecificLocks()}
610
+ */
611
+ @ Deprecated
612
+ public Iterator <Map .Entry <String ,LockMode >> getAliasLockIterator () {
613
+ return getAliasSpecificLocks ().iterator ();
614
+ }
615
+
616
+ /**
617
+ * Determine the {@link LockMode} to apply to the given alias. If no
618
+ * mode was {@linkplain #setAliasSpecificLockMode(String, LockMode)
619
+ * explicitly set}, the {@linkplain #getLockMode() overall mode} is
620
+ * returned. If the overall lock mode is also {@code null},
621
+ * {@link LockMode#NONE} is returned.
622
+ * <p>
623
+ * Differs from {@link #getAliasSpecificLockMode(String)} in that here
624
+ * we fall back to only returning the overall lock mode.
625
+ *
626
+ * @param alias The alias for which to locate the effective lock mode.
627
+ * @return The effective lock mode.
628
+ *
629
+ * @apiNote This will be removed in 7.1 and replaced with an extension
630
+ * to JPA's {@linkplain PessimisticLockScope}
631
+ */
632
+ @ Remove
633
+ public LockMode getEffectiveLockMode (String alias ) {
634
+ LockMode lockMode = getAliasSpecificLockMode ( alias );
635
+ if ( lockMode == null ) {
636
+ lockMode = this .lockMode ;
637
+ }
638
+ return lockMode == null ? LockMode .NONE : lockMode ;
639
+ }
640
+
641
+ /**
642
+ * Currently needed for follow-on locking.
643
+ *
644
+ * @return The greatest of all requested lock modes.
645
+ *
646
+ * @apiNote This will be removed in 7.1 and replaced with an extension
647
+ * to JPA's {@linkplain PessimisticLockScope}. See {@linkplain #getLockMode()}
648
+ */
649
+ @ Remove
650
+ public LockMode findGreatestLockMode () {
651
+ LockMode lockModeToUse = getLockMode ();
652
+ if ( lockModeToUse == null ) {
653
+ lockModeToUse = LockMode .NONE ;
654
+ }
655
+
656
+ if ( aliasSpecificLockModes == null ) {
657
+ return lockModeToUse ;
658
+ }
659
+
660
+ for ( LockMode lockMode : aliasSpecificLockModes .values () ) {
661
+ if ( lockMode .greaterThan ( lockModeToUse ) ) {
662
+ lockModeToUse = lockMode ;
663
+ }
664
+ }
665
+
666
+ return lockModeToUse ;
667
+ }
636
668
}
0 commit comments