1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.query.internal

File DefaultQueryExecutorManager.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
10
2
1
92
52
4
0.4
5
2
2

Classes

Class Line # Actions
DefaultQueryExecutorManager 51 10 0% 4 1
0.928571492.9%
 

Contributing tests

This file is covered by 14 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Default implementation of {@link QueryExecutorManager}.
43    *
44    * @version $Id: a716918ef3b24146eb1ae1269e8dad40510a09ab $
45    */
46    // Note that we force the Component annotation so that this component is only registered as a
47    // QueryExecutorManager and not a QueryExecutor too since we don't want this manager to be visible
48    // to users as a valid QueryExecutor component.
49    @Component(roles = {QueryExecutorManager.class })
50    @Singleton
 
51    public class DefaultQueryExecutorManager implements QueryExecutorManager
52    {
53    @Inject
54    @Named("context")
55    private Provider<ComponentManager> componentManagerProvider;
56   
57    /**
58    * Executor provider for named queries. This provider will give us an executor which is native to the type of
59    * storage engine used.
60    */
61    @Inject
62    private Provider<QueryExecutor> namedQueryExecutorProvider;
63   
 
64  12219 toggle @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   
 
79  12094 toggle @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    }