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.lang.reflect.Type; |
23 |
|
import java.util.HashSet; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Set; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Named; |
29 |
|
import javax.inject.Provider; |
30 |
|
import javax.inject.Singleton; |
31 |
|
|
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
34 |
|
import org.xwiki.component.manager.ComponentLookupException; |
35 |
|
import org.xwiki.component.manager.ComponentManager; |
36 |
|
import org.xwiki.query.Query; |
37 |
|
import org.xwiki.query.QueryException; |
38 |
|
import org.xwiki.query.QueryExecutor; |
39 |
|
import org.xwiki.query.QueryExecutorManager; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@Component(roles = {QueryExecutorManager.class }) |
50 |
|
@Singleton |
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
51 |
|
public class DefaultQueryExecutorManager implements QueryExecutorManager |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
@Named("context") |
55 |
|
private Provider<ComponentManager> componentManagerProvider; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
private Provider<QueryExecutor> namedQueryExecutorProvider; |
63 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
64 |
12219 |
@Override... |
65 |
|
public <T> List<T> execute(Query query) throws QueryException |
66 |
|
{ |
67 |
12223 |
if (query.isNamed()) { |
68 |
289 |
return this.namedQueryExecutorProvider.get().execute(query); |
69 |
|
} else { |
70 |
11934 |
try { |
71 |
11934 |
return this.componentManagerProvider.get() |
72 |
|
.<QueryExecutor>getInstance(QueryExecutor.class, query.getLanguage()).execute(query); |
73 |
|
} catch (ComponentLookupException e) { |
74 |
0 |
throw new QueryException("Fail to lookup query executor", query, e); |
75 |
|
} |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
79 |
12094 |
@Override... |
80 |
|
public Set<String> getLanguages() |
81 |
|
{ |
82 |
12094 |
List<ComponentDescriptor<QueryExecutor>> executors = |
83 |
|
this.componentManagerProvider.get().getComponentDescriptorList((Type) QueryExecutor.class); |
84 |
|
|
85 |
12094 |
Set<String> executorNames = new HashSet<String>(executors.size()); |
86 |
12094 |
for (ComponentDescriptor<QueryExecutor> executor : executors) { |
87 |
43317 |
executorNames.add(executor.getRoleHint()); |
88 |
|
} |
89 |
|
|
90 |
12094 |
return executorNames; |
91 |
|
} |
92 |
|
} |