|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2023 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -343,12 +343,26 @@ interface ResultQuerySpec {
|
343 | 343 |
|
344 | 344 | /**
|
345 | 345 | * Retrieve a single value result.
|
346 |
| - * @return the single row represented as its single column value |
| 346 | + * <p>Note: As of 6.2, this will enforce non-null result values |
| 347 | + * as originally designed (just accidentally not enforced before). |
| 348 | + * (never {@code null}) |
| 349 | + * @see #optionalValue() |
347 | 350 | * @see DataAccessUtils#requiredSingleResult(Collection)
|
348 | 351 | */
|
349 | 352 | default Object singleValue() {
|
350 | 353 | return DataAccessUtils.requiredSingleResult(singleColumn());
|
351 | 354 | }
|
| 355 | + |
| 356 | + /** |
| 357 | + * Retrieve a single value result, if available, as an {@link Optional} handle. |
| 358 | + * @return an Optional handle with the single column value from the single row |
| 359 | + * @since 6.2 |
| 360 | + * @see #singleValue() |
| 361 | + * @see DataAccessUtils#optionalResult(Collection) |
| 362 | + */ |
| 363 | + default Optional<Object> optionalValue() { |
| 364 | + return DataAccessUtils.optionalResult(singleColumn()); |
| 365 | + } |
352 | 366 | }
|
353 | 367 |
|
354 | 368 |
|
@@ -384,25 +398,27 @@ default Set<T> set() {
|
384 | 398 | return new LinkedHashSet<>(list());
|
385 | 399 | }
|
386 | 400 |
|
387 |
| - /** |
388 |
| - * Retrieve a single result, if available, as an {@link Optional} handle. |
389 |
| - * @return an Optional handle with a single result object or none |
390 |
| - * @see #list() |
391 |
| - * @see DataAccessUtils#optionalResult(Collection) |
392 |
| - */ |
393 |
| - default Optional<T> optional() { |
394 |
| - return DataAccessUtils.optionalResult(list()); |
395 |
| - } |
396 |
| - |
397 | 401 | /**
|
398 | 402 | * Retrieve a single result as a required object instance.
|
| 403 | + * <p>Note: As of 6.2, this will enforce non-null result values |
| 404 | + * as originally designed (just accidentally not enforced before). |
399 | 405 | * @return the single result object (never {@code null})
|
400 |
| - * @see #list() |
| 406 | + * @see #optional() |
401 | 407 | * @see DataAccessUtils#requiredSingleResult(Collection)
|
402 | 408 | */
|
403 | 409 | default T single() {
|
404 | 410 | return DataAccessUtils.requiredSingleResult(list());
|
405 | 411 | }
|
| 412 | + |
| 413 | + /** |
| 414 | + * Retrieve a single result, if available, as an {@link Optional} handle. |
| 415 | + * @return an Optional handle with a single result object or none |
| 416 | + * @see #single() |
| 417 | + * @see DataAccessUtils#optionalResult(Collection) |
| 418 | + */ |
| 419 | + default Optional<T> optional() { |
| 420 | + return DataAccessUtils.optionalResult(list()); |
| 421 | + } |
406 | 422 | }
|
407 | 423 |
|
408 | 424 | }
|
0 commit comments