Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2008-2019 the original author or authors.
*
* 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 org.springframework.data.jpa.repository.query;
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
import static org.springframework.data.repository.query.parser.Part.Type.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.SingularAttribute;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.query.ParameterMetadataProvider.ParameterMetadata;
import org.springframework.data.mapping.PropertyPath;
import org.springframework.data.repository.query.ReturnedType;
import org.springframework.data.repository.query.parser.AbstractQueryCreator;
import org.springframework.data.repository.query.parser.Part;
import org.springframework.data.repository.query.parser.Part.Type;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Query creator to create a {@link CriteriaQuery} from a {@link PartTree}.
*
* @author Oliver Gierke
* @author Mark Paluch
* @author Michael Cramer
* @author Mark Paluch
* @author Reda.Housni-Alaoui
*/
public class JpaQueryCreator extends AbstractQueryCreator, Predicate> {
private final CriteriaBuilder builder;
private final Root root;
private final CriteriaQuery query;
private final ParameterMetadataProvider provider;
private final ReturnedType returnedType;
private final PartTree tree;
/**
* Create a new {@link JpaQueryCreator}.
*
* @param tree must not be {@literal null}.
* @param type must not be {@literal null}.
* @param builder must not be {@literal null}.
* @param provider must not be {@literal null}.
*/
public JpaQueryCreator(PartTree tree, ReturnedType type, CriteriaBuilder builder,
ParameterMetadataProvider provider) {
super(tree);
this.tree = tree;
CriteriaQuery criteriaQuery = createCriteriaQuery(builder, type);
this.builder = builder;
this.query = criteriaQuery.distinct(tree.isDistinct());
this.root = query.from(type.getDomainType());
this.provider = provider;
this.returnedType = type;
}
/**
* Creates the {@link CriteriaQuery} to apply predicates on.
*
* @param builder will never be {@literal null}.
* @param type will never be {@literal null}.
* @return must not be {@literal null}.
*/
protected CriteriaQuery createCriteriaQuery(CriteriaBuilder builder, ReturnedType type) {
Class typeToRead = type.getTypeToRead();
return typeToRead == null || tree.isExistsProjection() ? builder.createTupleQuery()
: builder.createQuery(typeToRead);
}
/**
* Returns all {@link javax.persistence.criteria.ParameterExpression} created when creating the query.
*
* @return the parameterExpressions
*/
public List> getParameterExpressions() {
return provider.getExpressions();
}
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.parser.AbstractQueryCreator#create(org.springframework.data.repository.query.parser.Part, java.util.Iterator)
*/
@Override
protected Predicate create(Part part, Iterator