Author: vgritsenko
Date: Tue Nov 7 20:20:47 2006
New Revision: 472384
URL: http://svn.apache.org/viewvc?view=rev&rev=472384
Log:
<action dev="VG" type="fix" fixes-bug="31974">
Fix exception executing xpath query in collections with
mixed (XML and binary) content.
</action>
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java
xml/xindice/trunk/status.xml
Modified:
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java?view=diff&rev=472384&r1=472383&r2=472384
==============================================================================
---
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
(original)
+++
xml/xindice/trunk/java/src/org/apache/xindice/core/query/XPathQueryResolver.java
Tue Nov 7 20:20:47 2006
@@ -18,17 +18,6 @@
package org.apache.xindice.core.query;
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.SourceLocator;
-import javax.xml.transform.TransformerException;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.xindice.core.Collection;
@@ -57,9 +46,9 @@
import org.apache.xindice.xml.NamespaceMap;
import org.apache.xindice.xml.SymbolTable;
import org.apache.xindice.xml.dom.DBDocument;
+import org.apache.xindice.xml.dom.DBNode;
import org.apache.xindice.xml.dom.DocumentImpl;
import org.apache.xindice.xml.dom.TextImpl;
-import org.apache.xindice.xml.dom.DBNode;
import org.apache.xml.utils.DefaultErrorHandler;
import org.apache.xml.utils.PrefixResolver;
import org.apache.xml.utils.PrefixResolverDefault;
@@ -74,6 +63,7 @@
import org.apache.xpath.objects.XNumber;
import org.apache.xpath.objects.XObject;
import org.apache.xpath.objects.XString;
+
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -82,6 +72,17 @@
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.SourceLocator;
+import javax.xml.transform.TransformerException;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
/**
* XPathQueryResolver
*
@@ -1236,10 +1237,13 @@
while (keyPos < keySet.length) {
final Key key = keySet[keyPos++];
- final DBDocument d = (DBDocument) context.getDocument(key);
- if (d == null) {
+
+ Object entry = context.getEntry(key);
+ if (!(entry instanceof DBDocument)) {
continue;
}
+
+ DBDocument d = (DBDocument) entry;
final Node n = d.getDocumentElement();
if (n == null) {
Modified:
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java?view=diff&rev=472384&r1=472383&r2=472384
==============================================================================
---
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
(original)
+++
xml/xindice/trunk/java/tests/src/org/apache/xindice/core/CollectionTest.java
Tue Nov 7 20:20:47 2006
@@ -18,6 +18,8 @@
package org.apache.xindice.core;
+import org.apache.xindice.core.data.NodeSet;
+import org.apache.xindice.core.query.XPathQueryResolver;
import org.apache.xindice.util.Configuration;
import org.apache.xindice.xml.TextWriter;
import org.apache.xindice.xml.dom.DOMParser;
@@ -34,12 +36,15 @@
*/
public class CollectionTest extends TestCase {
- private Database db;
- private Collection collection;
+ private static final String XML = "<test string='true'>This is a test
document</test>";
- public CollectionTest(String name) {
+ private Database db;
+ private Collection collection;
+
+
+ public CollectionTest(String name) {
super(name);
- }
+ }
public void setUp() throws Exception {
String name = getClass().getName();
@@ -53,48 +58,85 @@
));
}
- public void tearDown() throws Exception {
- db.dropCollection(collection);
+ public void tearDown() throws Exception {
+ db.dropCollection(collection);
db.close();
- }
+ }
- /**
- * Tests insertBinary, getBinary, remove
- */
- public void testBinary() throws Exception {
+ private byte[] generateBinary() {
byte[] in = new byte[256];
for (int i = 0; i < in.length; i++) {
in[i] = (byte) (Math.random() * 256);
}
+ return in;
+ }
+
+ /**
+ * Tests insertBinary, getBinary, remove
+ */
+ public void testBinary() throws Exception {
+ byte[] in = generateBinary();
- collection.insertBinary("binary", in);
+ collection.insertBinary("binary", in);
byte[] out = collection.getBinary("binary");
- assertNotNull("Binary must be in there", out);
- assertEquals("The size of the found and saved binary should be
the same", in.length, out.length);
- for (int i = 0; i < in.length; ++i) {
- assertEquals("The resources differ in byte " + i,
in[i], out[i]);
- }
+ assertNotNull("Binary must be in there", out);
+ assertEquals("The size of the found and saved binary should be the
same", in.length, out.length);
+ for (int i = 0; i < in.length; ++i) {
+ assertEquals("The resources differ in byte " + i, in[i], out[i]);
+ }
collection.remove("binary");
out = collection.getBinary("binary");
assertNull("Binary should have been removed", out);
- }
+ }
/**
* Tests insertDocument, getDocument, remove
*/
- public void testDocument() throws Exception {
+ public void testDocument() throws Exception {
Document in = collection.getConfig().getElement().getOwnerDocument();
String inStr = TextWriter.toString(in);
- collection.insertDocument("document", in);
+ collection.insertDocument("document", in);
Document out = collection.getDocument("document");
assertNotNull("Document must be in there", out);
String outStr = TextWriter.toString(out);
- assertEquals("Documents do not match", inStr, outStr);
+ assertEquals("Documents do not match", inStr, outStr);
collection.remove("document");
out = collection.getDocument("document");
assertNull("Document should have been removed", out);
- }
+ }
+
+ /**
+ * Test querying of mixed content (XML and binary) collection
+ */
+ public void testMixedContent() throws Exception {
+ Document document = DOMParser.toDocument(XML);
+ byte[] binary = generateBinary();
+
+ collection.insertDocument("document", document);
+ collection.insertBinary("binary", binary);
+
+ XPathQueryResolver service = new XPathQueryResolver();
+ NodeSet resultSet = service.query(collection, "/test", null, null);
+
+ int resultCount = 0;
+ while (resultSet.hasMoreNodes()) {
+ resultSet.getNextNode();
+ resultCount++;
+ }
+
+ assertEquals(1, resultCount);
+ }
+
+// FIXME Define semantics of document cache, and write tests for it
+// public void testDocumentCache() throws Exception {
+// Document in = collection.getConfig().getElement().getOwnerDocument();
+// collection.insertDocument("document", in);
+//
+// Document out1 = collection.getDocument("document");
+// Document out2 = collection.getDocument("document");
+// assertTrue(out1 == out2);
+// }
}
Modified:
xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java?view=diff&rev=472384&r1=472383&r2=472384
==============================================================================
---
xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java
(original)
+++
xml/xindice/trunk/java/tests/src/org/apache/xindice/integration/client/services/IndexedSearchTest.java
Tue Nov 7 20:20:47 2006
@@ -87,7 +87,7 @@
}
/**
- * Creates 104 test documents and inserts them into the test Collection.
+ * Creates 250 test documents and inserts them into the test Collection.
*/
private void createTestDocs() throws Exception {
for (int anIndex = 0; anIndex < 250; ++anIndex) {
Modified: xml/xindice/trunk/status.xml
URL:
http://svn.apache.org/viewvc/xml/xindice/trunk/status.xml?view=diff&rev=472384&r1=472383&r2=472384
==============================================================================
--- xml/xindice/trunk/status.xml (original)
+++ xml/xindice/trunk/status.xml Tue Nov 7 20:20:47 2006
@@ -74,6 +74,10 @@
<changes>
<release version="1.1b5-dev" date="Oct 27 2006">
+ <action dev="VG" type="fix" fixes-bug="31974">
+ Fix exception executing xpath query in collections with
+ mixed (XML and binary) content.
+ </action>
<action dev="VG" type="fix" fixes-bug="23571">
Stop timer thread on database shutdown.
</action>