org.dellroad.querystream.jpa.ExprStream Maven / Gradle / Ivy
/*
* Copyright (C) 2018 Archie L. Cobbs. All rights reserved.
*/
package org.dellroad.querystream.jpa;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.SingularAttribute;
/**
* {@link SearchStream} containing items representable as {@link Expression}s.
*/
public interface ExprStream> extends SearchStream {
// Subqueries
/**
* Convert this instance into a subquery that can be used within an intermediate step of an outer query.
*
* @return criteria subquery object corresponding to this stream
* @throws IllegalStateException if not invoked during a terminal operation on an outer query
*/
Subquery asSubquery();
/**
* Convert this instance into an "exists" subquery that can be used within an intermediate step of an outer query.
*
*
* Note: to perform the equivalent of an "exists" operation on the outermost query, use {@link #isEmpty}.
*
* @return boolean single-valued stream determining the existence of any items in this stream
* @throws IllegalStateException if invoked on a stream which is not being used as a subquery
* @see #isEmpty
*/
Predicate exists();
// Aggregation
/**
* Create value returning the number of instances in this stream.
*
* Warning: don't use in combination with {@code groupBy()}, because SQL's {@code COUNT()} returns a non-unique
* result in grouped queries, or else a {@link javax.persistence.NonUniqueResultException} can result.
*
* @return single-valued stream counting instances in this stream
*/
LongValue count();
/**
* Create value returning the number of distinct instances in this stream.
*
* Warning: don't use in combination with {@code groupBy()}, because SQL's {@code COUNT()} returns a non-unique
* result in grouped queries, or else a {@link javax.persistence.NonUniqueResultException} can result.
*
* @return single-valued stream counting distinct instances in this stream
*/
LongValue countDistinct();
// Narrowing overrides (SearchStream)
@Override
ExprStream distinct();
@Override
ExprStream orderBy(Ref, ? extends Expression>> ref, boolean asc);
@Override
ExprStream orderBy(SingularAttribute super X, ?> attribute, boolean asc);
@Override
ExprStream orderBy(SingularAttribute super X, ?> attribute1, boolean asc1,
SingularAttribute super X, ?> attribute2, boolean asc2);
@Override
ExprStream orderBy(SingularAttribute super X, ?> attribute1, boolean asc1,
SingularAttribute super X, ?> attribute2, boolean asc2, SingularAttribute super X, ?> attribute3, boolean asc3);
@Override
ExprStream orderBy(Function super S, ? extends Expression>> orderExprFunction, boolean asc);
@Override
ExprStream orderBy(Order... orders);
@Override
ExprStream orderByMulti(Function super S, ? extends List extends Order>> orderListFunction);
@Override
ExprStream thenOrderBy(SingularAttribute super X, ?> attribute, boolean asc);
@Override
ExprStream thenOrderBy(Ref, ? extends Expression>> ref, boolean asc);
@Override
ExprStream thenOrderBy(Order... orders);
@Override
ExprStream thenOrderBy(Function super S, ? extends Expression>> orderExprFunction, boolean asc);
@Override
ExprStream groupBy(Ref, ? extends Expression>> ref);
@Override
ExprStream groupBy(SingularAttribute super X, ?> attribute);
@Override
ExprStream groupBy(Function super S, ? extends Expression>> groupFunction);
@Override
ExprStream groupByMulti(Function super S, ? extends List>> groupFunction);
@Override
ExprStream having(Function super S, ? extends Expression> havingFunction);
@Override
ExprValue findAny();
@Override
ExprValue findFirst();
// Narrowing overrides (QueryStream)
@Override
ExprStream bind(Ref ref);
@Override
ExprStream peek(Consumer super S> peeker);
@Override
> ExprStream bind(Ref ref, Function super S, ? extends S2> refFunction);
@Override
ExprStream addRoot(Ref> ref, Class type);
@Override
ExprStream filter(SingularAttribute super X, Boolean> attribute);
@Override
ExprStream filter(Function super S, ? extends Expression> predicateBuilder);
@Override
ExprStream limit(int maxSize);
@Override
ExprStream skip(int num);
@Override
ExprStream withFlushMode(FlushModeType flushMode);
@Override
ExprStream withLockMode(LockModeType lockMode);
@Override
ExprStream withHint(String name, Object value);
@Override
ExprStream withHints(Map hints);
@Override
ExprStream withLoadGraph(String name);
@Override
ExprStream withFetchGraph(String name);
}