org.dellroad.querystream.jpa.RootStreamImpl 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.EntityManager;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.SingularAttribute;
import org.dellroad.querystream.jpa.querytype.SearchType;
class RootStreamImpl extends FromStreamImpl> implements RootStream {
// Constructors
RootStreamImpl(EntityManager entityManager, Class type) {
this(entityManager, new SearchType(type));
}
// Separate constructor to avoid bogus error ("cannot reference queryType before supertype constructor has been called")
private RootStreamImpl(EntityManager entityManager, SearchType queryType) {
this(entityManager, queryType, (builder, query) -> query.from(queryType.getType()), new QueryInfo());
}
RootStreamImpl(EntityManager entityManager, SearchType queryType,
QueryConfigurer, X, ? extends Root> configurer, QueryInfo queryInfo) {
super(entityManager, queryType, configurer, queryInfo);
}
// Narrowing overrides (PathStreamImpl)
@Override
public RootStream cast(Class type) {
return new RootStreamImpl(this.getEntityManager(), new SearchType<>(type),
(builder, query) -> builder.treat(this.configure(builder, query), type), this.queryInfo);
}
// Narrowing overrides (SearchStreamImpl)
@Override
RootStream create(EntityManager entityManager, SearchType queryType,
QueryConfigurer, X, ? extends Root> configurer, QueryInfo queryInfo) {
return new RootStreamImpl<>(entityManager, queryType, configurer, queryInfo);
}
@Override
RootValue toValue() {
return this.toValue(false);
}
@Override
RootValue toValue(boolean forceLimit) {
return new RootValueImpl<>(this.entityManager, this.queryType,
this.configurer, forceLimit ? this.queryInfo.withMaxResults(1) : this.queryInfo);
}
@Override
public RootStream distinct() {
return (RootStream)super.distinct();
}
@Override
public RootStream orderBy(Ref, ? extends Expression>> ref, boolean asc) {
return (RootStream)super.orderBy(ref, asc);
}
@Override
public RootStream orderBy(SingularAttribute super X, ?> attribute, boolean asc) {
return (RootStream)super.orderBy(attribute, asc);
}
@Override
public RootStream orderBy(SingularAttribute super X, ?> attribute1, boolean asc1,
SingularAttribute super X, ?> attribute2, boolean asc2) {
return (RootStream)super.orderBy(attribute1, asc1, attribute2, asc2);
}
@Override
public RootStream orderBy(SingularAttribute super X, ?> attribute1, boolean asc1,
SingularAttribute super X, ?> attribute2, boolean asc2, SingularAttribute super X, ?> attribute3, boolean asc3) {
return (RootStream)super.orderBy(attribute1, asc1, attribute2, asc2, attribute3, asc3);
}
@Override
public RootStream orderBy(Function super Root, ? extends Expression>> orderExprFunction, boolean asc) {
return (RootStream)super.orderBy(orderExprFunction, asc);
}
@Override
public RootStream orderBy(Order... orders) {
return (RootStream)super.orderBy(orders);
}
@Override
public RootStream orderByMulti(Function super Root, ? extends List extends Order>> orderListFunction) {
return (RootStream)super.orderByMulti(orderListFunction);
}
@Override
public RootStream thenOrderBy(Ref, ? extends Expression>> ref, boolean asc) {
return (RootStream)super.thenOrderBy(ref, asc);
}
@Override
public RootStream thenOrderBy(Order... orders) {
return (RootStream)super.thenOrderBy(orders);
}
@Override
public RootStream thenOrderBy(SingularAttribute super X, ?> attribute, boolean asc) {
return (RootStream)super.thenOrderBy(attribute, asc);
}
@Override
public RootStream thenOrderBy(Function super Root, ? extends Expression>> orderExprFunction, boolean asc) {
return (RootStream)super.thenOrderBy(orderExprFunction, asc);
}
@Override
public RootStream groupBy(Ref, ? extends Expression>> ref) {
return (RootStream)super.groupBy(ref);
}
@Override
public RootStream groupBy(SingularAttribute super X, ?> attribute) {
return (RootStream)super.groupBy(attribute);
}
@Override
public RootStream groupBy(Function super Root, ? extends Expression>> groupFunction) {
return (RootStream)super.groupBy(groupFunction);
}
@Override
public RootStream groupByMulti(Function super Root, ? extends List>> groupFunction) {
return (RootStream)super.groupByMulti(groupFunction);
}
@Override
public RootStream having(Function super Root, ? extends Expression> havingFunction) {
return (RootStream)super.having(havingFunction);
}
@Override
public RootValue findAny() {
return (RootValue)super.findAny();
}
@Override
public RootValue findFirst() {
return (RootValue)super.findFirst();
}
@Override
public RootStream addRoot(Ref> ref, Class type) {
return (RootStream)super.addRoot(ref, type);
}
// Narrowing overrides (QueryStreamImpl)
@Override
public RootStream bind(Ref> ref) {
return (RootStream)super.bind(ref);
}
@Override
public RootStream peek(Consumer super Root> peeker) {
return (RootStream)super.peek(peeker);
}
@Override
public > RootStream bind(
Ref ref, Function super Root, ? extends S2> refFunction) {
return (RootStream)super.bind(ref, refFunction);
}
@Override
public RootStream filter(SingularAttribute super X, Boolean> attribute) {
return (RootStream)super.filter(attribute);
}
@Override
public RootStream filter(Function super Root, ? extends Expression> predicateBuilder) {
return (RootStream)super.filter(predicateBuilder);
}
@Override
public RootStream limit(int limit) {
return (RootStream)super.limit(limit);
}
@Override
public RootStream skip(int skip) {
return (RootStream)super.skip(skip);
}
@Override
public RootStream withFlushMode(FlushModeType flushMode) {
return (RootStream)super.withFlushMode(flushMode);
}
@Override
public RootStream withLockMode(LockModeType lockMode) {
return (RootStream)super.withLockMode(lockMode);
}
@Override
public RootStream withHint(String name, Object value) {
return (RootStream)super.withHint(name, value);
}
@Override
public RootStream withHints(Map hints) {
return (RootStream)super.withHints(hints);
}
@Override
public RootStream withLoadGraph(String name) {
return (RootStream)super.withLoadGraph(name);
}
@Override
public RootStream withFetchGraph(String name) {
return (RootStream)super.withFetchGraph(name);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy