|
| 1 | +/* |
| 2 | + * Copyright 2025 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.jpa.repository.query; |
| 17 | + |
| 18 | +import java.util.Collections; |
| 19 | +import java.util.List; |
| 20 | + |
| 21 | + |
| 22 | +/** |
| 23 | + * @author Christoph Strobl |
| 24 | + */ |
| 25 | +final class BindableQuery implements DeclaredQuery { |
| 26 | + |
| 27 | + private final DeclaredQuery source; |
| 28 | + private final String bindableQueryString; |
| 29 | + private final List<ParameterBinding> bindings; |
| 30 | + private final boolean usesJdbcStyleParameters; |
| 31 | + |
| 32 | + public BindableQuery(DeclaredQuery source, String bindableQueryString, List<ParameterBinding> bindings, boolean usesJdbcStyleParameters) { |
| 33 | + this.source = source; |
| 34 | + this.bindableQueryString = bindableQueryString; |
| 35 | + this.bindings = bindings; |
| 36 | + this.usesJdbcStyleParameters = usesJdbcStyleParameters; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public boolean isNativeQuery() { |
| 41 | + return source.isNativeQuery(); |
| 42 | + } |
| 43 | + |
| 44 | + boolean hasBindings() { |
| 45 | + return !bindings.isEmpty(); |
| 46 | + } |
| 47 | + |
| 48 | + boolean usesJdbcStyleParameters() { |
| 49 | + return usesJdbcStyleParameters; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public String getQueryString() { |
| 54 | + return bindableQueryString; |
| 55 | + } |
| 56 | + |
| 57 | + public BindableQuery unifyBindings(BindableQuery comparisonQuery) { |
| 58 | + if (comparisonQuery.hasBindings() && !comparisonQuery.bindings.equals(this.bindings)) { |
| 59 | + return new BindableQuery(source, bindableQueryString, comparisonQuery.bindings, usesJdbcStyleParameters); |
| 60 | + } |
| 61 | + return this; |
| 62 | + } |
| 63 | + |
| 64 | + public List<ParameterBinding> getBindings() { |
| 65 | + return Collections.unmodifiableList(bindings); |
| 66 | + } |
| 67 | +} |
0 commit comments