Class EntityProjectionQuery<E extends BaseEntity,R>
java.lang.Object
com.github.collinalpert.java2db.queries.SingleEntityProjectionQuery<E,R>
com.github.collinalpert.java2db.queries.EntityProjectionQuery<E,R>
- Type Parameters:
E- The entity which the query is supposed to be executed for.R- The return type of the projection this query represents.
- All Implemented Interfaces:
Queryable<R>,SingleQueryable<R>
- Direct Known Subclasses:
AsyncEntityProjectionQuery
public class EntityProjectionQuery<E extends BaseEntity,R> extends SingleEntityProjectionQuery<E,R> implements Queryable<R>
A query which represents a projection from an
EntityQuery to a single column on the database.- Author:
- Collin Alpert
-
Field Summary
Fields inherited from class com.github.collinalpert.java2db.queries.SingleEntityProjectionQuery
originalQuery, returnType -
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 aList.<K> java.util.Map<K,R>toMap(java.util.function.Function<R,K> keyMapping)Executes a new query and returns the result as aMap.<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 aMap.java.util.stream.Stream<R>toStream()Executes the query and returns the result as aStream.Methods inherited from class com.github.collinalpert.java2db.queries.SingleEntityProjectionQuery
getQuery
-
Constructor Details
-
EntityProjectionQuery
public EntityProjectionQuery(com.github.collinalpert.lambda2sql.functions.SqlFunction<E,R> projection, EntityQuery<E> originalQuery)
-
-
Method Details
-
first
Description copied from interface:SingleQueryableGets the first value from the database result. This method should be used when only one result is expected.- Specified by:
firstin interfaceSingleQueryable<E extends BaseEntity>- Overrides:
firstin classSingleEntityProjectionQuery<E extends BaseEntity,R>- 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.
-
toList
Description copied from interface:QueryableExecutes the query and returns the result as aList.- Specified by:
toListin interfaceQueryable<E extends BaseEntity>- Returns:
- A list of entities representing the result rows.
-
toStream
Description copied from interface:QueryableExecutes the query and returns the result as aStream.- Specified by:
toStreamin interfaceQueryable<E extends BaseEntity>- Returns:
- A list of entities representing the result rows.
-
toArray
Description copied from interface:QueryableExecutes a new query and returns the result as an array.- Specified by:
toArrayin interfaceQueryable<E extends BaseEntity>- Returns:
- An array of entities representing the result rows.
-
toMap
Executes a new query and returns the result as aMap. This method is equivalent to the callQueryable#toMap(keyMapping, x -> x).- Specified by:
toMapin interfaceQueryable<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 aMap.- Specified by:
toMapin interfaceQueryable<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.
-