1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.query; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
import javax.inject.Singleton; |
25 |
|
|
26 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
27 |
|
import org.slf4j.Logger; |
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.manager.ComponentLookupException; |
30 |
|
import org.xwiki.component.manager.ComponentManager; |
31 |
|
import org.xwiki.context.Execution; |
32 |
|
import org.xwiki.query.QueryExecutor; |
33 |
|
|
34 |
|
import com.xpn.xwiki.XWikiContext; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Singleton |
|
|
| 82.4% |
Uncovered Elements: 3 (17) |
Complexity: 5 |
Complexity Density: 0.38 |
|
44 |
|
public class ConfiguredQueryExecutorProvider implements Provider<QueryExecutor> |
45 |
|
{ |
46 |
|
|
47 |
|
@Inject |
48 |
|
private ComponentManager manager; |
49 |
|
|
50 |
|
|
51 |
|
@Inject |
52 |
|
private Execution exec; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@Inject |
59 |
|
private QueryExecutor queryExecutor; |
60 |
|
|
61 |
|
|
62 |
|
@Inject |
63 |
|
private Logger logger; |
64 |
|
|
65 |
|
|
66 |
|
private boolean initialized; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
|
|
| 70% |
Uncovered Elements: 3 (10) |
Complexity: 3 |
Complexity Density: 0.3 |
|
72 |
23 |
private void init()... |
73 |
|
{ |
74 |
23 |
final XWikiContext context; |
75 |
23 |
try { |
76 |
23 |
context = (XWikiContext) this.exec.getContext().getProperty("xwikicontext"); |
77 |
|
} catch (NullPointerException e) { |
78 |
0 |
this.logger.warn("The QueryExecutor was called without an XWikiContext available. " |
79 |
|
+ "This means the old core (and likely the storage engine) is probably " |
80 |
|
+ "not yet initialized. The default QueryExecutor will be returned.", e); |
81 |
0 |
return; |
82 |
|
} |
83 |
|
|
84 |
23 |
final String storeName = context.getWiki().Param("xwiki.store.main.hint", "default"); |
85 |
23 |
try { |
86 |
23 |
this.queryExecutor = this.manager.getInstance(QueryExecutor.class, storeName); |
87 |
|
} catch (ComponentLookupException e) { |
88 |
0 |
this.logger.warn("Could not find a QueryExecutor with hint [{}] which is the hint for the storage engine, " |
89 |
|
+ "defined in your XWiki configuration under the [xwiki.store.main.hint] property. " |
90 |
|
+ "The default QueryExecutor will be used instead. Reason: [{}]", storeName, |
91 |
|
ExceptionUtils.getRootCauseMessage(e)); |
92 |
|
} |
93 |
|
|
94 |
23 |
this.initialized = true; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
97 |
288 |
@Override... |
98 |
|
public QueryExecutor get() |
99 |
|
{ |
100 |
286 |
if (!this.initialized) { |
101 |
23 |
this.init(); |
102 |
|
} |
103 |
|
|
104 |
287 |
return this.queryExecutor; |
105 |
|
} |
106 |
|
} |