You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by "Mark J. Stang" <ma...@earthlink.net> on 2002/06/20 15:28:12 UTC

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(XPathQueryResolver.java:1003)
>         at
> org.apache.xindice.core.query.XPathQueryResolver$ResultSet.<init>(XPathQueryResolver.java:995)
>         at
> org.apache.xindice.core.query.XPathQueryResolver$XPathQuery.execute(XPathQueryResolver.java:247)
>         at
> org.apache.xindice.core.query.XPathQueryResolver.query(XPathQueryResolver.java: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(XUpdateQueryResolver.java:172)
>         at
> org.apache.xindice.core.xupdate.XUpdateQueryResolver.query(XUpdateQueryResolver.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(CollectionServant.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:750)
>         at
> org.openorb.net.ServerManagerImpl.serve_request(ServerManagerImpl.java:1467)
>         at
> org.openorb.net.ServerManagerImpl.thread_pool_main(ServerManagerImpl.java:1410)
>         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


Re: sudden errors while xupdate

Posted by Jens Kumpfmueller <je...@stud.uni-rostock.de>.
it's always the same set of queries (the whole story: i'm writing a 
jca-resource adapter.
To test the adapter i using junit and a stateful session bean.
TestSuite: 1. create a collection, 2. store document, 3. retrieve 
document, 4. query (xpath), 5. query (xupdate), 6. remove document, 7. 
remove collection

This suite returns sometimes with errors in query (xupdate) part.

The document is: (taken (like the xupdate expressions) from 
http://www.xmldatabases.org/projects/XUpdate-UseCases/)

<addresses>
   
   <address id= "1">
      <!--This is the users name-->
      <name>
         <first> John</first>
         <last> Smith</last>
      </name>      
      <city>Houston </city>
      <state>Texas </state>
      <country> United States</country>
      <phone type= "home">333-300-0300 </phone>
      <phone type= "work">333-500-9080 </phone>
      <note><![CDATA[This is a new user]]></note >
   </address>
   
</addresses>


Here are the "core"-xupdate query-strings used in query (xupdate):

      xupdate =   "<xupdate:insert-before 
select=\"/addresses/address[@id = 1]/name/last\" >" +
                  "  <xupdate:element 
name=\"middle\">Lennox</xupdate:element>" +
                  "</xupdate:insert-before>";

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

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

      xupdate =   "<xupdate:append select=\"/addresses/address[@id = 
1]/phone[@type='work']\" >" +
                  "  <xupdate:attribute 
name=\"extension\">223</xupdate:attribute>" +
                  "</xupdate:append>";

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

      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>";

>>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(XPathQueryResolver.java:1003)
>>        at
>>org.apache.xindice.core.query.XPathQueryResolver$ResultSet.<init>(XPathQueryResolver.java:995)
>>        at
>>org.apache.xindice.core.query.XPathQueryResolver$XPathQuery.execute(XPathQueryResolver.java:247)
>>        at
>>org.apache.xindice.core.query.XPathQueryResolver.query(XPathQueryResolver.java: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(XUpdateQueryResolver.java:172)
>>        at
>>org.apache.xindice.core.xupdate.XUpdateQueryResolver.query(XUpdateQueryResolver.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(CollectionServant.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:750)
>>        at
>>org.openorb.net.ServerManagerImpl.serve_request(ServerManagerImpl.java:1467)
>>        at
>>org.openorb.net.ServerManagerImpl.thread_pool_main(ServerManagerImpl.java:1410)
>>        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
>>


Meta Data RDBMS combined with XIndice

Posted by Alex McLintock <al...@OWAL.co.uk>.

Hi folks,


I'm pretty impressed with XIndice for retrieving XML docs for my Apache 
Cocoon based web app (even though I don't have dynamic updating of 
documents yet).
However I am not so impressed with the speed of metadata retrieval.

I'd like to cache such things as the documents' author, title, publisher, 
topic, date,  and so on in a relational database so that the relational 
database can do things like list all the authors, or list all the titles.

Surely this is a fairly common requirement - so is there a standard 
application or system for this?

Thanks

Alex McLintock




Openweb Analysts Ltd, London: Software For Complex Websites 
http://www.OWAL.co.uk/
Free Consultancy for London Companies thinking of Open Source Software.


Re: sudden errors while xupdate

Posted by Jens Kumpfmueller <je...@stud.uni-rostock.de>.
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/address[@id=1]";
         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/phone[@type='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/address[@id = 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/address[@id=1]");
      }
      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/address[@id 
= 1]/phone[@type='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/address[@id=1]");
      }
      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/address[@id = 
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/address[@id=1]");
      }
      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/address[@id = 
1]/phone[@type='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/address[@id=1]");
      }
      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/address[@id = 
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/address[@id=1]");
      }
      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/address[@id=2]");
      }
      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" <ma...@earthlink.net>
>To: <xi...@xml.apache.org>
>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
>>
>>
>