Class StoredProcedureQuery<T>

java.lang.Object
com.github.collinalpert.java2db.queries.StoredProcedureQuery<T>
All Implemented Interfaces:
Queryable<T>
Direct Known Subclasses:
AsyncStoredProcedureQuery

public class StoredProcedureQuery<T>
extends Object
implements Queryable<T>
Author:
Collin Alpert
  • Constructor Details

  • Method Details

    • first

      public Optional<T> first()
      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<T>
      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<T> toList()
      Executes the query and returns the result as a List.
      Specified by:
      toList in interface Queryable<T>
      Returns:
      A list of entities representing the result rows.
    • toStream

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

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

      public <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.
      Specified by:
      toMap in interface Queryable<T>
      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<T> toSet()
      Executes the query and returns the result as a Set.
      Specified by:
      toSet in interface Queryable<T>
      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<T>
      Returns:
      The DQL statement which fetches data from the database.