hm... to exclude any other possible errors i excluded my methods from resource adapter and put them into JUNIT-test cases. they use the xmldb api to access xindice.
storing, retrieving and deleting works always fine, but the qerry and update tests fail very often, but sometimes the succeeded.


junit tests:

  public void testQuery()
  {
     try
     {
        String xpath = null;
        String[] result = null;

        // Suche nach allen Addressen
        xpath = "/addresses";
        result = this.query(xpath);
        assertTrue("no results found ",result.length > 0);

        // Suche nach Adresse mit id 1
        xpath = "/addresses/[EMAIL PROTECTED]";
        result = this.query(xpath);

        for(int i = 0; i < result.length; i++)
        {
           Document found = null;

           try
           {
              found = DOMParser.toDocument(result[i]);
              assertNotNull("dom document is null",found);
           }
           catch (Exception exc)
           {
              fail("could not create dom document from found xml string");
           }

assertEquals("id",
found.getFirstChild().getAttributes().getNamedItem("id").getNodeValue(),
"1");
}


        // Suche nach Element
        xpath = "/addresses/address/phone";
        result = this.query(xpath);
        System.out.println("xpath = " + xpath);
        System.out.println("result length: " + result.length);
        assertEquals("3. query",2, result.length);

        for(int i = 0; i < result.length; i++)
        {
           System.out.println("result: " + result[i]);
        }

        // Suche nach Element mit Attribut
        xpath = "/addresses/address/[EMAIL PROTECTED]'home']";
        result = this.query(xpath);
        System.out.println("xpath = " + xpath);
        System.out.println("result length: " + result.length);
        assertEquals("4. query", result.length,1);

        for(int i = 0; i < result.length; i++)
        {
           System.out.println("result: " + result[i]);
        }


} catch (ResourceException exc) { fail("could not query db\r\n" + exc.toString()); } }

public void testXUpdate()
{
long count = 0;
String xupdate = null;
String[] result = null;
String prefix =
"<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\";>";
String suffix =
"</xupdate:modifications>";


// 1. Insert Element Before
xupdate = "<xupdate:insert-before select=\"/addresses/[EMAIL PROTECTED] = 1]/name/last\" >" +
" <xupdate:element name=\"middle\">Lennox</xupdate:element>" +
"</xupdate:insert-before>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }

     // 2. Insert Element After

xupdate = "<xupdate:insert-after select=\"/addresses/[EMAIL PROTECTED] = 1]/[EMAIL PROTECTED]'home']\">" +
" <xupdate:element name=\"phone\"><xupdate:attribute name=\"type\">cell</xupdate:attribute>490-494-4904</xupdate:element>" +
"</xupdate:insert-after>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        System.out.println("xupdate 2");
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }

     // 3. Append Element

xupdate = "<xupdate:append select=\"/addresses/[EMAIL PROTECTED] = 1]\" >" +
" <xupdate:element name=\"zip\">90200</xupdate:element>" +
"</xupdate:append>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }

     // 4.Insert attribute

xupdate = "<xupdate:append select=\"/addresses/[EMAIL PROTECTED] = 1]/[EMAIL PROTECTED]'work']\" >" +
" <xupdate:attribute name=\"extension\">223</xupdate:attribute>" +
"</xupdate:append>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }

     // 5.Insert Text Content

xupdate = "<xupdate:append select=\"/addresses/[EMAIL PROTECTED] = 1]/country\" >" +
" <xupdate:text> of America</xupdate:text>" +
"</xupdate:append>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }

     // 6. Insert XML Block

xupdate = "<xupdate:append select=\"/addresses\" >" +
" <xupdate:element name=\"address\">" +
" <xupdate:attribute name=\"id\">2</xupdate:attribute>" +
" <name>" +
" <first>Susan</first>" +
" <last>Long</last>" +
" </name>" +
" <city>Tucson</city>" +
" <state>Arizona</state>" +
" <country>United States</country>" +
" <phone type=\"home\">430-304-3040</phone>" +
" </xupdate:element>" +
"</xupdate:append>";


     try
     {
        count = this.xupdate(id,prefix + xupdate + suffix);
        assertEquals("updated nodes",1,count);
        result = this.query("/addresses/[EMAIL PROTECTED]");
     }
     catch (ResourceException exc)
     {
        fail("could not access db\r\n" + exc.toString());
     }

     for(int i = 0; i < result.length; i++)
     {
        System.out.println(i + ". result: " + result[i]);
     }
  }
<========

the query and xupdate methods to test are here:

<========
private String[] query(String xPathExpr)
throws ResourceException
{
try
{
// this.con holds a org.xmldb.api.base.Collection
XPathQueryService service =
(XPathQueryService) this.con.getService("XPathQueryService", "1.0");


        ResourceSet resultSet = service.query(xPathExpr);

        LinkedList returnList = new LinkedList();
        ResourceIterator results = resultSet.getIterator();

        while (results.hasMoreResources())
        {
           Resource res = results.nextResource();
            returnList.add((String) res.getContent());
         }

return (String[]) returnList.toArray(new String[]{});
}
catch (XMLDBException e)
{
ResourceException exception = new ResourceException("XML:DB Exception occured " + e.errorCode);
exception.setLinkedException(e);
throw exception;
}
}


private long xupdate(String id, String xUpdateExpr)
throws ResourceException
{
try
{
// this.con holds a org.xmldb.api.base.Collection
XUpdateQueryService service =
(XUpdateQueryService) this.con.getService("XUpdateQueryService", "1.0");


return con
}
catch (XMLDBException exc)
{
ResourceException exception = new ResourceException("XML:DB Excpetion occured " + exc.errorCode);
exception.setLinkedException(exc);
throw exception;
}
}
<========


the errormessage thrown by xindice-server is the same as posted before (see below).

Any idea how to solve this? any fixes available?

greetings  jens

Jeff Greif wrote:

From the stack trace, it appears that the XUpdate has found some documents
to modify, and breaks trying to retrieve them to carry out the
modifications, owing to some failure to retrieve from the collection's
document cache.

Just looking at the stack trace and a little source code, I would guess
there is a bug in Xindice, probably in the DocumentCache implementation, but
possibly higher up in the XPathQueryResolver.  My guess is that the
org.apache.xindice.core.DocumentCache.CacheKey.equals needs to test for null
before trying to extract parts of the two objects being compared, especially
since the DocumentCache uses a WeakHashMap from which the garbage collector
may delete keys at arbitrary times.  This may explain the intermittency of
the appearance of the bug.

I don't know enough about WeakHashMaps to be authoritative, but the class
documentation describes them as best suited for keys that are immutable and
can be compared using ==.  This is not the way that class is being used in
DocumentCache, but that in itself doesn't mean that it is being misused,
just that the usage should be checked.

Hope this proves helpful and not misleading.

Jeff
----- Original Message -----
From: "Mark J. Stang" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Thursday, June 20, 2002 6:28 AM
Subject: Re: sudden errors while xupdate


Is it the same query always?   When it fails is the query different.
Sounds like the XPath part of your XUpdate is failing...

Does the query work sometimes?

Can you provide the query and the document so the list can look at it?

thanks,

Mark

Jens Kumpfmueller wrote:

Hi *,

finally i managed it to start the xindice-server. When i'm trying to do
some xupdates (mentioned on
http://www.xmldatabases.org/projects/XUpdate-UseCases/ ), sometimes
everything is ok, all xupdates are done. but sometimes i got this error:

java.lang.NullPointerException
       at

org.apache.xindice.core.DocumentCache$CacheKey.equals(DocumentCache.java:171
)

       at java.util.WeakHashMap.eq(WeakHashMap.java:256)
       at java.util.WeakHashMap.get(WeakHashMap.java:348)
       at
org.apache.xindice.core.DocumentCache.getDocument(DocumentCache.java:79)
       at
org.apache.xindice.core.Collection.getDocument(Collection.java:711)
       at

org.apache.xindice.core.query.XPathQueryResolver$ResultSet.prepareNextNode(X
PathQueryResolver.java:1003)

       at

org.apache.xindice.core.query.XPathQueryResolver$ResultSet.<init>(XPathQuery
Resolver.java:995)

       at

org.apache.xindice.core.query.XPathQueryResolver$XPathQuery.execute(XPathQue
ryResolver.java:247)

       at

org.apache.xindice.core.query.XPathQueryResolver.query(XPathQueryResolver.ja
va:151)

       at
org.apache.xindice.core.query.QueryEngine.query(QueryEngine.java:147)
       at
org.apache.xindice.core.Collection.queryCollection(Collection.java:847)
       at

org.apache.xindice.core.xupdate.XUpdateImpl.execute(XUpdateImpl.java:185)

       at

org.apache.xindice.core.xupdate.XUpdateQueryResolver$XUpdateQuery.execute(XU
pdateQueryResolver.java:172)

       at

org.apache.xindice.core.xupdate.XUpdateQueryResolver.query(XUpdateQueryResol
ver.java:106)

       at
org.apache.xindice.core.query.QueryEngine.query(QueryEngine.java:147)
       at
org.apache.xindice.core.Collection.queryCollection(Collection.java:847)
       at

org.apache.xindice.client.corba.CollectionServant.queryCollection(Collection
Servant.java:424)

       at

org.apache.xindice.client.corba.db.CollectionPOA._invoke(CollectionPOA.java:
332)

       at org.openorb.adapter.poa.POA.dispatch(POA.java:975)
       at

org.openorb.net.AbstractServerRequest.dispatch(AbstractServerRequest.java:75
0)

       at

org.openorb.net.ServerManagerImpl.serve_request(ServerManagerImpl.java:1467)

       at

org.openorb.net.ServerManagerImpl.thread_pool_main(ServerManagerImpl.java:14
10)

       at
org.openorb.net.ServerManagerImpl.access$200(ServerManagerImpl.java:77)
       at

org.openorb.net.ServerManagerImpl$PoolThread.run(ServerManagerImpl.java:1557
)

i'm using jdk1.4, linux suse 8.0 xindice birdday 1.0 (precompiled)

thx in advance

jens

--
Mark J Stang
Software Architect
Cybershop Systems







Reply via email to