Class SelectEngineTerminal

java.lang.Object
org.litebridge.orm.engine.SelectEngineTerminal

public class SelectEngineTerminal extends Object
Executes SQL SELECT statements.
  • Constructor Details

  • Method Details

    • fetchOne

      public <DTO> Optional<DTO> fetchOne(QueryNode node, LitebridgeContext litebridgeContext) throws NonUniqueResultException
      Executes the query and returns exactly one result.

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

      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      an Optional containing the single result, if present
      Throws:
      NonUniqueResultException - if the query returns more than one result
    • fetchOneOrNull

      public <DTO> @Nullable DTO fetchOneOrNull(QueryNode node, LitebridgeContext litebridgeContext) 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.

      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      the single result, or null when no row matches
      Throws:
      NonUniqueResultException - if more than one row matches
    • fetchOneOrThrow

      public <DTO> DTO fetchOneOrThrow(QueryNode node, LitebridgeContext litebridgeContext)
      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.

      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      the single result
      Throws:
      NoSuchElementException - if no row matches
      NonUniqueResultException - if more than one row matches
    • fetchOneOrThrow

      public <DTO, X extends Throwable> DTO fetchOneOrThrow(QueryNode node, LitebridgeContext litebridgeContext, Supplier<? extends X> exceptionSupplier) throws X
      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:
      DTO - the result type
      X - exception type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      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
    • fetchFirst

      public <DTO> Optional<DTO> fetchFirst(QueryNode node, LitebridgeContext litebridgeContext)
      Executes the query and returns the first row if present.

      Unlike fetchOne(QueryNode, LitebridgeContext), this method does not require uniqueness; if multiple rows match, only the first is returned (according to the effective ordering, if any).

      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      an Optional with the first result, if present
    • fetchFirstOrNull

      public <DTO> @Nullable DTO fetchFirstOrNull(QueryNode node, LitebridgeContext litebridgeContext)
      Executes the query and returns the first row if present, or null if no row matches.
      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      the first result, or null if no row matches
    • fetchFirstOrThrow

      public <DTO> DTO fetchFirstOrThrow(QueryNode node, LitebridgeContext litebridgeContext)
      Executes the query and returns the first row.

      If no row matches, an NoSuchElementException is thrown.

      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      the first result
      Throws:
      NoSuchElementException - if no row matches
    • fetchFirstOrThrow

      public <DTO, X extends Throwable> DTO fetchFirstOrThrow(QueryNode node, LitebridgeContext litebridgeContext, 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:
      DTO - the result type
      X - exception type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      exceptionSupplier - supplier used to create the exception to throw when no row matches
      Returns:
      the first result
      Throws:
      X - if no row matches
    • fetchStream

      public <DTO> Stream<DTO> fetchStream(QueryNode node, LitebridgeContext litebridgeContext)
      Executes the query and returns results as a Stream.
      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      a stream of results
    • fetchList

      public <DTO> List<DTO> fetchList(QueryNode node, LitebridgeContext litebridgeContext)
      Executes the query and returns a list of results.
      Type Parameters:
      DTO - the result type
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      list of all matching results (possibly empty)
    • generateSql

      public PreparedSql generateSql(QueryNode node, LitebridgeContext litebridgeContext)
      Generates SQL for the query without executing it.
      Parameters:
      node - the AST query node representing the query
      litebridgeContext - the Litebridge context
      Returns:
      The generated SQL, bind values and query metadata.