Interface Queryable<T>

All Known Subinterfaces:
AsyncQueryable<T>
All Known Implementing Classes:
AsyncEntityProjectionQuery, AsyncEntityQuery, AsyncSingleEntityProjectionQuery, AsyncSingleEntityQuery, AsyncStoredProcedureQuery, EntityProjectionQuery, EntityQuery, SingleEntityProjectionQuery, SingleEntityQuery, StoredProcedureQuery

public interface Queryable<T>
Author:
Collin Alpert
  • Method Summary

    Modifier and Type Method Description
    Optional<T> first()
    Gets the first value from the database result.
    String getQuery()
    Responsible for building and returning the individual DQL statement.
    T[] toArray()
    Executes a new query and returns the result as an array.
    List<T> toList()
    Executes the query and returns the result as a List.
    default <K> Map<K,​T> toMap​(Function<T,​K> keyMapping)
    Executes a new query and returns the result as a Map.
    <K,​ V> Map<K,​V> toMap​(Function<T,​K> keyMapping, Function<T,​V> valueMapping)
    Executes a new query and returns the result as a Map.
    Set<T> toSet()
    Executes the query and returns the result as a Set.
    Stream<T> toStream()
    Executes the query and returns the result as a Stream.
  • Method Details

    • first

      Optional<T> first()
      Gets the first value from the database result. This method should be used when only one result is expected.
      Returns:
      The first row as an entity wrapped in an Optional if there is at least one row. Otherwise Optional.empty() is returned. If the value from the database is null, an empty Optional is also returned.
    • toList

      List<T> toList()
      Executes the query and returns the result as a List.
      Returns:
      A list of entities representing the result rows.
    • toStream

      Stream<T> toStream()
      Executes the query and returns the result as a Stream.
      Returns:
      A list of entities representing the result rows.
    • toArray

      T[] toArray()
      Executes a new query and returns the result as an array.
      Returns:
      An array of entities representing the result rows.
    • toMap

      default <K> Map<K,​T> toMap​(Function<T,​K> keyMapping)
      Executes a new query and returns the result as a Map. This method is equivalent to the call Queryable#toMap(keyMapping, x -> x).
      Type Parameters:
      K - The type of the field representing the keys.
      Parameters:
      keyMapping - The field representing the keys of the map.
      Returns:
      A map containing the result of the query.
    • toMap

      <K,​ V> Map<K,​V> toMap​(Function<T,​K> keyMapping, Function<T,​V> valueMapping)
      Executes a new query and returns the result as a Map.
      Type Parameters:
      K - The type of the field representing the keys.
      V - The type of the field representing the values.
      Parameters:
      keyMapping - The field representing the keys of the map.
      valueMapping - The field representing the values of the map.
      Returns:
      A map containing the result of the query.
    • toSet

      Set<T> toSet()
      Executes the query and returns the result as a Set.
      Returns:
      A set of entities representing the result rows.
    • getQuery

      String getQuery()
      Responsible for building and returning the individual DQL statement.
      Returns:
      The DQL statement which fetches data from the database.