On Thu, Feb 25, 2016 at 1:33 PM, Peter Huisman <p.huis...@ximm.nl> wrote:

> Hi,
>
> I have the following question.
>
> I have an main wiki (xwiki) and a subwiki (test)
> I want to access objects from class ’space.someclassClass’ located on a
> page ‘space.somepage' in the main wiki
> When in the subwiki, I have a query such as:
>
> String query = "select name.value from XWikiDocument doc, BaseObject obj,
> StringProperty name where doc.fullName=obj.name and
> obj.className=‘space.someclassClass’ and” +
>      "obj.className<>’space.someclassTemplate’ and name.id.id=obj.id
> order by doc.title"
>
> List<java.lang.Object[]> results = (List<java.lang.Object[]>) (List)
> this.queryManager.createQuery(query, Query.XWQL).setWiki(“xwiki").execute();
>
> This gives me the name.value of the property of the object in the main
> wiki.
>
> What I need however is something like:
>
> String query = "select obj from XWikiDocument doc, BaseObject obj where
> doc.fullName=obj.name and obj.className=‘space.someclassClass’ and” +
>      "obj.className<>’space.someclassTemplate’ order by doc.title”
>
>

> I expect this to return a BaseObject. When displaying this
> (toXMLString()), it is however an empty object:
> <?xml version="1.0" encoding="UTF-8"?>
> <object>
> <name>space.somepage</name>
> <number>0</number>
> <className>space.someclassClass</className>
> <guid>3c145abe-b334-4801-a100-24c8ef2eea9f</guid>
> </object>
>

If you check
http://platform.xwiki.org/xwiki/bin/view/DevGuide/DatabaseSchema you'll see
that the object data is spread in multiple database tables. What you get is
only the information from the xwikiobjects table (that corresponds to
BaseObject from your query). That's why you need to join StringProperty (in
your first query) if you want the value of a string property from your
object. Since an object can have many properties, it's not convenient to
join all the tables for all the properties. You can instead select the page
full name and the object number, and then use the scripting API to access
the object from the corresponding document.

Hope this helps,
Marius


>
> There is no way (that I have tried) that would give me the object of class
> “xwiki:space.someclassClass” that contains the properties that I need (and
> get using the first query).
>
> I expect that it might have to do with the context but I’m not that
> familiar with it that I know how to do this.
>
> Can someone please shed some light on this?
>
> With kind regards,
>
> Peter Huisman
> _______________________________________________
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to