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

File ConfiguredQueryExecutorProvider.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
13
2
1
106
56
5
0.38
6.5
2
2.5

Classes

Class Line # Actions
ConfiguredQueryExecutorProvider 44 13 0% 5 3
0.823529482.4%
 

Contributing tests

No tests hitting this source file were found.

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 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    * A provider of QueryExecutor. Allows providing of a QueryExecutor defined by the configuration.
38    *
39    * @version $Id: 87a101a1ed6ce84ea80e2e5751679d1f9a2d5f2b $
40    * @since 4.0M1
41    */
42    @Component
43    @Singleton
 
44    public class ConfiguredQueryExecutorProvider implements Provider<QueryExecutor>
45    {
46    /** A means of getting QueryExecutors. */
47    @Inject
48    private ComponentManager manager;
49   
50    /** The execution, needed to get the main store hint which is used to choose the QueryExecutor. */
51    @Inject
52    private Execution exec;
53   
54    /**
55    * The QueryExecutor which we will provide. Start off by injecting the default then later (once the XWiki object is
56    * initialized) that will be swapped out for whatever type of storage the system is using as per it's configuration.
57    */
58    @Inject
59    private QueryExecutor queryExecutor;
60   
61    /** The man who cuts down trees. */
62    @Inject
63    private Logger logger;
64   
65    /** Set to true once the query executor has been initialized. */
66    private boolean initialized;
67   
68    /**
69    * Switch the queryExecutor based on what main store is being used. This is called lazily because the XWikiContext
70    * might not yet exist when this class is instantiated.
71    */
 
72  23 toggle 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   
 
97  288 toggle @Override
98    public QueryExecutor get()
99    {
100  286 if (!this.initialized) {
101  23 this.init();
102    }
103   
104  287 return this.queryExecutor;
105    }
106    }