com.mysema.query.sql.ProjectableSQLQuery 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.sql;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import com.mysema.commons.lang.CloseableIterator;
import com.mysema.query.*;
import com.mysema.query.QueryFlag.Position;
import com.mysema.query.support.Expressions;
import com.mysema.query.support.ProjectableQuery;
import com.mysema.query.support.QueryMixin;
import com.mysema.query.types.*;
import com.mysema.query.types.expr.Wildcard;
import com.mysema.query.types.query.ListSubQuery;
import com.mysema.query.types.template.NumberTemplate;
import com.mysema.query.types.template.SimpleTemplate;
/**
* ProjectableSQLQuery is the base type for SQL query implementations
*
* @param concrete subtype
*/
public abstract class ProjectableSQLQuery & Query> extends ProjectableQuery implements SQLCommonQuery {
private static final Path> defaultQueryAlias = new PathImpl(Object.class, "query");
protected final Configuration configuration;
@Nullable
protected Expression> union;
protected SubQueryExpression> firstUnionSubQuery;
protected boolean unionAll;
@SuppressWarnings("unchecked")
public ProjectableSQLQuery(QueryMixin queryMixin, Configuration configuration) {
super(queryMixin);
this.queryMixin.setSelf((Q) this);
this.configuration = configuration;
}
/**
* Add the given String literal as a join flag to the last added join with the position
* BEFORE_TARGET
*
* @param flag
* @return
*/
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q addJoinFlag(String flag) {
return addJoinFlag(flag, JoinFlag.Position.BEFORE_TARGET);
}
/**
* Add the given String literal as a join flag to the last added join
*
* @param flag
* @param position
* @return
*/
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
@SuppressWarnings("unchecked")
public Q addJoinFlag(String flag, JoinFlag.Position position) {
queryMixin.addJoinFlag(new JoinFlag(flag, position));
return (Q)this;
}
/**
* Add the given prefix and expression as a general query flag
*
* @param position position of the flag
* @param prefix prefix for the flag
* @param expr expression of the flag
* @return
*/
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q addFlag(Position position, String prefix, Expression> expr) {
Expression> flag = SimpleTemplate.create(expr.getType(), prefix + "{0}", expr);
return queryMixin.addFlag(new QueryFlag(position, flag));
}
/**
* Add the given query flag
*
* @param flag
* @return
*/
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q addFlag(QueryFlag flag) {
return queryMixin.addFlag(flag);
}
/**
* Add the given String literal as query flag
*
* @param position
* @param flag
* @return
*/
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q addFlag(Position position, String flag) {
return queryMixin.addFlag(new QueryFlag(position, flag));
}
/**
* Add the given Expression as a query flag
*
* @param position
* @param flag
* @return
*/
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q addFlag(Position position, Expression> flag) {
return queryMixin.addFlag(new QueryFlag(position, flag));
}
@Override
public long count() {
Number number = uniqueResult(Wildcard.countAsInt);
return number.longValue();
}
@Override
public boolean exists() {
return singleResult(NumberTemplate.ONE) != null;
}
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q from(Expression> arg) {
return queryMixin.from(arg);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q from(Expression>... args) {
return queryMixin.from(args);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
@SuppressWarnings({ "unchecked", "rawtypes" })
public Q from(SubQueryExpression> subQuery, Path> alias) {
return queryMixin.from(ExpressionUtils.as((Expression) subQuery, alias));
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q fullJoin(EntityPath> target) {
return queryMixin.fullJoin(target);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q fullJoin(RelationalFunctionCall target, Path alias) {
return queryMixin.fullJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q fullJoin(SubQueryExpression> target, Path> alias) {
return queryMixin.fullJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q fullJoin(ForeignKey key, RelationalPath entity) {
return queryMixin.fullJoin(entity).on(key.on(entity));
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q innerJoin(EntityPath> target) {
return queryMixin.innerJoin(target);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q innerJoin(RelationalFunctionCall target, Path alias) {
return queryMixin.innerJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q innerJoin(SubQueryExpression> target, Path> alias) {
return queryMixin.innerJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q innerJoin(ForeignKey key, RelationalPath entity) {
return queryMixin.innerJoin(entity).on(key.on(entity));
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q join(EntityPath> target) {
return queryMixin.join(target);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q join(RelationalFunctionCall target, Path alias) {
return queryMixin.join(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q join(SubQueryExpression> target, Path> alias) {
return queryMixin.join(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q join(ForeignKey key, RelationalPath entity) {
return queryMixin.join(entity).on(key.on(entity));
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q leftJoin(EntityPath> target) {
return queryMixin.leftJoin(target);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q leftJoin(RelationalFunctionCall target, Path alias) {
return queryMixin.leftJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q leftJoin(SubQueryExpression> target, Path> alias) {
return queryMixin.leftJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q leftJoin(ForeignKey key, RelationalPath entity) {
return queryMixin.leftJoin(entity).on(key.on(entity));
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q rightJoin(EntityPath> target) {
return queryMixin.rightJoin(target);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q rightJoin(RelationalFunctionCall target, Path alias) {
return queryMixin.rightJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q rightJoin(SubQueryExpression> target, Path> alias) {
return queryMixin.rightJoin(target, alias);
}
@Override
@WithBridgeMethods(value=AbstractSQLQuery.class, castRequired=true)
public Q rightJoin(ForeignKey key, RelationalPath entity) {
return queryMixin.rightJoin(entity).on(key.on(entity));
}
public QueryMetadata getMetadata() {
return queryMixin.getMetadata();
}
@SuppressWarnings("unchecked")
private
© 2015 - 2025 Weber Informatics LLC | Privacy Policy