Class EntityProjectionQuery<E extends BaseEntity,​R>

    • Constructor Summary

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

      Modifier and Type Method Description
      java.util.Optional<R> first()
      Gets the first value from the database result.
      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.
      <K> java.util.Map<K,​R> toMap​(java.util.function.Function<R,​K> keyMapping)
      Executes a new query and returns the result as a Map.
      <K,​V>
      java.util.Map<K,​V>
      toMap​(java.util.function.Function<R,​K> keyMapping, java.util.function.Function<R,​V> valueMapping)
      Executes a new query and returns the result as a Map.
      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​(com.github.collinalpert.lambda2sql.functions.SqlFunction<E,​R> projection,
                                     EntityQuery<E> originalQuery)
    • Method Detail

      • first

        public java.util.Optional<R> first()
        Description copied from interface: SingleQueryable
        Gets the first value from the database result. This method should be used when only one result is expected.
        Specified by:
        first in interface SingleQueryable<E extends BaseEntity>
        Overrides:
        first in class SingleEntityProjectionQuery<E extends BaseEntity,​R>
        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.
      • toMap

        public <K> java.util.Map<K,​R> toMap​(java.util.function.Function<R,​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).
        Specified by:
        toMap in interface Queryable<E extends BaseEntity>
        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

        public <K,​V> java.util.Map<K,​V> toMap​(java.util.function.Function<R,​K> keyMapping,
                                                          java.util.function.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.