cogAllow testing queries written in XWQL and HQL syntax, including usage of usual filters.
Developed by

Denis Gervalle

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

Description

You just have to put the following snippet into a xwiki page:

{{velocity}}
#set ($filters = $request.getParameterValues('filters'))
#macro (filterCheckbox $filter $default)
   <label class="checkbox-inline"><input type="checkbox" name="filters" value="$filter" #if($!filters.contains($filter) || ($default && !$filters))checked="checked"#end/>$filter</label>
#end
{{html wiki="true"}}
<form method="post">
<div class="form-group"><label for="lg">Query language</label>
 <select class="form-control" id="lg" name="querylg">
   <option value="xwql" #if ("$!request.querylg" == "xwql")selected#end>XWiki Query Language (XWQL)</option>
   <option value="hql" #if ("$!request.querylg" == "hql")selected#end>Hibernate Query Language (HQL)</option>
 </select>
</div>
<div class="form-group"><label for="limit">Limit (not applied to count filter)</label><input class="form-control" id="limit" name="limit" value="#if ("$!request.limit" != "")$request.limit#{else}50#end" /></div>
<div class="form-group">
 <label for="filters">Filters</label>
 <div class="form-group">
   <input class="hidden" type="checkbox" name="filters" value="none" checked="checked"/>
   #filterCheckbox('count' false)
   #filterCheckbox('hidden' true)
   #filterCheckbox('unique' false)
   #filterCheckbox('language' false)
   #filterCheckbox('currentlanguage' true)
 </div>
</div>
<div class="form-group"><label for="xwqlQuery">XWQL</label><textarea class="form-control" name="xwqlQuery" rows="4">
#if($request.xwqlQuery)$request.xwqlQuery#{else}from doc.object(XWiki.XWikiUsers) as user#end
</textarea></div>
<div class="form-group"><input class="button" type="submit" value="Submit XWQL query" onclick="$('lg').value='xwql'" /></div>
<div class="form-group"><label for="hqlQuery">HQL</label><textarea class="form-control" name="hqlQuery" rows="4">
#if($request.hqlQuery)$request.hqlQuery#{else}select doc.fullName, firstname.value, lastname.value from XWikiDocument doc, BaseObject obj, StringProperty firstname, StringProperty lastname where obj.className='XWiki.XWikiUsers' and obj.name=doc.fullName and obj.id=firstname.id.id and firstname.id.name='first_name' and lastname.id.name='last_name' and obj.id=lastname.id.id
#end
</textarea></div>
<div class="form-group"><input class="button" type="submit" value="Submit HQL query" onclick="$('lg').value='hql'" /></div>
</form>
{{/html}}
{{/velocity}}

{{velocity}}
#try()
 #if ($filters)
=== Results
   #if ("$!request.querylg" == "xwql")
     #set ($query = $services.query.xwql($request.xwqlQuery.trim()))
   #elseif ("$!request.querylg" == "hql")
     #set ($query = $services.query.hql($request.hqlQuery.trim()))
   #end
   #if ($filters)
     #foreach($filter in $filters)
       #if ($filter != 'none')
         #set ($query = $query.addFilter($filter))
       #end
     #end
   #end
   #if (!$!filters.contains('count'))
     #set ($query = $query.setLimit($mathtool.toInteger($request.limit)))
   #end
   #set ($results = $query.execute())
   #foreach ($result in $results)
     #if ($result.size())
       #foreach ($item in $result)| #if($item == $NULL)NULL#else$item#end#end

     #else
        | $result
     #end
   #end
 #end
#end

#if ("$!exception" != '')
 {{html}}
   #displayUnhandledException($exception)
 {{/html}}
 #if ($!exception != '')
   #set ($exception = '')
 #end
#end
{{/velocity}}

You will get a UI like this:

querytester.png

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags:
Created by Denis Gervalle on 2017/04/03 12:43
     

Get Connected