General Actions:
| Allows querying the XWiki Model using a variety of query languages |
| Type | JAR |
| Developed by | |
| License | GNU Lesser General Public License 2.1 |
| Bundled With | XWiki Enterprise, XWiki Enterprise Manager |
Table of contents
All data making up the XWiki application can be queried using one of the supported Query languages. Right now we support 2 languages:
Historically XWiki was only supporting HQL but that lead to complex queries in some instances and thus we've introduced XWQL which is a JPQL superset and which makes it much easier to write queries for the XWiki model, as you can see in the examples below.
| Query Description | XWQL | HQL | |
|---|---|---|---|
| Query listing all documents | <empty query> | <empty query> | |
| Query listing all documents created after a given date | where doc.creationDate > '2008-01-01' | where doc.creationDate > '2008-01-01' | |
| Query listing all documents last updated by a given user | where doc.author = 'XWiki.LudovicDubost' | where doc.author = 'XWiki.LudovicDubost' | |
| Query listing all documents containing XWiki Objects (XObject) of a given XWiki Class (XClass) | from doc.object(XWiki.XWikiUsers) as user | , BaseObject as obj where doc.fullName = obj.name and obj.className = 'XWiki.XWikiUsers' | |
| Query on XObjects and filtering on XObject property value | where doc.author = 'XWiki.LudovicDubost' and doc.object(XWiki.XWikiUsers).email like '%xwiki.com' | , BaseObject as obj, StringProperty as prop where doc.fullName = obj.name and obj.className = 'XWiki.XWikiUsers' and obj.id=prop.id.id and prop.id.name='email' and prop.value like '%xwiki.com' and doc.author ='XWiki.LudovicDubost' | |
| Query on 2 XObjects | where doc.object(XWiki.XWikiUsers).email like '%xwiki.com' and doc.object(XWiki.ArticleClass).content like '%ludovic%' | , BaseObject as obj, StringProperty as prop, BaseObject as obj2, LargeStringProperty as contentprop where doc.fullName = obj.name and obj.className = 'XWiki.XWikiUsers' and obj.id=prop.id.id and prop.id.name='email' and prop.value like '%xwiki.com' and doc.fullName=obj2.name and obj2.className='XWiki.ArticleClass' and obj2.id=contentprop.id.id and contentprop.id.name='content' and contentprop.value like '%ludovic%' | |
| Search blogs per category | where doc.fullName <> 'XWiki.ArticleClassTemplate' and :category member of doc.object(XWiki.ArticleClass).category | , BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.name=doc.fullName and obj.className='XWiki.ArticleClass' and obj.name<>'XWiki.ArticleClassTemplate' and obj.id=prop.id.id and prop.id.name='category' and list='${category}' order by doc.creationDate desc | |
| List all tags | select distinct obj.tags from Document doc, doc.object(XWiki.TagClass) as obj | select distinct tag from BaseObject as obj, DBStringListProperty as prop join prop.list as tag where obj.className='XWiki.TagClass' and obj.id=prop.id.id and prop.id.name='tags' | |
| List all blog posts, published and not hidden (filter by multiple properties of an object) | from doc.object(Blog.BlogPostClass) as blog where blog.published = '1' and :category member of blog.category and blog.hidden = '0' and doc.web = 'Blog' order by blog.publishDate desc | , BaseObject as obj, IntegerProperty publishedProp, IntegerProperty hiddenProp, DateProperty publishDateProp, DBStringListProperty as categoryProp join categoryProp.list list where obj.name=doc.fullName and obj.className='Blog.BlogPostClass' and doc.space = 'Blog' and obj.id=categoryProp.id.id and categoryProp.id.name='category' and list='$category' and publishedProp.id.id = obj.id and publishedProp.id.name = 'published' and publishedProp.value = '1' and hiddenProp.id.id = obj.id and hiddenProp.id.name='hidden' and hiddenProp.value = '0' and publishDateProp.id.id = obj.id and publishDateProp.id.name='publishDate' order by publishDateProp.value desc |
The principle is to get a reference to the Query Manager, then call a method on it to create a Query for a given Query language. Then on the Query object you can set some behaviors (limit the number of returned result, bind variables, set the offset, set the wiki on which to execute the query) and then execute it.
For XWQL:
Specific example that will return all documents that have comments containing the test string:
For HQL:
For XWQL (example with Groovy):
For HQL:
Get a QueryManager injected. For example :
Obtain and execute a query :
The XWQL grammar is defined here.
Note that currently the XWQL implementation translates queries into HQL which are then executed using Hibernate against the RDBMS.
Note that any JPQL query is a correct XWQL query. This also means almost any HQL query (HQL is a JPQL superset) will work with XWQL (when executed on the XWiki Hibernate store).
| Description | XWQL | HQL | Details |
|---|---|---|---|
| Like statement can't be transformed in XWQL | where upper(doc.name) like 'WEBHOME' | where upper(doc.name) like upper('webhome') | The string_expression must have a string value. The pattern_value is a string literal or a string-valued input parameter |
See the Velocity HQL Guide (till we incorporate it back in this guide).