Class SingleEntityProjectionQuery<E extends BaseEntity,​R>

java.lang.Object
com.github.collinalpert.java2db.queries.SingleEntityProjectionQuery<E,​R>
Type Parameters:
E - The entity which the query is supposed to be executed for.
R - The return type of the projection this query represents.
All Implemented Interfaces:
Queryable<R>
Direct Known Subclasses:
AsyncSingleEntityProjectionQuery

public class SingleEntityProjectionQuery<E extends BaseEntity,​R>
extends Object
implements Queryable<R>
A query which represents a projection from an SingleEntityQuery to a single column on the database.
Author:
Collin Alpert
  • Constructor Details

  • Method Details

    • first

      public Optional<R> first()
      Description copied from interface: Queryable
      Gets the first value from the database result. This method should be used when only one result is expected.
      Specified by:
      first in interface Queryable<E extends BaseEntity>
      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

      public List<R> toList()
      Executes the query and returns the result as a List.
      Specified by:
      toList in interface Queryable<E extends BaseEntity>
      Returns:
      A list of entities representing the result rows.
    • toStream

      public Stream<R> toStream()
      Executes the query and returns the result as a Stream.
      Specified by:
      toStream in interface Queryable<E extends BaseEntity>
      Returns:
      A list of entities representing the result rows.
    • toArray

      public R[] toArray()
      Executes a new query and returns the result as an array.
      Specified by:
      toArray in interface Queryable<E extends BaseEntity>
      Returns:
      An array of entities representing the result rows.
    • toMap

      public <K,​ V> Map<K,​V> toMap​(Function<R,​K> keyMapping, Function<R,​V> valueMapping)
      Executes a new query and returns the result as a Map.
      Specified by:
      toMap in interface Queryable<E extends BaseEntity>
      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

      public Set<R> toSet()
      Executes the query and returns the result as a Set.
      Specified by:
      toSet in interface Queryable<E extends BaseEntity>
      Returns:
      A set of entities representing the result rows.
    • getQuery

      public String getQuery()
      Responsible for building and returning the individual DQL statement.
      Specified by:
      getQuery in interface Queryable<E extends BaseEntity>
      Returns:
      The DQL statement which fetches data from the database.