Class EntityProjectionQuery<E extends BaseEntity,​R>

  • All Implemented Interfaces:
    Queryable<R>

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

      Constructors 
      Constructor Description
      EntityProjectionQuery​(java.lang.Class<R> returnType, com.github.collinalpert.lambda2sql.functions.SqlFunction<E,​R> projection, EntityQuery<E> originalQuery)  
    • Method Summary

      Modifier and Type Method Description
      java.util.Optional<R> getFirst()
      Gets the first value from the database result.
      java.lang.String getQuery()
      Responsible for building and returning the individual DQL statement.
      R[] toArray()
      Executes a new query and returns the result as an array.
      java.util.List<R> toList()
      Executes the query and returns the result as a List
      java.util.stream.Stream<R> toStream()
      Executes the query and returns the result as a Stream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EntityProjectionQuery

        public EntityProjectionQuery​(java.lang.Class<R> returnType,
                                     com.github.collinalpert.lambda2sql.functions.SqlFunction<E,​R> projection,
                                     EntityQuery<E> originalQuery)
    • Method Detail

      • getFirst

        public java.util.Optional<R> getFirst()
        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:
        getFirst 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 java.util.List<R> toList()
        Description copied from interface: Queryable
        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 java.util.stream.Stream<R> toStream()
        Description copied from interface: Queryable
        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()
        Description copied from interface: Queryable
        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.
      • getQuery

        public java.lang.String getQuery()
        Description copied from interface: Queryable
        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.