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.StringgetQuery()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 aList.<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 aMap.java.util.stream.Stream<T>toStream()Executes the query and returns the result as aStream.
-
Constructor Details
-
StoredProcedureQuery
public StoredProcedureQuery(java.lang.Class<T> underlyingClass, DBConnection connection, java.lang.String procedureName, java.lang.Object[] arguments)
-
-
Method Details
-
toList
Executes the query and returns the result as aList. -
toStream
Executes the query and returns the result as aStream. -
toArray
Executes a new query and returns the result as an array. -
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 aMap.- Specified by:
toMapin interfaceQueryable<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
Gets the first value from the database result. This method should be used when only one result is expected.- Specified by:
firstin interfaceSingleQueryable<T>- Returns:
- The first row as an entity wrapped in an
Optionalif there is at least one row. OtherwiseOptional.empty()is returned. If the value from the database isnull, an emptyOptionalis also returned.
-
getQuery
public java.lang.String getQuery()Responsible for building and returning the individual DQL statement.- Specified by:
getQueryin interfaceSingleQueryable<T>- Returns:
- The DQL statement which fetches data from the database.
-