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

com.mysema.query.jpa.AbstractJPASubQuery Maven / Gradle / Ivy

/*
 * Copyright 2015, The Querydsl Team (http://www.querydsl.com/team)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mysema.query.jpa;

import java.util.List;

import com.google.common.collect.Lists;
import com.mysema.query.DefaultQueryMetadata;
import com.mysema.query.JoinExpression;
import com.mysema.query.JoinType;
import com.mysema.query.QueryMetadata;
import com.mysema.query.support.DetachableQuery;
import com.mysema.query.support.Expressions;
import com.mysema.query.types.*;
import com.mysema.query.types.query.NumberSubQuery;
import com.mysema.query.types.template.NumberTemplate;

/**
 * Abstract superclass for SubQuery implementations
 *
 * @author tiwe
 *
 * @param  concrete subtype
 */
public class AbstractJPASubQuery> extends DetachableQuery implements JPQLSubQuery {

    private final JPAQueryMixin queryMixin;

    public AbstractJPASubQuery() {
        this(new DefaultQueryMetadata().noValidate());
    }

    @SuppressWarnings("unchecked")
    public AbstractJPASubQuery(QueryMetadata metadata) {
        super(new JPAQueryMixin(metadata));
        super.queryMixin.setSelf((Q)this);
        this.queryMixin = (JPAQueryMixin) super.queryMixin;
    }

    @Override
    public NumberSubQuery count() {
        StringBuilder count = new StringBuilder("count(");
        List> args = Lists.newArrayList();
        for (JoinExpression join : queryMixin.getMetadata().getJoins()) {
            if (join.getType() == JoinType.DEFAULT) {
                if (!args.isEmpty()) {
                    count.append(", ");
                }
                count.append("{" + args.size() + "}");
                args.add(join.getTarget());
            }
        }
        count.append(")");
        return unique(NumberTemplate.create(Long.class, count.toString(), args.toArray()));
    }

    public Q from(EntityPath o) {
        return queryMixin.from(o);
    }

    @Override
    public Q from(EntityPath... o) {
        return queryMixin.from(o);
    }

    @Override
    public 

Q from(CollectionExpression target, Path

alias) { return queryMixin.from(Expressions.as((Path)target, alias)); } @Override @Deprecated public

Q fullJoin(CollectionExpression target) { return queryMixin.fullJoin(target); } @Override @Deprecated public

Q fullJoin(CollectionExpression target, Path

alias) { return queryMixin.fullJoin(target, alias); } @Override @Deprecated public

Q fullJoin(EntityPath

target) { return queryMixin.fullJoin(target); } @Override @Deprecated public

Q fullJoin(EntityPath

target, Path

alias) { return queryMixin.fullJoin(target, alias); } @Override @Deprecated public

Q fullJoin(MapExpression target) { return queryMixin.fullJoin(target); } @Override @Deprecated public

Q fullJoin(MapExpression target, Path

alias) { return queryMixin.fullJoin(target, alias); } @Override public

Q innerJoin(CollectionExpression target) { return queryMixin.innerJoin(target); } @Override public

Q innerJoin(CollectionExpression target, Path

alias) { return queryMixin.innerJoin(target, alias); } @Override public

Q innerJoin(EntityPath

target) { return queryMixin.innerJoin(target); } @Override public

Q innerJoin(EntityPath

target, Path

alias) { return queryMixin.innerJoin(target, alias); } @Override public

Q innerJoin(MapExpression target) { return queryMixin.innerJoin(target); } @Override public

Q innerJoin(MapExpression target, Path

alias) { return queryMixin.innerJoin(target, alias); } @Override public

Q join(CollectionExpression target) { return queryMixin.join(target); } @Override public

Q join(CollectionExpression target, Path

alias) { return queryMixin.join(target, alias); } @Override public

Q join(EntityPath

target) { return queryMixin.join(target); } @Override public

Q join(EntityPath

target, Path

alias) { return queryMixin.join(target, alias); } @Override public

Q join(MapExpression target) { return queryMixin.join(target); } @Override public

Q join(MapExpression target, Path

alias) { return queryMixin.join(target, alias); } @Override public

Q leftJoin(CollectionExpression target) { return queryMixin.leftJoin(target); } @Override public

Q leftJoin(CollectionExpression target, Path

alias) { return queryMixin.leftJoin(target, alias); } @Override public

Q leftJoin(EntityPath

target) { return queryMixin.leftJoin(target); } @Override public

Q leftJoin(EntityPath

target, Path

alias) { return queryMixin.leftJoin(target, alias); } @Override public

Q leftJoin(MapExpression target) { return queryMixin.leftJoin(target); } @Override public

Q leftJoin(MapExpression target, Path

alias) { return queryMixin.leftJoin(target, alias); } @Override public

Q rightJoin(CollectionExpression target) { return queryMixin.rightJoin(target); } @Override public

Q rightJoin(CollectionExpression target, Path

alias) { return queryMixin.rightJoin(target, alias); } @Override public

Q rightJoin(EntityPath

target) { return queryMixin.rightJoin(target); } @Override public

Q rightJoin(EntityPath

target, Path

alias) { return queryMixin.rightJoin(target, alias); } @Override public

Q rightJoin(MapExpression target) { return queryMixin.rightJoin(target); } @Override public

Q rightJoin(MapExpression target, Path

alias) { return queryMixin.rightJoin(target, alias); } public Q on(Predicate condition) { return queryMixin.on(condition); } @Override public Q on(Predicate... conditions) { return queryMixin.on(conditions); } @Override @Deprecated public Q limit(long l) { throw new UnsupportedOperationException("JPQL doesn't support limit on subqueries"); } @Override @Deprecated public Q offset(long o) { throw new UnsupportedOperationException("JPQL doesn't support offset on subqueries"); } @Override @Deprecated public Q orderBy(OrderSpecifier o) { throw new UnsupportedOperationException("JPQL doesn't support order by on subqueries"); } @Override @Deprecated public Q orderBy(OrderSpecifier... o) { throw new UnsupportedOperationException("JPQL doesn't support order by on subqueries"); } @Override public String toString() { if (!queryMixin.getMetadata().getJoins().isEmpty()) { JPQLSerializer serializer = new JPQLSerializer(JPQLTemplates.DEFAULT, null); serializer.setStrict(false); serializer.serialize(queryMixin.getMetadata(), false, null); return serializer.toString().trim(); } else { return super.toString(); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy