- Type Parameters:
DTO- the type of the result object
- All Known Subinterfaces:
FromClauseTerminal<DTO,,JC, JCC, JCCT, WCC, WCCT, GBCT, HCC, HCCT, OBC, OBCC> GroupByClauseTerminal<DTO,,HCC, HCCT, OBC, OBCC> HavingClauseTerminal<DTO,,OBC, OBCC> HavingConditionClauseTerminal<DTO,,HCC, SELF, OBC, OBCC> JoinClauseTerminal<DTO,,JC, JCC, JCCT, WCC, WCCT, GBCT, HCC, HCCT, OBC, OBCC> LimitClauseTerminal<DTO>,OrderByClauseChain<DTO,,OBC, OBCC> OrderByClauseTerminal<DTO>,SqlJoinClauseTerminal,WhereClauseTerminal<DTO,,GBCT, HCC, HCCT, OBC, OBCC> WhereConditionClauseTerminal<DTO,WCC, SELF, GBCT, HCC, HCCT, OBC, OBCC>
- All Known Implementing Classes:
org.litebridgedb.orm.api.select.impl.AbstractFromClauseTerminal,org.litebridgedb.orm.api.select.impl.AbstractGroupByClauseTerminal,org.litebridgedb.orm.api.select.impl.AbstractHavingClauseTerminal,org.litebridgedb.orm.api.select.impl.AbstractJoinClauseTerminal,org.litebridgedb.orm.api.select.impl.AbstractJoinConditionClauseTerminal,org.litebridgedb.orm.api.select.impl.AbstractSelector,org.litebridgedb.orm.api.select.impl.AbstractWhereClauseTerminal,org.litebridgedb.orm.api.select.impl.DelegatingSelector,DtoFromClauseTerminal,DtoGroupByClauseTerminal,DtoHavingConditionClauseTerminal,DtoJoinConditionClauseTerminal,DtoOrderByClauseChain,DtoSelector,DtoWhereConditionClauseTerminal,org.litebridgedb.orm.api.select.impl.LimitClauseTerminalImpl,org.litebridgedb.orm.api.select.impl.OrderByClauseTerminalImpl,SqlFromClauseTerminal,SqlGroupByClauseTerminal,SqlHavingConditionClauseTerminal,SqlJoinConditionClauseTerminal,SqlOrderByClauseChain,SqlSelector,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.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 materializes all results into aList.one()Executes the query and expects exactly one result.@Nullable DTOExecutes the query and expects exactly one result.Executes the query and expects exactly one result.oneOrThrow(Supplier<? extends X> exceptionSupplier) Executes the query and expects exactly one result.stream()Executes the query and returns results as aStream.toSql()
-
Method Details
-
one
Executes the query and expects exactly one result.The returned
Optionalis empty when no row matches. If more than one row matches, the underlying implementation is expected to fail (typically by throwing an exception).- Returns:
- an
Optionalcontaining the single result, if present
-
oneOrNull
Executes the query and expects exactly one result.- Returns:
- the single result, or
nullwhen no row matches - Throws:
NonUniqueResultException- if more than one row matches
-
oneOrThrow
Executes the query and expects exactly one result.- Returns:
- the single result
- Throws:
NoSuchElementException- if no row matches or more than one row matches
-
oneOrThrow
Executes the query and expects exactly one result.When the result is not exactly one row, the supplied exception is 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 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.- Returns:
- the first result, or
nullwhen no row matches
-
firstOrThrow
Executes the query and returns the first row.- Returns:
- the first result
- Throws:
NoSuchElementException- if no row matches
-
firstOrThrow
Executes the query and returns the first row.When 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.Implementations may tie the stream to underlying resources (for example a JDBC
ResultSet). Prefer using try-with-resources (or otherwise ensuring the stream is closed) if the returned stream isAutoCloseableviaBaseStream.close().- Returns:
- a stream of results
-
list
Executes the query and materializes all results into aList.- Returns:
- list of all matching results (possibly empty)
-
toSql
String toSql()
-