You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by "Vladimir R. Bossicard" <vl...@bossicard.com> on 2002/12/18 13:12:03 UTC

Embed driver: getId returns null... bug?

It's far less fancy than discovering how Xindice works or integrating it 
into the latest container server but I've finally decided -instead of -1 
everything- to help the users and  write an "embed driver tutorial". 
And fix bugs along the way (it looks like we still have a few).

With the following code

      String xpath_query = "//person[first='John']";
      XPathQueryService xpath = (XPathQueryService)
col.getService("XPathQueryService", "1.0");
      ResourceSet resultSet = xpath.query(xpath_query);

      ResourceIterator results = resultSet.getIterator();
      Resource res = results.nextResource();
      out.println("Result from the query:");
      out.println("   content: " + res.getContent());
      out.println("   id     : " + res.getId());

the output is

Result from the query:
     content: <person xmlns:src="http://xml.apache.org/xindice/Query"
src:col="/db/example"
src:key="00000000485bce48000000f2314ce5a7"><first>John</first><last>Doe</last><phone 

type="home">555-123-456</phone><phone
type="work">555-456-789</phone></person>
     id     : null

Well, getId() returns null.  I have almost no doubt that this is a bug 
but I am surprised the noone ever noticed it.

-Vladimir

-- 
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice




Re: Embed driver: getId returns null... bug?

Posted by James Bates <ja...@amplexor.com>.
On Wednesday 18 December 2002 15:54, Terry Rosenbaum wrote:
> The problem is that depending on the XPath,
> a query can return all or part of a document.
> Documents have a resource ID (the document ID)
> and as such can be retrieved (in their entirity)
> from the database using that ID. A part of
> a document has no ID. The part can only be
> retrieved using an XPath that selects the
> same part of the document. So, a query
> can return a resource, or something that
> is not really a resource. That is why a query
> result has no resource ID.
>
> -Terry
>

I'd agree with this point of view actually. It seems like a small
matter to ask people to use getDocumentId() which has consistent behaviour in 
this way.

Don't forget, even a query result which returns the "whole document" is not
necessarily the same resource as the original: it has some extra attributes, 
it may have been transformed (if some future query language will allow it).

Even in today's XPath, there's a difference between / and /* for example,
and /* can't really be said to be the whole result (It doesn't contain PI's or 
top-level comments).

James



Re: Embed driver: getId returns null... bug?

Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
But does it make sense for every user to implement the workaround (as I 
see it), or for the implementation to do it once?

I do see your point, I guess it's a toss up.

-Kevin

Terry Rosenbaum wrote:

> I think your suggested requirement places
> too great a burden on the implementation. The implementation
> would need to determine for each query whether or not
> what it is returning indeed has an ID. Am I returning
> a complete document or a fragment?
>
> I believe that the design is correct as-is. Hopefully the
> user will know whether or not her/his query returns
> a full document (in which case referring to the result as
> a resource with an ID makes sense and a call to getDocumentID()
> returns the desired ID). The burden is on the user here.
> It's always a simple burden for the user to cope with but perhaps
> a difficult one for the implementer.
>
> -Terry
>
> Kevin Ross wrote:
>
>> Agreed, but, since the ID is available at times, doesn't it make 
>> sense to populate it in that case? If I use the database, querying a 
>> list of resources with IDs (like getting a personList), it wouldn't 
>> be out of line to expect the Java API to behave as it would when you 
>> call Collection.getResource(id).
>>
>> Of course it is understood that if you query a resource without an 
>> id, there is no way to populate with one.  I believe that *this* is 
>> the execptional case where the getID() shoud be null.
>>
>> -Kevin
>>
>> Terry Rosenbaum wrote:
>>
>>> The problem is that depending on the XPath,
>>> a query can return all or part of a document.
>>> Documents have a resource ID (the document ID)
>>> and as such can be retrieved (in their entirity)
>>> from the database using that ID. A part of
>>> a document has no ID. The part can only be
>>> retrieved using an XPath that selects the
>>> same part of the document. So, a query
>>> can return a resource, or something that
>>> is not really a resource. That is why a query
>>> result has no resource ID.
>>>
>>> -Terry
>>>
>>> Kevin Ross wrote:
>>>
>>>> I reported this long ago, (as some others did too) on this list, 
>>>> but as you've figured out, the XML:DB spec mandated it.  I would 
>>>> appreciate it GREATLY if you would be willing to handle this 
>>>> inconsistency with those folks.
>>>>
>>>> After all, a Resource, no matter which way you get it, is still a 
>>>> Resource!  I think it should be populated if available...
>>>>
>>>> -Kevin
>>>>
>>>> Vladimir R. Bossicard wrote:
>>>>
>>>>>> "Returns the unique id for this Resource or null if the Resource 
>>>>>> is anonymous. The Resource will be anonymous if it is obtained as 
>>>>>> the result of a query."
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Thanks for the detailed explanation.  But why did I think that it 
>>>>> was our fault? :-)
>>>>>
>>>>>> I must confess I find this pretty strange, but I guess the XML:DB 
>>>>>> API guys know what they're doing?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> For example, the following code will not work:
>>>>>
>>>>>       String xpath_query = "//person[first='John']";
>>>>>       XPathQueryService xpath = (XPathQueryService)
>>>>> col.getService("XPathQueryService", "1.0");
>>>>>       ResourceSet resultSet = xpath.query(xpath_query);
>>>>>
>>>>>       ResourceIterator results = resultSet.getIterator();
>>>>>       Resource res = results.nextResource();
>>>>>
>>>>> --->  Resource res2 = col.getResource(res.getId());
>>>>> --->  col.removeResource(res2);
>>>>>
>>>>> which is very very strange.
>>>>>
>>>>> I'll send a mail to the XMLDB:API guys to know more about this issue.
>>>>>
>>>>> -Vladimir
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>



Re: Embed driver: getId returns null... bug?

Posted by Terry Rosenbaum <Te...@amicas.com>.
I think your suggested requirement places
too great a burden on the implementation. The implementation
would need to determine for each query whether or not
what it is returning indeed has an ID. Am I returning
a complete document or a fragment?

I believe that the design is correct as-is. Hopefully the
user will know whether or not her/his query returns
a full document (in which case referring to the result as
a resource with an ID makes sense and a call to getDocumentID()
returns the desired ID). The burden is on the user here.
It's always a simple burden for the user to cope with but perhaps
a difficult one for the implementer.

-Terry

Kevin Ross wrote:

> Agreed, but, since the ID is available at times, doesn't it make sense 
> to populate it in that case? 
> If I use the database, querying a list of resources with IDs (like 
> getting a personList), it wouldn't be out of line to expect the Java 
> API to behave as it would when you call Collection.getResource(id).
>
> Of course it is understood that if you query a resource without an id, 
> there is no way to populate with one.  I believe that *this* is the 
> execptional case where the getID() shoud be null.
>
> -Kevin
>
> Terry Rosenbaum wrote:
>
>> The problem is that depending on the XPath,
>> a query can return all or part of a document.
>> Documents have a resource ID (the document ID)
>> and as such can be retrieved (in their entirity)
>> from the database using that ID. A part of
>> a document has no ID. The part can only be
>> retrieved using an XPath that selects the
>> same part of the document. So, a query
>> can return a resource, or something that
>> is not really a resource. That is why a query
>> result has no resource ID.
>>
>> -Terry
>>
>> Kevin Ross wrote:
>>
>>> I reported this long ago, (as some others did too) on this list, but 
>>> as you've figured out, the XML:DB spec mandated it.  I would 
>>> appreciate it GREATLY if you would be willing to handle this 
>>> inconsistency with those folks.
>>>
>>> After all, a Resource, no matter which way you get it, is still a 
>>> Resource!  I think it should be populated if available...
>>>
>>> -Kevin
>>>
>>> Vladimir R. Bossicard wrote:
>>>
>>>>> "Returns the unique id for this Resource or null if the Resource 
>>>>> is anonymous. The Resource will be anonymous if it is obtained as 
>>>>> the result of a query."
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Thanks for the detailed explanation.  But why did I think that it 
>>>> was our fault? :-)
>>>>
>>>>> I must confess I find this pretty strange, but I guess the XML:DB 
>>>>> API guys know what they're doing?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> For example, the following code will not work:
>>>>
>>>>       String xpath_query = "//person[first='John']";
>>>>       XPathQueryService xpath = (XPathQueryService)
>>>> col.getService("XPathQueryService", "1.0");
>>>>       ResourceSet resultSet = xpath.query(xpath_query);
>>>>
>>>>       ResourceIterator results = resultSet.getIterator();
>>>>       Resource res = results.nextResource();
>>>>
>>>> --->  Resource res2 = col.getResource(res.getId());
>>>> --->  col.removeResource(res2);
>>>>
>>>> which is very very strange.
>>>>
>>>> I'll send a mail to the XMLDB:API guys to know more about this issue.
>>>>
>>>> -Vladimir
>>>>
>>>
>>>
>>
>>
>
>



Re: Embed driver: getId returns null... bug?

Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
Agreed, but, since the ID is available at times, doesn't it make sense 
to populate it in that case?  

If I use the database, querying a list of resources with IDs (like 
getting a personList), it wouldn't be out of line to expect the Java API 
to behave as it would when you call Collection.getResource(id).

Of course it is understood that if you query a resource without an id, 
there is no way to populate with one.  I believe that *this* is the 
execptional case where the getID() shoud be null.

-Kevin

Terry Rosenbaum wrote:

> The problem is that depending on the XPath,
> a query can return all or part of a document.
> Documents have a resource ID (the document ID)
> and as such can be retrieved (in their entirity)
> from the database using that ID. A part of
> a document has no ID. The part can only be
> retrieved using an XPath that selects the
> same part of the document. So, a query
> can return a resource, or something that
> is not really a resource. That is why a query
> result has no resource ID.
>
> -Terry
>
> Kevin Ross wrote:
>
>> I reported this long ago, (as some others did too) on this list, but 
>> as you've figured out, the XML:DB spec mandated it.  I would 
>> appreciate it GREATLY if you would be willing to handle this 
>> inconsistency with those folks.
>>
>> After all, a Resource, no matter which way you get it, is still a 
>> Resource!  I think it should be populated if available...
>>
>> -Kevin
>>
>> Vladimir R. Bossicard wrote:
>>
>>>> "Returns the unique id for this Resource or null if the Resource is 
>>>> anonymous. The Resource will be anonymous if it is obtained as the 
>>>> result of a query."
>>>
>>>
>>>
>>>
>>> Thanks for the detailed explanation.  But why did I think that it 
>>> was our fault? :-)
>>>
>>>> I must confess I find this pretty strange, but I guess the XML:DB 
>>>> API guys know what they're doing?
>>>
>>>
>>>
>>>
>>> For example, the following code will not work:
>>>
>>>       String xpath_query = "//person[first='John']";
>>>       XPathQueryService xpath = (XPathQueryService)
>>> col.getService("XPathQueryService", "1.0");
>>>       ResourceSet resultSet = xpath.query(xpath_query);
>>>
>>>       ResourceIterator results = resultSet.getIterator();
>>>       Resource res = results.nextResource();
>>>
>>> --->  Resource res2 = col.getResource(res.getId());
>>> --->  col.removeResource(res2);
>>>
>>> which is very very strange.
>>>
>>> I'll send a mail to the XMLDB:API guys to know more about this issue.
>>>
>>> -Vladimir
>>>
>>
>>
>
>



Re: Embed driver: getId returns null... bug?

Posted by James Bates <ja...@amplexor.com>.
On Wednesday 18 December 2002 17:11, Terry Rosenbaum wrote:
> Vladimir R. Bossicard wrote:
> > Very good explanation.  So now the next (and last) step will be to put
> > this into the documentation.
> >
> > Terry, thanks for volunteering. :-)
>
> Done.
>
> Attached is the updated guide-developer.xml file
> containing a new section below the section entitled
> "Querying with XPath". Can someone please check this in?
> I do not have Forrest installed so have not tested it.
>
> -Terry

The XML is fine; I've commited it.
James

Re: Embed driver: getId returns null... bug?

Posted by Terry Rosenbaum <Te...@amicas.com>.
Vladimir R. Bossicard wrote:

> Very good explanation.  So now the next (and last) step will be to put 
> this into the documentation.
>
> Terry, thanks for volunteering. :-) 

Done.

Attached is the updated guide-developer.xml file
containing a new section below the section entitled
"Querying with XPath". Can someone please check this in?
I do not have Forrest installed so have not tested it.

-Terry


Re: Embed driver: getId returns null... bug?

Posted by "Vladimir R. Bossicard" <vl...@apache.org>.
> The problem is that depending on the XPath,
> a query can return all or part of a document.
> Documents have a resource ID (the document ID)
> and as such can be retrieved (in their entirity)
> from the database using that ID. A part of
> a document has no ID. The part can only be
> retrieved using an XPath that selects the
> same part of the document. So, a query
> can return a resource, or something that
> is not really a resource. That is why a query
> result has no resource ID.

Very good explanation.  So now the next (and last) step will be to put 
this into the documentation.

Terry, thanks for volunteering. :-)

-Vladimir

-- 
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice


Re: Embed driver: getId returns null... bug?

Posted by Terry Rosenbaum <Te...@amicas.com>.
The problem is that depending on the XPath,
a query can return all or part of a document.
Documents have a resource ID (the document ID)
and as such can be retrieved (in their entirity)
from the database using that ID. A part of
a document has no ID. The part can only be
retrieved using an XPath that selects the
same part of the document. So, a query
can return a resource, or something that
is not really a resource. That is why a query
result has no resource ID.

-Terry

Kevin Ross wrote:

> I reported this long ago, (as some others did too) on this list, but 
> as you've figured out, the XML:DB spec mandated it.  I would 
> appreciate it GREATLY if you would be willing to handle this 
> inconsistency with those folks.
>
> After all, a Resource, no matter which way you get it, is still a 
> Resource!  I think it should be populated if available...
>
> -Kevin
>
> Vladimir R. Bossicard wrote:
>
>>> "Returns the unique id for this Resource or null if the Resource is 
>>> anonymous. The Resource will be anonymous if it is obtained as the 
>>> result of a query."
>>
>>
>>
>> Thanks for the detailed explanation.  But why did I think that it was 
>> our fault? :-)
>>
>>> I must confess I find this pretty strange, but I guess the XML:DB 
>>> API guys know what they're doing?
>>
>>
>>
>> For example, the following code will not work:
>>
>>       String xpath_query = "//person[first='John']";
>>       XPathQueryService xpath = (XPathQueryService)
>> col.getService("XPathQueryService", "1.0");
>>       ResourceSet resultSet = xpath.query(xpath_query);
>>
>>       ResourceIterator results = resultSet.getIterator();
>>       Resource res = results.nextResource();
>>
>> --->  Resource res2 = col.getResource(res.getId());
>> --->  col.removeResource(res2);
>>
>> which is very very strange.
>>
>> I'll send a mail to the XMLDB:API guys to know more about this issue.
>>
>> -Vladimir
>>
>
>



Re: Embed driver: getId returns null... bug?

Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
Thanks Vladimir, you're a great help.

I didn't try to solve it because I found it long ago before I was a 
committer.  Since I use framework code for everything, I have already 
worked around it in one place, and I've forgotten entirely about it.

Sorry to inconvenience you.

-Kevin

Vladimir R. Bossicard wrote:

>> I reported this long ago, (as some others did too) on this list, but 
>> as you've figured out, the XML:DB spec mandated it.  I would 
>> appreciate it GREATLY if you would be willing to handle this 
>> inconsistency with those folks.
>
>
> Why try to solve a problem? Vladimir will take care of it sooner or 
> later...
>
> -Vladimir
>



Re: Embed driver: getId returns null... bug?

Posted by "Vladimir R. Bossicard" <vl...@apache.org>.
> I reported this long ago, (as some others did too) on this list, but as 
> you've figured out, the XML:DB spec mandated it.  I would appreciate it 
> GREATLY if you would be willing to handle this inconsistency with those 
> folks.

Why try to solve a problem? Vladimir will take care of it sooner or later...

-Vladimir

-- 
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice


Re: Embed driver: getId returns null... bug?

Posted by Kevin Ross <Ke...@iVerticalLeap.com>.
I reported this long ago, (as some others did too) on this list, but as 
you've figured out, the XML:DB spec mandated it.  I would appreciate it 
GREATLY if you would be willing to handle this inconsistency with those 
folks.

After all, a Resource, no matter which way you get it, is still a 
Resource!  I think it should be populated if available...

-Kevin

Vladimir R. Bossicard wrote:

>> "Returns the unique id for this Resource or null if the Resource is 
>> anonymous. The Resource will be anonymous if it is obtained as the 
>> result of a query."
>
>
> Thanks for the detailed explanation.  But why did I think that it was 
> our fault? :-)
>
>> I must confess I find this pretty strange, but I guess the XML:DB API 
>> guys know what they're doing?
>
>
> For example, the following code will not work:
>
>       String xpath_query = "//person[first='John']";
>       XPathQueryService xpath = (XPathQueryService)
> col.getService("XPathQueryService", "1.0");
>       ResourceSet resultSet = xpath.query(xpath_query);
>
>       ResourceIterator results = resultSet.getIterator();
>       Resource res = results.nextResource();
>
> --->  Resource res2 = col.getResource(res.getId());
> --->  col.removeResource(res2);
>
> which is very very strange.
>
> I'll send a mail to the XMLDB:API guys to know more about this issue.
>
> -Vladimir
>



Re: Embed driver: getId returns null... bug?

Posted by "Vladimir R. Bossicard" <vl...@apache.org>.
> "Returns the unique id for this Resource or null if the Resource is anonymous. 
> The Resource will be anonymous if it is obtained as the result of a query."

Thanks for the detailed explanation.  But why did I think that it was 
our fault? :-)

> I must confess I find this pretty strange, but I guess the XML:DB API guys 
> know what they're doing?

For example, the following code will not work:

       String xpath_query = "//person[first='John']";
       XPathQueryService xpath = (XPathQueryService)
col.getService("XPathQueryService", "1.0");
       ResourceSet resultSet = xpath.query(xpath_query);

       ResourceIterator results = resultSet.getIterator();
       Resource res = results.nextResource();

--->  Resource res2 = col.getResource(res.getId());
--->  col.removeResource(res2);

which is very very strange.

I'll send a mail to the XMLDB:API guys to know more about this issue.

-Vladimir

-- 
Vladimir R. Bossicard
Apache Xindice - http://xml.apache.org/xindice


Re: Embed driver: getId returns null... bug?

Posted by James Bates <ja...@amplexor.com>.
On Wednesday 18 December 2002 14:31, James Bates wrote:
> On Wednesday 18 December 2002 13:12, Vladimir R. Bossicard wrote:
> > It's far less fancy than discovering how Xindice works or integrating it
> > into the latest container server but I've finally decided -instead of -1
> > everything- to help the users and  write an "embed driver tutorial".
> > And fix bugs along the way (it looks like we still have a few).
> >
> > With the following code
> >
> >       String xpath_query = "//person[first='John']";
> >       XPathQueryService xpath = (XPathQueryService)
> > col.getService("XPathQueryService", "1.0");
> >       ResourceSet resultSet = xpath.query(xpath_query);
> >
> >       ResourceIterator results = resultSet.getIterator();
> >       Resource res = results.nextResource();
> >       out.println("Result from the query:");
> >       out.println("   content: " + res.getContent());
> >       out.println("   id     : " + res.getId());
> >
> > the output is
> >
> > Result from the query:
> >      content: <person xmlns:src="http://xml.apache.org/xindice/Query"
> > src:col="/db/example"
> > src:key="00000000485bce48000000f2314ce5a7"><first>John</first><last>Doe</
> >la st><phone
> >
> > type="home">555-123-456</phone><phone
> > type="work">555-456-789</phone></person>
> >      id     : null
> >
> > Well, getId() returns null.  I have almost no doubt that this is a bug
> > but I am surprised the noone ever noticed it.
>
> The problem is in
> org.apache.client.xmldb.embed.CollectionImpl.query(), line 457. For some
> reason XMLResourceImpl's make a distinction between "documentId" and simply
> "Id". The above line sets id to NULL and documentId to the src:key
> attribute of the result.
>
> Exactly the same occurs with the XML-RPC driver in
> org.apache.client.xmldb.xmlrpc.CollectionImpl.query(), line 559.
>
> We should try and find out why there are separate id's and documentId's...
>

From the XML:DB API JavaDoc of Resource.getId().
(http://www.xmldb.org/xapi/api/org/xmldb/api/base/Resource.html#getId()):

"Returns the unique id for this Resource or null if the Resource is anonymous. 
The Resource will be anonymous if it is obtained as the result of a query."

According to the API, the client code should therefor use getDocumentId(), 
which will have the correct value.



I must confess I find this pretty strange, but I guess the XML:DB API guys 
know what they're doing?


James

Re: Embed driver: getId returns null... bug?

Posted by Kimbro Staken <ks...@xmldatabases.org>.
One other point on this. Resources will always have getDocumentID set.  
So if you consistently want to retrieve the ID for any document then  
this is the way to do it. Just remember it's the id for the containing  
document, not the resource itself. A resource retrieved from a query  
simply doesn't have an ID so getID has nothing to return.

You guys are right, there is a problem here but it's deeper then just  
getID/getDocumentID. It's really a problem with the way resources are  
used in general.

On Wednesday, December 18, 2002, at 03:15  PM, Kimbro Staken wrote:

> This isn't a bug, it's how it was designed. getID returns the ID only  
> on resources that are actually documents, getDocumentID always returns  
> the id for the document that contains returned resource. Basically if  
> a node (i.e. resource) is retrieved from deep within the document then  
> getID will return null, because that resource does not have an id.  
> However, that resource is part of a document so if you do want to find  
> out what document it is in you can call getDocumentID. If the  
> retrieved resource is an actual document instance (i.e. you used  
> Collection.getDocument() to get it) then both getID and getDocumentID  
> will return the same thing. It's confusing, I know.
>
> On Wednesday, December 18, 2002, at 06:31  AM, James Bates wrote:
>
>> On Wednesday 18 December 2002 13:12, Vladimir R. Bossicard wrote:
>>> It's far less fancy than discovering how Xindice works or  
>>> integrating it
>>> into the latest container server but I've finally decided -instead  
>>> of -1
>>> everything- to help the users and  write an "embed driver tutorial".
>>> And fix bugs along the way (it looks like we still have a few).
>>>
>>> With the following code
>>>
>>>       String xpath_query = "//person[first='John']";
>>>       XPathQueryService xpath = (XPathQueryService)
>>> col.getService("XPathQueryService", "1.0");
>>>       ResourceSet resultSet = xpath.query(xpath_query);
>>>
>>>       ResourceIterator results = resultSet.getIterator();
>>>       Resource res = results.nextResource();
>>>       out.println("Result from the query:");
>>>       out.println("   content: " + res.getContent());
>>>       out.println("   id     : " + res.getId());
>>>
>>> the output is
>>>
>>> Result from the query:
>>>      content: <person xmlns:src="http://xml.apache.org/xindice/Query"
>>> src:col="/db/example"
>>> src:key="00000000485bce48000000f2314ce5a7"><first>John</ 
>>> first><last>Doe</la
>>> st><phone
>>>
>>> type="home">555-123-456</phone><phone
>>> type="work">555-456-789</phone></person>
>>>      id     : null
>>>
>>> Well, getId() returns null.  I have almost no doubt that this is a  
>>> bug
>>> but I am surprised the noone ever noticed it.
>>>
>>
>> The problem is in
>> org.apache.client.xmldb.embed.CollectionImpl.query(), line 457. For  
>> some
>> reason XMLResourceImpl's make a distinction between "documentId" and  
>> simply
>> "Id". The above line sets id to NULL and documentId to the src:key  
>> attribute
>> of the result.
>>
>> Exactly the same occurs with the XML-RPC driver in
>> org.apache.client.xmldb.xmlrpc.CollectionImpl.query(), line 559.
>>
>> We should try and find out why there are separate id's and  
>> documentId's...
>>
>> James
>>
>>
>>
>>> -Vladimir
>>
>>
> Kimbro Staken
> Java and XML Software, Consulting and Writing  
> http://www.xmldatabases.org/
> Apache Xindice native XML database http://xml.apache.org/xindice
> XML:DB Initiative http://www.xmldb.org
>
>
Kimbro Staken
Java and XML Software, Consulting and Writing  
http://www.xmldatabases.org/
Apache Xindice native XML database http://xml.apache.org/xindice
XML:DB Initiative http://www.xmldb.org


Re: Embed driver: getId returns null... bug?

Posted by Kimbro Staken <ks...@xmldatabases.org>.
This isn't a bug, it's how it was designed. getID returns the ID only  
on resources that are actually documents, getDocumentID always returns  
the id for the document that contains returned resource. Basically if a  
node (i.e. resource) is retrieved from deep within the document then  
getID will return null, because that resource does not have an id.  
However, that resource is part of a document so if you do want to find  
out what document it is in you can call getDocumentID. If the retrieved  
resource is an actual document instance (i.e. you used  
Collection.getDocument() to get it) then both getID and getDocumentID  
will return the same thing. It's confusing, I know.

On Wednesday, December 18, 2002, at 06:31  AM, James Bates wrote:

> On Wednesday 18 December 2002 13:12, Vladimir R. Bossicard wrote:
>> It's far less fancy than discovering how Xindice works or integrating  
>> it
>> into the latest container server but I've finally decided -instead of  
>> -1
>> everything- to help the users and  write an "embed driver tutorial".
>> And fix bugs along the way (it looks like we still have a few).
>>
>> With the following code
>>
>>       String xpath_query = "//person[first='John']";
>>       XPathQueryService xpath = (XPathQueryService)
>> col.getService("XPathQueryService", "1.0");
>>       ResourceSet resultSet = xpath.query(xpath_query);
>>
>>       ResourceIterator results = resultSet.getIterator();
>>       Resource res = results.nextResource();
>>       out.println("Result from the query:");
>>       out.println("   content: " + res.getContent());
>>       out.println("   id     : " + res.getId());
>>
>> the output is
>>
>> Result from the query:
>>      content: <person xmlns:src="http://xml.apache.org/xindice/Query"
>> src:col="/db/example"
>> src:key="00000000485bce48000000f2314ce5a7"><first>John</ 
>> first><last>Doe</la
>> st><phone
>>
>> type="home">555-123-456</phone><phone
>> type="work">555-456-789</phone></person>
>>      id     : null
>>
>> Well, getId() returns null.  I have almost no doubt that this is a bug
>> but I am surprised the noone ever noticed it.
>>
>
> The problem is in
> org.apache.client.xmldb.embed.CollectionImpl.query(), line 457. For  
> some
> reason XMLResourceImpl's make a distinction between "documentId" and  
> simply
> "Id". The above line sets id to NULL and documentId to the src:key  
> attribute
> of the result.
>
> Exactly the same occurs with the XML-RPC driver in
> org.apache.client.xmldb.xmlrpc.CollectionImpl.query(), line 559.
>
> We should try and find out why there are separate id's and  
> documentId's...
>
> James
>
>
>
>> -Vladimir
>
>
Kimbro Staken
Java and XML Software, Consulting and Writing  
http://www.xmldatabases.org/
Apache Xindice native XML database http://xml.apache.org/xindice
XML:DB Initiative http://www.xmldb.org


Re: Embed driver: getId returns null... bug?

Posted by James Bates <ja...@amplexor.com>.
On Wednesday 18 December 2002 13:12, Vladimir R. Bossicard wrote:
> It's far less fancy than discovering how Xindice works or integrating it
> into the latest container server but I've finally decided -instead of -1
> everything- to help the users and  write an "embed driver tutorial".
> And fix bugs along the way (it looks like we still have a few).
>
> With the following code
>
>       String xpath_query = "//person[first='John']";
>       XPathQueryService xpath = (XPathQueryService)
> col.getService("XPathQueryService", "1.0");
>       ResourceSet resultSet = xpath.query(xpath_query);
>
>       ResourceIterator results = resultSet.getIterator();
>       Resource res = results.nextResource();
>       out.println("Result from the query:");
>       out.println("   content: " + res.getContent());
>       out.println("   id     : " + res.getId());
>
> the output is
>
> Result from the query:
>      content: <person xmlns:src="http://xml.apache.org/xindice/Query"
> src:col="/db/example"
> src:key="00000000485bce48000000f2314ce5a7"><first>John</first><last>Doe</la
>st><phone
>
> type="home">555-123-456</phone><phone
> type="work">555-456-789</phone></person>
>      id     : null
>
> Well, getId() returns null.  I have almost no doubt that this is a bug
> but I am surprised the noone ever noticed it.
>

The problem is in 
org.apache.client.xmldb.embed.CollectionImpl.query(), line 457. For some 
reason XMLResourceImpl's make a distinction between "documentId" and simply 
"Id". The above line sets id to NULL and documentId to the src:key attribute 
of the result.

Exactly the same occurs with the XML-RPC driver in
org.apache.client.xmldb.xmlrpc.CollectionImpl.query(), line 559.

We should try and find out why there are separate id's and documentId's...

James



> -Vladimir