Class StoredProcedureQuery<T>

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

public class StoredProcedureQuery<T>
extends java.lang.Object
implements Queryable<T>
Author:
Collin Alpert
  • Constructor Summary

    Constructors 
    Constructor Description
    StoredProcedureQuery​(java.lang.Class<T> underlyingClass, DBConnection connection, java.lang.String procedureName, java.lang.Object[] arguments)  
  • Method Summary

    Modifier and Type Method Description
    java.util.Optional<T> first()
    Gets the first value from the database result.
    java.lang.String getQuery()
    Responsible for building and returning the individual DQL statement.
    T[] toArray()
    Executes a new query and returns the result as an array.
    java.util.List<T> toList()
    Executes the query and returns the result as a List.
    <K,​ V> java.util.Map<K,​V> toMap​(java.util.function.Function<T,​K> keyMapping, java.util.function.Function<T,​V> valueMapping)
    Executes a new query and returns the result as a Map.
    java.util.stream.Stream<T> 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

    Methods inherited from interface com.github.collinalpert.java2db.queries.Queryable

    toMap
  • Constructor Details

    • StoredProcedureQuery

      public StoredProcedureQuery​(java.lang.Class<T> underlyingClass, DBConnection connection, java.lang.String procedureName, java.lang.Object[] arguments)
  • Method Details

    • toList

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

      public java.util.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 SingleQueryable<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.
    • getQuery

      public java.lang.String getQuery()
      Responsible for building and returning the individual DQL statement.
      Specified by:
      getQuery in interface SingleQueryable<T>
      Returns:
      The DQL statement which fetches data from the database.