1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.query.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.HashMap; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
|
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.slf4j.LoggerFactory; |
29 |
|
import org.xwiki.query.Query; |
30 |
|
import org.xwiki.query.QueryException; |
31 |
|
import org.xwiki.query.QueryExecutor; |
32 |
|
import org.xwiki.query.QueryFilter; |
33 |
|
import org.xwiki.query.SecureQuery; |
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@version |
39 |
|
@since |
40 |
|
|
|
|
| 97.3% |
Uncovered Elements: 2 (75) |
Complexity: 28 |
Complexity Density: 0.64 |
|
41 |
|
public class DefaultQuery implements SecureQuery |
42 |
|
{ |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultQuery.class); |
47 |
|
|
48 |
|
|
49 |
|
@link |
50 |
|
|
51 |
|
protected boolean isNamed; |
52 |
|
|
53 |
|
|
54 |
|
@link |
55 |
|
|
56 |
|
private String statement; |
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
|
61 |
|
private String language; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private String wiki; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private Map<String, Object> namedParameters = new HashMap<String, Object>(); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private Map<Integer, Object> positionalParameters = new HashMap<Integer, Object>(); |
77 |
|
|
78 |
|
|
79 |
|
@link |
80 |
|
|
81 |
|
private int limit; |
82 |
|
|
83 |
|
|
84 |
|
@link |
85 |
|
|
86 |
|
private int offset; |
87 |
|
|
88 |
|
|
89 |
|
@see |
90 |
|
|
91 |
|
private boolean checkCurrentAuthor; |
92 |
|
|
93 |
|
|
94 |
|
@see |
95 |
|
|
96 |
|
private boolean checkCurrentUser; |
97 |
|
|
98 |
|
|
99 |
|
@link |
100 |
|
|
101 |
|
private List<QueryFilter> filters = new ArrayList<QueryFilter>(); |
102 |
|
|
103 |
|
|
104 |
|
@link |
105 |
|
|
106 |
|
private transient QueryExecutor executer; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
@param |
113 |
|
@param |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
115 |
12104 |
public DefaultQuery(String statement, String language, QueryExecutor executor)... |
116 |
|
{ |
117 |
12104 |
this.statement = statement; |
118 |
12104 |
this.language = language; |
119 |
12104 |
this.executer = executor; |
120 |
12104 |
this.isNamed = false; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
@param |
127 |
|
@param |
128 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
129 |
292 |
public DefaultQuery(String queryName, QueryExecutor executor)... |
130 |
|
{ |
131 |
292 |
this.statement = queryName; |
132 |
291 |
this.executer = executor; |
133 |
292 |
this.isNamed = true; |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
12860 |
@Override... |
137 |
|
public String getStatement() |
138 |
|
{ |
139 |
12861 |
return this.statement; |
140 |
|
} |
141 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
142 |
12217 |
@Override... |
143 |
|
public String getLanguage() |
144 |
|
{ |
145 |
12217 |
return this.language; |
146 |
|
} |
147 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
148 |
23425 |
@Override... |
149 |
|
public boolean isNamed() |
150 |
|
{ |
151 |
23426 |
return this.isNamed; |
152 |
|
} |
153 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
154 |
6926 |
@Override... |
155 |
|
public Query setWiki(String wiki) |
156 |
|
{ |
157 |
6926 |
this.wiki = wiki; |
158 |
6926 |
return this; |
159 |
|
} |
160 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
161 |
19169 |
@Override... |
162 |
|
public String getWiki() |
163 |
|
{ |
164 |
19170 |
return this.wiki; |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
167 |
16882 |
@Override... |
168 |
|
public Query bindValue(String var, Object val) |
169 |
|
{ |
170 |
16883 |
this.namedParameters.put(var, val); |
171 |
16880 |
return this; |
172 |
|
} |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
174 |
343 |
@Override... |
175 |
|
public Query bindValue(int index, Object val) |
176 |
|
{ |
177 |
343 |
this.positionalParameters.put(index, val); |
178 |
343 |
return this; |
179 |
|
} |
180 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
181 |
280 |
@Override... |
182 |
|
public Query bindValues(List<Object> values) |
183 |
|
{ |
184 |
484 |
for (int i = 0; i < values.size(); i++) { |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
|
191 |
204 |
if (Query.HQL.equals(getLanguage())) { |
192 |
204 |
bindValue(i, values.get(i)); |
193 |
|
} else { |
194 |
0 |
bindValue(i + 1, values.get(i)); |
195 |
|
} |
196 |
|
} |
197 |
280 |
return this; |
198 |
|
} |
199 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
200 |
12658 |
@Override... |
201 |
|
public int getLimit() |
202 |
|
{ |
203 |
12657 |
return this.limit; |
204 |
|
} |
205 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
12296 |
@Override... |
207 |
|
public int getOffset() |
208 |
|
{ |
209 |
12294 |
return this.offset; |
210 |
|
} |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
212 |
2079 |
@Override... |
213 |
|
public Query setLimit(int limit) |
214 |
|
{ |
215 |
2082 |
this.limit = limit; |
216 |
2081 |
return this; |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
219 |
2087 |
@Override... |
220 |
|
public Query setOffset(int offset) |
221 |
|
{ |
222 |
2089 |
this.offset = offset; |
223 |
2087 |
return this; |
224 |
|
} |
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
226 |
12233 |
@Override... |
227 |
|
public boolean isCurrentAuthorChecked() |
228 |
|
{ |
229 |
12233 |
return this.checkCurrentAuthor; |
230 |
|
} |
231 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
232 |
773 |
@Override... |
233 |
|
public SecureQuery checkCurrentAuthor(boolean checkCurrentAuthor) |
234 |
|
{ |
235 |
773 |
this.checkCurrentAuthor = checkCurrentAuthor; |
236 |
|
|
237 |
773 |
return this; |
238 |
|
} |
239 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
1052 |
@Override... |
241 |
|
public boolean isCurrentUserChecked() |
242 |
|
{ |
243 |
1052 |
return this.checkCurrentUser; |
244 |
|
} |
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
246 |
1366 |
@Override... |
247 |
|
public SecureQuery checkCurrentUser(boolean checkUser) |
248 |
|
{ |
249 |
1366 |
this.checkCurrentUser = checkUser; |
250 |
|
|
251 |
1366 |
return this; |
252 |
|
} |
253 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
254 |
12307 |
@Override... |
255 |
|
public Map<String, Object> getNamedParameters() |
256 |
|
{ |
257 |
12304 |
return this.namedParameters; |
258 |
|
} |
259 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
260 |
12553 |
@Override... |
261 |
|
public Map<Integer, Object> getPositionalParameters() |
262 |
|
{ |
263 |
12554 |
return this.positionalParameters; |
264 |
|
} |
265 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
266 |
47919 |
@Override... |
267 |
|
public List<QueryFilter> getFilters() |
268 |
|
{ |
269 |
47921 |
return this.filters; |
270 |
|
} |
271 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
272 |
1956 |
@Override... |
273 |
|
public Query addFilter(QueryFilter filter) |
274 |
|
{ |
275 |
1956 |
if (!this.filters.contains(filter)) { |
276 |
1955 |
this.filters.add(filter); |
277 |
|
} else { |
278 |
1 |
LOGGER.warn("QueryFilter [{}] already added to the query [{}]", filter.toString(), this.getStatement()); |
279 |
|
} |
280 |
|
|
281 |
1956 |
return this; |
282 |
|
} |
283 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
12221 |
@Override... |
285 |
|
public <T> List<T> execute() throws QueryException |
286 |
|
{ |
287 |
12221 |
return getExecuter().execute(this); |
288 |
|
} |
289 |
|
|
290 |
|
|
291 |
|
@return |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
293 |
12219 |
protected QueryExecutor getExecuter()... |
294 |
|
{ |
295 |
12220 |
return this.executer; |
296 |
|
} |
297 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
298 |
384 |
@Override... |
299 |
|
public String toString() |
300 |
|
{ |
301 |
384 |
return getStatement(); |
302 |
|
} |
303 |
|
} |