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 2017 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 java.util.List;
import java.util.function.Function;
import javax.persistence.Query;
import javax.persistence.TemporalType;
import org.springframework.data.jpa.repository.query.JpaParameters.JpaParameter;
import org.springframework.data.jpa.repository.query.ParameterMetadataProvider.ParameterMetadata;
import org.springframework.data.jpa.repository.query.QueryParameterSetter.NamedOrIndexedQueryParameterSetter;
import org.springframework.data.jpa.repository.query.StringQuery.ParameterBinding;
import org.springframework.data.repository.query.EvaluationContextProvider;
import org.springframework.data.repository.query.Parameter;
import org.springframework.data.repository.query.Parameters;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Encapsulates different strategies for the creation of a {@link QueryParameterSetter} from a {@link Query} and a
* {@link ParameterBinding}
*
* @author Jens Schauder
* @author Oliver Gierke
* @author Mark Paluch
* @since 2.0
*/
abstract class QueryParameterSetterFactory {
@Nullable
abstract QueryParameterSetter create(ParameterBinding binding, @Nullable String queryString);
/**
* Creates a new {@link QueryParameterSetterFactory} for the given {@link JpaParameters}.
*
* @param parameters must not be {@literal null}.
* @return a basic {@link QueryParameterSetterFactory} that can handle named and index parameters.
*/
static QueryParameterSetterFactory basic(JpaParameters parameters) {
Assert.notNull(parameters, "JpaParameters must not be null!");
return new BasicQueryParameterSetterFactory(parameters);
}
/**
* Creates a new {@link QueryParameterSetterFactory} using the given {@link JpaParameters} and
* {@link ParameterMetadata}.
*
* @param parameters must not be {@literal null}.
* @param metadata must not be {@literal null}.
* @return a {@link QueryParameterSetterFactory} for criteria Queries.
*/
static QueryParameterSetterFactory forCriteriaQuery(JpaParameters parameters, List> metadata) {
Assert.notNull(parameters, "JpaParameters must not be null!");
Assert.notNull(metadata, "ParameterMetadata must not be null!");
return new CriteriaQueryParameterSetterFactory(parameters, metadata);
}
/**
* Creates a new {@link QueryParameterSetterFactory} for the given {@link SpelExpressionParser},
* {@link EvaluationContextProvider} and {@link Parameters}.
*
* @param parser must not be {@literal null}.
* @param evaluationContextProvider must not be {@literal null}.
* @param parameters must not be {@literal null}.
* @return a {@link QueryParameterSetterFactory} that can handle
* {@link org.springframework.expression.spel.standard.SpelExpression}s.
*/
static QueryParameterSetterFactory parsing(SpelExpressionParser parser,
EvaluationContextProvider evaluationContextProvider, Parameters parameters) {
Assert.notNull(parser, "SpelExpressionParser must not be null!");
Assert.notNull(evaluationContextProvider, "EvaluationContextProvider must not be null!");
Assert.notNull(parameters, "Parameters must not be null!");
return new ExpressionBasedQueryParameterSetterFactory(parser, evaluationContextProvider, parameters);
}
/**
* Creates a {@link QueryParameterSetter} from a {@link JpaParameter}. Handles named and indexed parameters,
* TemporalType annotations and might ignore certain exception when requested to do so.
*
* @param valueExtractor extracts the relevant value from an array of method parameter values.
* @param binding the binding of the query parameter to be set.
* @param parameter the method parameter to bind.
* @param lenient when true certain exceptions thrown when setting the query parameters get ignored.
*/
private static QueryParameterSetter createSetter(Function