Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JdbcClient ResultQuerySpec - Provide a optionalValue() method #33560

Closed
vcruzmj opened this issue Sep 18, 2024 · 1 comment
Closed

JdbcClient ResultQuerySpec - Provide a optionalValue() method #33560

vcruzmj opened this issue Sep 18, 2024 · 1 comment
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@vcruzmj
Copy link

vcruzmj commented Sep 18, 2024

The current singleValue() on the interface ResultQuerySpec expects 1 mandatory result, making confuse to get 0 or 1 results, wich is very common to have a query that returns 1 or 0 results, like this

SELECT somecolumn
FROM sometable
WHERE :somefilter
LIMIT 1

If that filter is not meet, the result is empty, and singleValue() is not usefull

Current implementation:

default Object singleValue() {
    return DataAccessUtils.requiredSingleResult(singleColumn());
}

The current implementation can be enhanced by just adding this extra method (using the existing DataAccessUtils method optionalResult.

default Object singleValue() {
    return DataAccessUtils.requiredSingleResult(singleColumn());
}

default Optional<Object> optionalValue() {
    return DataAccessUtils.optionalResult(singleColumn());
}

This will also help maintain coherence with the single() and optional() methods already provided on MappedQuerySpec.

@vcruzmj vcruzmj changed the title JdbcClient ResultQuerySpec - Provide a optionalValue method JdbcClient ResultQuerySpec - Provide a optionalValue() method Sep 18, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 18, 2024
@jhoeller jhoeller added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 18, 2024
@jhoeller jhoeller self-assigned this Sep 18, 2024
@jhoeller jhoeller added this to the 6.2.0-RC2 milestone Sep 18, 2024
@jhoeller
Copy link
Contributor

Good point, this goes together nicely with #33300 where we are enforcing non-null values contained in the result now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants