1 /*
2  * Copyright 2018-2020 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 import org.springframework.lang.Nullable;
22 import org.springframework.util.Assert;
23
24 /**
25  * NULL-Object pattern implementation for {@link DeclaredQuery}.
26  *
27  * @author Jens Schauder
28  * @since 2.0.3
29  */

30 class EmptyDeclaredQuery implements DeclaredQuery {
31
32     /**
33      * An implementation implementing the NULL-Object pattern for situations where there is no query.
34      */

35     static final DeclaredQuery EMPTY_QUERY = new EmptyDeclaredQuery();
36
37     /*
38      * (non-Javadoc)
39      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#hasNamedParameter()
40      */

41     @Override
42     public boolean hasNamedParameter() {
43         return false;
44     }
45
46     /*
47      * (non-Javadoc)
48      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#getQueryString()
49      */

50     @Override
51     public String getQueryString() {
52         return "";
53     }
54
55     /*
56      * (non-Javadoc)
57      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#getAlias()
58      */

59     @Override
60     public String getAlias() {
61         return null;
62     }
63
64     /*
65      * (non-Javadoc)
66      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#hasConstructorExpression()
67      */

68     @Override
69     public boolean hasConstructorExpression() {
70         return false;
71     }
72
73     /*
74      * (non-Javadoc)
75      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#isDefaultProjection()
76      */

77     @Override
78     public boolean isDefaultProjection() {
79         return false;
80     }
81
82     /*
83      * (non-Javadoc)
84      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#getParameterBindings()
85      */

86     @Override
87     public List<StringQuery.ParameterBinding> getParameterBindings() {
88         return Collections.emptyList();
89     }
90
91     /*
92      * (non-Javadoc)
93      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#deriveCountQuery(java.lang.String, java.lang.String)
94      */

95     @Override
96     public DeclaredQuery deriveCountQuery(@Nullable String countQuery, @Nullable String countQueryProjection) {
97
98         Assert.hasText(countQuery, "CountQuery must not be empty!");
99
100         return DeclaredQuery.of(countQuery);
101     }
102
103     /*
104      * (non-Javadoc)
105      * @see org.springframework.data.jpa.repository.query.DeclaredQuery#usesJdbcStyleParameters()
106      */

107     @Override
108     public boolean usesJdbcStyleParameters() {
109         return false;
110     }
111 }
112