- Type Parameters:
DTO- the type of the result object
- All Known Subinterfaces:
FromClauseTerminal<DTO,,JC, JCC, JCCT, WCC, WCCT, GBCT, HCC, HCCT, QCB, OBC, OBCC> GroupByClauseTerminal<DTO,,HCC, HCCT, QCB, OBC, OBCC> HavingClauseTerminal<DTO,,OBC, OBCC> HavingConditionClauseTerminal<DTO,,HCC, SELF, QCB, OBC, OBCC> JoinClauseTerminal<DTO,,JC, JCC, JCCT, WCC, WCCT, GBCT, HCC, HCCT, QCB, OBC, OBCC> LimitClauseTerminal<DTO>,OrderByClauseChain<DTO,,OBC, OBCC> OrderByClauseTerminal<DTO>,SqlJoinClauseTerminal<ReturnType>,WhereClauseTerminal<DTO,,GBCT, HCC, HCCT, QCB, OBC, OBCC> WhereConditionClauseTerminal<DTO,WCC, SELF, GBCT, HCC, HCCT, QCB, OBC, OBCC>
- All Known Implementing Classes:
AbstractFromClauseTerminal,AbstractGroupByClauseTerminal,AbstractHavingClauseTerminal,AbstractJoinClauseTerminal,AbstractJoinConditionClauseTerminal,AbstractWhereClauseTerminal,DelegatingSelectTerminal,DtoFromClauseTerminal,DtoGroupByClauseTerminal,DtoHavingConditionClauseTerminal,DtoJoinConditionClauseTerminal,DtoOrderByClauseChain,DtoWhereConditionClauseTerminal,FromClauseStart,FromClauseStartTypeOverride,LimitClauseTerminalImpl,OrderByClauseTerminalImpl,SqlFromClauseTerminal,SqlGroupByClauseTerminal,SqlHavingConditionClauseTerminal,SqlJoinConditionClauseTerminal,SqlOrderByClauseChain,SqlWhereConditionClauseTerminal
This interface provides methods for retrieving results such as a single row, the first row, all rows, or as a stream of data. It supports various handling mechanisms for situations like no result, multiple results, or custom exception throwing.
-
Method Summary
Modifier and TypeMethodDescriptionfirst()Executes the query and returns the first row if present.@Nullable DTOExecutes the query and returns the first row if present, ornullif no row matches.Executes the query and returns the first row.firstOrThrow(Supplier<? extends X> exceptionSupplier) Executes the query and returns the first row.list()Executes the query and returns a list of results.one()Executes the query and returns exactly one result.@Nullable DTOExecutes the query and returns exactly one result, ornullif no row matches.Executes the query and returns exactly one result.oneOrThrow(Supplier<? extends X> exceptionSupplier) Executes the query and returns exactly one result.stream()Executes the query and returns results as aStream.toSql()Generates SQL for the query without executing it.
-
Method Details
-
one
Executes the query and returns exactly one result.The returned
Optionalis empty when no row matches. If more than one row matches, anNonUniqueResultExceptionis thrown.- Returns:
- an
Optionalcontaining the single result, if present - Throws:
NonUniqueResultException- if the query returns more than one result
-
oneOrNull
Executes the query and returns exactly one result, ornullif no row matches.If more than one row matches, an
NonUniqueResultExceptionis thrown.- Returns:
- the single result, or
nullwhen no row matches - Throws:
NonUniqueResultException- if more than one row matches
-
oneOrThrow
Executes the query and returns exactly one result.If no row matches, an
NoSuchElementExceptionis thrown. If more than one row matches, anNonUniqueResultExceptionis thrown.- Returns:
- the single result
- Throws:
NoSuchElementException- if no row matchesNonUniqueResultException- if more than one row matches
-
oneOrThrow
<X extends Throwable> DTO oneOrThrow(Supplier<? extends X> exceptionSupplier) throws X, NonUniqueResultException Executes the query and returns exactly one result.If no row matches, the supplied exception is thrown. If more than one row matches, an
NonUniqueResultExceptionis thrown.- Type Parameters:
X- exception type- Parameters:
exceptionSupplier- supplier used to create the exception to throw when the result is not exactly one row- Returns:
- the single result
- Throws:
X- if no row matches or more than one row matchesNonUniqueResultException- if more than one row matches
-
first
Executes the query and returns the first row if present.Unlike
one(), this method does not require uniqueness; if multiple rows match, only the first is returned (according to the effective ordering, if any).- Returns:
- an
Optionalwith the first result, if present
-
firstOrNull
@Nullable DTO firstOrNull()Executes the query and returns the first row if present, ornullif no row matches.- Returns:
- the first result, or
nullif no row matches
-
firstOrThrow
Executes the query and returns the first row.If no row matches, an
NoSuchElementExceptionis thrown.- Returns:
- the first result
- Throws:
NoSuchElementException- if no row matches
-
firstOrThrow
Executes the query and returns the first row.If no row matches, the supplied exception is thrown.
- Type Parameters:
X- exception type- Parameters:
exceptionSupplier- supplier used to create the exception to throw when no row matches- Returns:
- the first result
- Throws:
X- if no row matches
-
stream
Executes the query and returns results as aStream.- Returns:
- a stream of results
-
list
Executes the query and returns a list of results.- Returns:
- list of all matching results (possibly empty)
-
toSql
PreparedSql toSql()Generates SQL for the query without executing it.- Returns:
- The generated SQL, bind values and query metadata.
-