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

com.querydsl.jpa.JPAQueryBase Maven / Gradle / Ivy

The newest version!
/*
 * 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.querydsl.jpa;

import com.querydsl.core.QueryMetadata;
import com.querydsl.core.support.FetchableSubQueryBase;
import com.querydsl.core.types.CollectionExpression;
import com.querydsl.core.types.EntityPath;
import com.querydsl.core.types.MapExpression;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.Expressions;

/**
 * {@code JPAQueryBase} is a base Query class for JPA queries
 *
 * @param  result type
 * @param  concrete subtype
 * @author tiwe
 */
public abstract class JPAQueryBase>
    extends FetchableSubQueryBase implements JPQLQuery {

  protected final JPAQueryMixin queryMixin;

  private final JPQLTemplates templates;

  @SuppressWarnings("unchecked")
  public JPAQueryBase(QueryMetadata md, JPQLTemplates templates) {
    super(new JPAQueryMixin<>(md));
    super.queryMixin.setSelf((Q) this);
    this.queryMixin = (JPAQueryMixin) super.queryMixin;
    this.templates = templates;
  }

  protected JPQLTemplates getTemplates() {
    return templates;
  }

  protected abstract JPQLSerializer createSerializer();

  protected JPQLSerializer serialize(boolean forCountRow) {
    return serialize(forCountRow, true);
  }

  protected JPQLSerializer serialize(boolean forCountRow, boolean validate) {
    if (validate) {
      if (queryMixin.getMetadata().getJoins().isEmpty()) {
        throw new IllegalArgumentException("No sources given");
      }
    }
    var serializer = createSerializer();
    serializer.serialize(queryMixin.getMetadata(), forCountRow, null);
    return serializer;
  }

  protected abstract void reset();

  @Override
  public Q fetchJoin() {
    return queryMixin.fetchJoin();
  }

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

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

  @SuppressWarnings("unchecked")
  @Override
  public 

Q from(CollectionExpression target, Path

alias) { return queryMixin.from(Expressions.as((Path) 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 public String toString() { var serializer = serialize(false, false); return serializer.toString().trim(); } @Override public abstract Q clone(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy