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,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

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.
    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 materializes all results into a List.
    one()
    Executes the query and expects exactly one result.
    @Nullable DTO
    Executes the query and expects exactly one result.
    Executes the query and expects exactly one result.
    <X extends Throwable>
    DTO
    oneOrThrow(Supplier<? extends X> exceptionSupplier)
    Executes the query and expects exactly one result.
    Executes the query and returns results as a Stream.
     
  • Method Details

    • one

      Optional<DTO> one()
      Executes the query and expects exactly one result.

      The returned Optional is 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 Optional containing the single result, if present
    • oneOrNull

      @Nullable DTO oneOrNull() throws NonUniqueResultException
      Executes the query and expects exactly one result.
      Returns:
      the single result, or null when no row matches
      Throws:
      NonUniqueResultException - if more than one row matches
    • oneOrThrow

      DTO oneOrThrow() throws NoSuchElementException
      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

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

      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.
      Returns:
      the first result, or null when no row matches
    • firstOrThrow

      DTO firstOrThrow() throws NoSuchElementException
      Executes the query and returns the first row.
      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.

      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

      Stream<DTO> stream()
      Executes the query and returns results as a Stream.

      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 is AutoCloseable via BaseStream.close().

      Returns:
      a stream of results
    • list

      List<DTO> list()
      Executes the query and materializes all results into a List.
      Returns:
      list of all matching results (possibly empty)
    • toSql

      String toSql()