Ahh, right, sorry. Don't use getId(), use getDocumentId(). The result of a query is not actually the document, it is the document element of the document. The document element doesn't have an id.

You're right this is an issue because the Resource returned from the query can't be directly deleted. This was recently brought up the XML:DB API list too. I'm thinking resources need to be a little smarter then they are currently. The problem is that resources returned from a query always represent a node some place in a document, while those retrieved from a collection represent the document it self. This makes the resources retrieved from the query second class citizens because you can't directly delete them or modify them.

It seems that a resource should be smarter, such that it always knows how to modify or delete it self. For instance if you run a query that returns nodes deep in a document and delete all the results then those nodes should be removed from the document but the document it self still exists.
The same with modifications. So regardless of where you get a resource, and what it represents you can always perform any resource operations on it and have it be consistent.


Does this make sense? What are the reasons not to do this?

On the XML:DB list it was proposed that queries shouldn't return resources at all. I'm not sure that is necessary, but we do need to better detail the behavior of query results.

On Tuesday, January 22, 2002, at 10:27 AM, [EMAIL PROTECTED] wrote:



Kimbro, I found the problem.....

The Resources in the ResourceSet obtained from the XPathQueryService have
an id that is null...therefore, trying to remove the resource as obtained
from the ResourceSet fails.  This is the same code as before, with the
enhancement of the System.out.println in the testQuery() to show the
resource.getId().

Here is the output:

Running test: testQuery
1. [null]
--------------------------
<?xml version="1.0"?>
<highKey uniqueIdentifier="foo.com" value="1011719774551" xmlns:src="
http://www.dbxml.org/Query"; src:col="/db/root/ocs" src:key
="6701000a459e2954000000eb8f326dfa" />


-Kevin Ross



============================================
<snip>
============================================

    /**
     * Search the database.
     */
    public void testQuery() throws XMLDBException {

        String xpathQuery = "/[EMAIL PROTECTED] = 'foo.com']";
        ResourceSet resourceSet = getResourceSet(xpathQuery);
        ResourceIterator resourceSetIterator = resourceSet.getIterator();

        int i = 0;
        while (resourceSetIterator.hasMoreResources()) {
            Resource resource = resourceSetIterator.nextResource();
            System.out.println((++i) + ". [" + resource.getId() + "]
\n--------------------------\n" + (String) resource.getContent() + "\n\n"
);
        }
    }

    public ResourceSet getResourceSet(Collection collection, String
xpathQuery) throws XMLDBException {

        XPathQueryService xpathQueryService = (XPathQueryService)
collection.getService("XPathQueryService", "1.0");
        return xpathQueryService.query(xpathQuery);
    }

============================================
<snip>
============================================





Kimbro Staken
<[EMAIL PROTECTED] To: xindice-
[EMAIL PROTECTED]
group.com> cc:
Subject: Re: Problem removing
01/21/2002
02:36 PM
Please respond
to
xindice-users







It looks right, what's the problem you're seeing?

On Monday, January 21, 2002, at 12:22 PM, [EMAIL PROTECTED] wrote:


Hello all,

I am attempting to create a simplified test case to recreate the problems

I
am having with OutOfMemoryException, but I am having problem with
collection.remove(Resource) in my test case testRemoveAll().

Any ideas?


Kevin Ross



Kimbro Staken
XML Database Software, Consulting and Writing
http://www.xmldatabases.org/










Reply via email to