On 6/6/07, [email protected] <[email protected]> wrote:
Hello,
I have problems making a query to retrieve from the database all the objects that are from a certain class (e.g "TryClass") and of a certain type as well (e.g "StaticListClass"). Can anyone give me a hint please?
Thank you very much.
Evelina Slatineanu
Hi, You should look in the hibernate mapping file to find out what are the terms you can use inside hql. There are 3 types of string properties: StringProperty, StringListProperty, DBStringListProperty. StringProperties are easy to retrieve, since they contain just one value per object. The query is something like: select distinct prop.value from BaseObject as obj, StringProperty as prop where obj.className='${xclass}' and obj.id=prop.id.id and prop.id.name='${xprop}' You should be able to pass the xclass and xprop parameters from the java displayEdit method to the javascript making the AJAX call, and from there to the velocity script returning the suggested items. The query indeed requires programming rights, so it should go to a special document in the XWiki space, something like XWiki.Suggest StringListProperties are a bit more difficult, since you retrieve the list of values as one string. The query is: select distinct prop.textValue from BaseObject as obj, StringListProperty as prop where obj.className='${xlass}' and obj.id=prop.id.id and prop.id.name='${xprop}' You will then need to split each result using the separators specified in the definition for that property. DBStringListProperties are easy to retrieve, though the query is a bit more difficult to find out when you don't know it already: select distinct list from BaseObject as obj, DBStringListProperty as prop join prop.list list where obj.className='${xclass}' and obj.id=prop.id.id and prop.id.name='${xprop}' This returns all the existing values, one per row. Now, you need to decide which type of property you have. The type of property used is not given by the type of property class you put in the class, but by the settings for multiSelect and relationalStorage, like this: if relationalStorage is true, then use DBStringListProperty, even for StaticListClass else, if multiSelect is true, use StringListProperty else use StringProperty, even for DBStringListClass So, when making the query, you need to do something like: if (isRelationalStorage() { make DBStringListProperty query } else if (isMultiSelect()) { make StringListProperty query } else { make StringProperty query } You should write this pseudocode in velocity. The object on which to call the is*() methods is the property definition, retrieved like: $xwiki.getDocument(${xclass}).getxWikiClass().get(${xprop}).isRelationalStorage() The problem is that these methods are not in the API, but they should be added (hint: you can make a JIRA issue and a patch for this). Meanwhile, you can use: $xwiki.getDocument(${xclass}).getxWikiClass().get(${xprop}).getPropertyClass().isRelationalStorage() which requires programming rights. Sergiu -- http://purl.org/net/sergiu