Class EntityProjectionQuery<E extends BaseEntity,R>
java.lang.Object
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>
- Direct Known Subclasses:
AsyncEntityProjectionQuery
public class EntityProjectionQuery<E extends BaseEntity,R> extends Object implements Queryable<R>
A query which represents a projection from an
EntityQuery to a single column on the database.- Author:
- Collin Alpert
-
Constructor Summary
Constructors Constructor Description EntityProjectionQuery(Class<R> returnType, IQueryBuilder<E> queryBuilder, QueryParameters<E> queryParameters, ConnectionConfiguration connectionConfiguration) -
Method Summary
Modifier and Type Method Description Optional<R>first()Gets the first value from the database result.StringgetQuery()Responsible for building and returning the individual DQL statement.R[]toArray()Executes a new query and returns the result as an array.List<R>toList()Executes the query and returns the result as aList.<K, V> Map<K,V>toMap(Function<R,K> keyMapping, Function<R,V> valueMapping)Executes a new query and returns the result as aMap.Set<R>toSet()Executes the query and returns the result as aSet.Stream<R>toStream()Executes the query and returns the result as aStream.
-
Constructor Details
-
EntityProjectionQuery
public EntityProjectionQuery(Class<R> returnType, IQueryBuilder<E> queryBuilder, QueryParameters<E> queryParameters, ConnectionConfiguration connectionConfiguration)
-
-
Method Details
-
first
Description copied from interface:QueryableGets the first value from the database result. This method should be used when only one result is expected.- Specified by:
firstin interfaceQueryable<E extends BaseEntity>- 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.- 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.
-
toSet
Executes the query and returns the result as aSet.- Specified by:
toSetin interfaceQueryable<E extends BaseEntity>- Returns:
- A set of entities representing the result rows.
-
getQuery
Description copied from interface:QueryableResponsible for building and returning the individual DQL statement.- Specified by:
getQueryin interfaceQueryable<E extends BaseEntity>- Returns:
- The DQL statement which fetches data from the database.
-