Class EntityProjectionQuery<E extends BaseEntity,R>
- java.lang.Object
-
- com.github.collinalpert.java2db.queries.EntityProjectionQuery<E,R>
-
- All Implemented Interfaces:
Queryable<R>
public class EntityProjectionQuery<E extends BaseEntity,R> extends java.lang.Object implements Queryable<R>
A query which represents a projection from anEntityQueryto a single column on the database.- Author:
- Collin Alpert
-
-
Constructor Summary
Constructors Constructor Description EntityProjectionQuery(java.lang.Class<R> returnType, com.github.collinalpert.lambda2sql.functions.SqlFunction<E,R> projection, EntityQuery<E> originalQuery)
-
Method Summary
Modifier and Type Method Description java.util.Optional<R>getFirst()Gets the first value from the database result.java.lang.StringgetQuery()Responsible for building and returning the individual DQL statement.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 aListjava.util.stream.Stream<R>toStream()Executes the query and returns the result as aStream-
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
getFirstAsync, getFirstAsync, toArrayAsync, toArrayAsync, toListAsync, toListAsync, toStreamAsync, toStreamAsync
-
-
-
-
Constructor Detail
-
EntityProjectionQuery
public EntityProjectionQuery(java.lang.Class<R> returnType, com.github.collinalpert.lambda2sql.functions.SqlFunction<E,R> projection, EntityQuery<E> originalQuery)
-
-
Method Detail
-
getFirst
public java.util.Optional<R> getFirst()
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:
getFirstin 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
public java.util.List<R> 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
public java.util.stream.Stream<R> 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
public R[] 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.
-
getQuery
public java.lang.String 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.
-
-