[xwiki-users] DB List Query Problems
I am trying to create a query to populate an attribute of an object with all the “Name” (an attribute of another object) . I seem to have run into an issue, in which I created a special space (CustomClass) to house all my User defined classes. I can’t seem to build a query to access that space. I have tried to normal default query that I found which worked was: select doc.fullName from XWikiDocument doc this of course returns all the documents in the wiki. Is there a way that I can get all the pages listed in a specific space and not just the XWiki default space (I assume I should be able to do this), and if I can do this, how can I query an instance of a class (Foo) that lives in the CustomClass I have tried and several permutations of the following query. I am hitting my head against a wall and all help would be greatly appreciated. Things that have been unsucessfull, Xwiki.CustomClass.Foo, Foo itself, the modifier seen below, I am at a loss on how to currently approach this. select foo.Name from CustomClass.Foo foo I am new to HQL, and while I have read up, it has not quite yet solved my problem in dealing with this XWiki problem. It is important to note that I have also taken the query out and used the feiled for Class, and Value but that also did not work. Advice? Thank you Martin Bryant Modus Operandi -- View this message in context: http://xwiki.475771.n2.nabble.com/DB-List-Query-Problems-tp5654730p5654730.h... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi! mbryant wrote:
I am trying to create a query to populate an attribute of an object with all the “Name” (an attribute of another object) .
I seem to have run into an issue, in which I created a special space (CustomClass) to house all my User defined classes.
I can’t seem to build a query to access that space.
I have tried to normal default query that I found which worked was:
select doc.fullName from XWikiDocument doc
this of course returns all the documents in the wiki.
Is there a way that I can get all the pages listed in a specific space and not just the XWiki default space (I assume I should be able to do this),
#set($hql = "where doc.space='YourSpace')
and if I can do this, how can I query an instance of a class (Foo) that lives in the CustomClass
Do you mean querying instances of a class instantiate in a given document? I think many examples in... http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples ... apply to your situation. If you want to get all objects of a given class: http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples#HGetti... If you want to query properties on that objects: http://platform.xwiki.org/xwiki/bin/view/DevGuide/velocityHqlExamples#HGetti... I can't help with the update part of your question. But I think I would be better if you get the select clause working first!
I have tried and several permutations of the following query. I am hitting my head against a wall and all help would be greatly appreciated. Things that have been unsucessfull, Xwiki.CustomClass.Foo, Foo itself, the modifier seen below, I am at a loss on how to currently approach this.
select foo.Name from CustomClass.Foo foo
I am new to HQL, and while I have read up, it has not quite yet solved my problem in dealing with this XWiki problem. It is important to note that I have also taken the query out and used the feiled for Class, and Value but that also did not work. Advice?
Thank you
Martin Bryant Modus Operandi
HTH. If it doesn't, don't hesitate to be more specific and I'll try to help! I'm learning HQL myself! :-) Greetings! Ricardo -- Ricardo Rodríguez CTO eBioTIC. Life Sciences, Data Modeling and Information Management Systems
So using HQL in velocity helps a little, I have been able to get results, and for that I thank you. I did run into an unexpected issues that you might be able to help with. Below is the query that was used {{velocity}} #set($hql = "select obj.name, prop.value from BaseObject obj, StringProperty prop where obj.className='CustClasses.ToolClass' and prop.id.id=obj.id and prop.name='ProductName'") #set($results = $xwiki.search($hql, 1000, 0)) #foreach ($item in $results) * $item #end {{/velocity}} While I get a result it is an unexpected value, it appears to have returned the object ID see below: * [Ljava.lang.Object;@af0baa It should be noted when I just try to get the obj.name without the property value it works fine. Now that I know the Query generally works in Velocity, It should be the same thing to just cut and paste the Query into the DB List attribute of an object. Thanks for your continued help and timely response. On a side note, I would like to be able to create links on results (when used inside of a velocity script on a page), is there an easy way to do that as well? Martin Modus Operandi -- View this message in context: http://xwiki.475771.n2.nabble.com/DB-List-Query-Problems-tp5654730p5656001.h... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi Martin, On 10/20/2010 09:10 PM, mbryant wrote:
So using HQL in velocity helps a little, I have been able to get results, and for that I thank you. I did run into an unexpected issues that you might be able to help with. Below is the query that was used
{{velocity}}
#set($hql = "select obj.name, prop.value from BaseObject obj, StringProperty prop where obj.className='CustClasses.ToolClass' and prop.id.id=obj.id and prop.name='ProductName'")
#set($results = $xwiki.search($hql, 1000, 0)) #foreach ($item in $results) * $item #end {{/velocity}}
While I get a result it is an unexpected value, it appears to have returned the object ID see below:
* [Ljava.lang.Object;@af0baa
That's normal because $item is an array of Java objects (xobject name and property value) and by simply printing $item you are in fact calling its toString() method which returns the string you see.
It should be noted when I just try to get the obj.name without the property value it works fine.
That's normal too, because in this case $item is not an array of Java objects but a string (xobject name). You can use this code to display the results: |=Object Name|=Property Value #foreach ($item in $results) |$item.get(0)|$item.get(1) #end Hope this helps, Marius
Now that I know the Query generally works in Velocity, It should be the same thing to just cut and paste the Query into the DB List attribute of an object.
Thanks for your continued help and timely response.
On a side note, I would like to be able to create links on results (when used inside of a velocity script on a page), is there an easy way to do that as well?
Martin Modus Operandi
Marius Dumitru Florea wrote:
Hi Martin,
On 10/20/2010 09:10 PM, mbryant wrote:
So using HQL in velocity helps a little, I have been able to get results, and for that I thank you. I did run into an unexpected issues that you might be able to help with. Below is the query that was used
{{velocity}}
#set($hql = "select obj.name, prop.value from BaseObject obj, StringProperty prop where obj.className='CustClasses.ToolClass' and prop.id.id=obj.id and prop.name='ProductName'")
#set($results = $xwiki.search($hql, 1000, 0)) #foreach ($item in $results) * $item #end {{/velocity}}
While I get a result it is an unexpected value, it appears to have returned the object ID see below:
* [Ljava.lang.Object;@af0baa
That's normal because $item is an array of Java objects (xobject name and property value) and by simply printing $item you are in fact calling its toString() method which returns the string you see.
It should be noted when I just try to get the obj.name without the property value it works fine.
That's normal too, because in this case $item is not an array of Java objects but a string (xobject name).
You can use this code to display the results:
|=Object Name|=Property Value #foreach ($item in $results) |$item.get(0)|$item.get(1) #end
Hope this helps, Marius
Now that I know the Query generally works in Velocity, It should be the same thing to just cut and paste the Query into the DB List attribute of an object.
Thanks for your continued help and timely response.
On a side note, I would like to be able to create links on results (when used inside of a velocity script on a page), is there an easy way to do that as well?
Martin Modus Operandi
You can use the public API method $searchDocuments this way...
{{velocity}} #set($query = ", BaseObject as obj, StringProperty as productName where doc.fullName = obj.name and obj.className='CustClasses.ToolClass' order by doc.fullName asc") #set($results=$xwiki.searchDocuments($query)) #foreach($item in $results) #set($itemdoc = $xwiki.getDocument($item)) [[$itemdoc.display('Name')>>$item]] #end {{/velocity}} Look for $searchDocuments in the API JavaDoc to better understantd what you are doing... http://platform.xwiki.org/xwiki/bin/view/DevGuide/API I, like you, I'm still trying to understand the whole stuff and to be able to do things as "easy" as developers do! :-) Greetings, Ricardo -- Ricardo Rodríguez CTO eBioTIC. Life Sciences, Data Modeling and Information Management Systems
participants (3)
-
[Ricardo Rodriguez] eBioTIC. -
Marius Dumitru Florea -
mbryant