All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.Calendar;
import java.util.Date;
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.Parameter;
import javax.persistence.TemporalType;
import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.PluralAttribute;
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> ref, boolean asc) {
        return (RootStream)super.orderBy(ref, asc);
    }

    @Override
    public RootStream orderBy(SingularAttribute attribute, boolean asc) {
        return (RootStream)super.orderBy(attribute, asc);
    }

    @Override
    public RootStream orderBy(SingularAttribute attribute1, boolean asc1,
      SingularAttribute attribute2, boolean asc2) {
        return (RootStream)super.orderBy(attribute1, asc1, attribute2, asc2);
    }

    @Override
    public RootStream orderBy(SingularAttribute attribute1, boolean asc1,
      SingularAttribute attribute2, boolean asc2, SingularAttribute attribute3, boolean asc3) {
        return (RootStream)super.orderBy(attribute1, asc1, attribute2, asc2, attribute3, asc3);
    }

    @Override
    public RootStream orderBy(Function, ? 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, ? extends List> orderListFunction) {
        return (RootStream)super.orderByMulti(orderListFunction);
    }

    @Override
    public RootStream thenOrderBy(Ref> 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 attribute, boolean asc) {
        return (RootStream)super.thenOrderBy(attribute, asc);
    }

    @Override
    public RootStream thenOrderBy(Function, ? extends Expression> orderExprFunction, boolean asc) {
        return (RootStream)super.thenOrderBy(orderExprFunction, asc);
    }

    @Override
    public RootStream groupBy(Ref> ref) {
        return (RootStream)super.groupBy(ref);
    }

    @Override
    public RootStream groupBy(SingularAttribute attribute) {
        return (RootStream)super.groupBy(attribute);
    }

    @Override
    public RootStream groupBy(Function, ? extends Expression> groupFunction) {
        return (RootStream)super.groupBy(groupFunction);
    }

    @Override
    public RootStream groupByMulti(Function, ? extends List>> groupFunction) {
        return (RootStream)super.groupByMulti(groupFunction);
    }

    @Override
    public RootStream having(Function, ? 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 RootValue findSingle() {
        return (RootValue)super.findSingle();
    }

    @Override
    public  RootStream addRoot(Ref> ref, Class type) {
        return (RootStream)super.addRoot(ref, type);
    }

    @Override
    public RootStream fetch(SingularAttribute attribute) {
        return (RootStream)super.fetch(attribute);
    }

    @Override
    public RootStream fetch(SingularAttribute attribute, JoinType joinType) {
        return (RootStream)super.fetch(attribute, joinType);
    }

    @Override
    public RootStream fetch(PluralAttribute attribute) {
        return (RootStream)super.fetch(attribute);
    }

    @Override
    public RootStream fetch(PluralAttribute attribute, JoinType joinType) {
        return (RootStream)super.fetch(attribute, joinType);
    }

// Narrowing overrides (QueryStreamImpl)

    @Override
    public RootStream bind(Ref> ref) {
        return (RootStream)super.bind(ref);
    }

    @Override
    public RootStream peek(Consumer> peeker) {
        return (RootStream)super.peek(peeker);
    }

    @Override
    public > RootStream bind(
      Ref ref, Function, ? extends S2> refFunction) {
        return (RootStream)super.bind(ref, refFunction);
    }

    @Override
    public RootStream filter(SingularAttribute attribute) {
        return (RootStream)super.filter(attribute);
    }

    @Override
    public RootStream filter(Function, ? 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 withParam(Parameter parameter, T value) {
        return (RootStream)super.withParam(parameter, value);
    }

    @Override
    public RootStream withParam(Parameter parameter, Date value, TemporalType temporalType) {
        return (RootStream)super.withParam(parameter, value, temporalType);
    }

    @Override
    public RootStream withParam(Parameter parameter, Calendar value, TemporalType temporalType) {
        return (RootStream)super.withParam(parameter, value, temporalType);
    }

    @Override
    public RootStream withParams(Iterable> params) {
        return (RootStream)super.withParams(params);
    }

    @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