VelocityToc
Last modified by Vincent Massol on 2009/09/08 14:08
Contents
HQL Query Examples in Velocity
XWiki allows user to access documents and objects with HQL queries in Velocity scripts.
Public API (searchDocuments)
You can execute queries as follows:Simple Query
qqqOrdered Query
qqqAdvanced Query (date & time)
Since there is no standard way to calculate dates interval in HQL those queries are a bit unnatural. qqqOther examples, documents modified :
during current day : "where year(doc.date) = year(current_date()) and month(doc.date) = month(current_date()) and day(doc.date) > (day(current_date()) - 1) order by doc.date desc"
during current week : "where year(doc.date) = year(current_date()) and month(doc.date) = month(current_date()) and day(doc.date) > (day(current_date()) - 7) order by doc.date desc"
during current month : "where year(doc.date) = year(current_date()) and month(doc.date) > (month(current_date()) - 1) order by doc.date desc"
during current day : "where year(doc.date) = year(current_date()) and month(doc.date) = month(current_date()) and day(doc.date) > (day(current_date()) - 1) order by doc.date desc"
during current week : "where year(doc.date) = year(current_date()) and month(doc.date) = month(current_date()) and day(doc.date) > (day(current_date()) - 7) order by doc.date desc"
during current month : "where year(doc.date) = year(current_date()) and month(doc.date) > (month(current_date()) - 1) order by doc.date desc"
Privileged API (search : Documents, Objects, Properties, etc)
You can execute queries as follows:Simple Query
qqqCount Query
qqqSimple Query with multiple fields
qqqGetting objects of a specific class
qqGetting objects’ properties
qqqGetting documents where objects’ properties equals some value
qqqqList users currently editing pages
qqqList attachments of a page
qqNon-exhaustive list of queryable object fields
XWikiDocument
- XWikiDocument.fullName : full name, including space and page name. Example of value : Main.WebHome.
- XWikiDocument.author : last editor. Example of value : XWiki.Admin.
- XWikiDocument.creator : first editor. Example of value : XWiki.Admin.
BaseObject
- BaseObject.id : arbitrary unique id of the object. Example of value : 123456789.
- BaseObject.className : class. Example of value : XWiki.XWikiUsers.
*Property (StringProperty, etc)
- Property.id.id : unique id of the object the property belongs to. Example of value : 123456789.
- Property.name : name of the property. Example of value : first_name.
- Property.value : value. Example of value : John.