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

File QueryManagerScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
8
4
1
106
44
5
0.62
2
4
1.25

Classes

Class Line # Actions
QueryManagerScriptService 44 8 0% 5 3
0.7857142778.6%
 

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 org.xwiki.query.script;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Singleton;
25   
26    import org.xwiki.component.annotation.Component;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.query.Query;
29    import org.xwiki.query.QueryException;
30    import org.xwiki.query.QueryManager;
31    import org.xwiki.query.SecureQuery;
32    import org.xwiki.query.internal.ScriptQuery;
33    import org.xwiki.script.service.ScriptService;
34   
35    /**
36    * Provides Query Manager-specific Scripting APIs.
37    *
38    * @version $Id: 4fd1b6a2a8c107eb5569305dcebdf7ffe0e13181 $
39    * @since 2.4M2
40    */
41    @Component
42    @Named("query")
43    @Singleton
 
44    public class QueryManagerScriptService implements ScriptService
45    {
46    /**
47    * Secure query manager that performs checks on rights depending on the query being executed.
48    */
49    @Inject
50    @Named("secure")
51    private QueryManager secureQueryManager;
52   
53    /**
54    * Used to create {@link org.xwiki.query.internal.ScriptQuery}.
55    */
56    @Inject
57    private ComponentManager componentManager;
58   
59    /**
60    * Shortcut for writing a XWQL query.
61    *
62    * @param statement the XWQL statement for the query
63    * @return the Query object, ready to be executed
64    * @throws org.xwiki.query.QueryException if any errors
65    */
 
66  71 toggle public Query xwql(String statement) throws QueryException
67    {
68  71 return createQuery(statement, Query.XWQL, false);
69    }
70   
71    /**
72    * Shortcut for writing a HQL query.
73    *
74    * @param statement the HQL statement for the query
75    * @return the Query object, ready to be executed
76    * @throws org.xwiki.query.QueryException if any errors
77    */
 
78  292 toggle public Query hql(String statement) throws QueryException
79    {
80  292 return createQuery(statement, Query.HQL, false);
81    }
82   
83    /**
84    * Create a Query for the given statement and language.
85    *
86    * @param statement the query statement
87    * @param language language of the query. Must be a supported language.
88    * @return the Query object
89    * @throws QueryException if language is not supported
90    */
 
91  0 toggle public Query createQuery(String statement, String language) throws QueryException
92    {
93  0 return createQuery(statement, language, true);
94    }
95   
 
96  363 toggle private Query createQuery(String statement, String language, boolean checkCurrentUser) throws QueryException
97    {
98  363 Query query = this.secureQueryManager.createQuery(statement, language);
99  363 if (query instanceof SecureQuery) {
100  363 ((SecureQuery) query).checkCurrentAuthor(true);
101  363 ((SecureQuery) query).checkCurrentUser(checkCurrentUser);
102    }
103   
104  363 return new ScriptQuery(query, this.componentManager);
105    }
106    }