Interface SelectTerminal<DTO>

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

public interface SelectTerminal<DTO>
Interface for executing and retrieving results from a select query.

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 Type
    Method
    Description
    Executes the query and returns the first row if present.
    @Nullable DTO
    Executes the query and returns the first row if present, or null if no row matches.
    Executes the query and returns the first row.
    <X extends Throwable>
    DTO
    firstOrThrow(Supplier<? extends X> exceptionSupplier)
    Executes the query and returns the first row.
    Executes the query and returns a list of results.
    one()
    Executes the query and returns exactly one result.
    @Nullable DTO
    Executes the query and returns exactly one result, or null if no row matches.
    Executes the query and returns exactly one result.
    <X extends Throwable>
    DTO
    oneOrThrow(Supplier<? extends X> exceptionSupplier)
    Executes the query and returns exactly one result.
    Executes the query and returns results as a Stream.
    Generates SQL for the query without executing it.
  • Method Details

    • one

      Executes the query and returns exactly one result.

      The returned Optional is empty when no row matches. If more than one row matches, an NonUniqueResultException is thrown.

      Returns:
      an Optional containing the single result, if present
      Throws:
      NonUniqueResultException - if the query returns more than one result
    • oneOrNull

      @Nullable DTO oneOrNull() throws NonUniqueResultException
      Executes the query and returns exactly one result, or null if no row matches.

      If more than one row matches, an NonUniqueResultException is thrown.

      Returns:
      the single result, or null when 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 NoSuchElementException is thrown. If more than one row matches, an NonUniqueResultException is thrown.

      Returns:
      the single result
      Throws:
      NoSuchElementException - if no row matches
      NonUniqueResultException - 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 NonUniqueResultException 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
      NonUniqueResultException - if more than one row matches
    • first

      Optional<DTO> 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 Optional with the first result, if present
    • firstOrNull

      @Nullable DTO firstOrNull()
      Executes the query and returns the first row if present, or null if no row matches.
      Returns:
      the first result, or null if no row matches
    • firstOrThrow

      DTO firstOrThrow() throws NoSuchElementException
      Executes the query and returns the first row.

      If no row matches, an NoSuchElementException is thrown.

      Returns:
      the first result
      Throws:
      NoSuchElementException - if no row matches
    • firstOrThrow

      <X extends Throwable> DTO firstOrThrow(Supplier<? extends X> exceptionSupplier) throws X
      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

      Stream<DTO> stream()
      Executes the query and returns results as a Stream.
      Returns:
      a stream of results
    • list

      List<DTO> 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.