clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enrid...@apache.org
Subject git commit: CLEREZZA-908 and CLEREZZA-909 Implemented the workaround of shadowing the rdf:XMLLiteral in the storage
Date Fri, 11 Apr 2014 17:17:16 GMT
Repository: clerezza
Updated Branches:
  refs/heads/master 1360c9f6f -> ad8b28e7d


CLEREZZA-908 and CLEREZZA-909 Implemented the workaround of shadowing the rdf:XMLLiteral in
the storage


Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/ad8b28e7
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/ad8b28e7
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/ad8b28e7

Branch: refs/heads/master
Commit: ad8b28e7d0106b0bc03efa2a522ad27ead9ecd42
Parents: 1360c9f
Author: enridaga <enridaga@apache.org>
Authored: Fri Apr 11 18:17:14 2014 +0100
Committer: enridaga <enridaga@apache.org>
Committed: Fri Apr 11 18:17:14 2014 +0100

----------------------------------------------------------------------
 .../rdf/virtuoso/storage/VirtuosoMGraph.java    | 19 ++++-------
 .../rdf/virtuoso/storage/access/DataAccess.java | 33 ++++++++++++++++++--
 .../rdf/virtuoso/storage/ConnectionTest.java    |  2 --
 .../rdf/virtuoso/storage/RdfIOTest.java         |  3 +-
 .../virtuoso/storage/VirtuosoMGraphTest.java    |  9 +++---
 5 files changed, 42 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/ad8b28e7/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
index e4dc6d6..68a646f 100644
--- a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
@@ -24,7 +24,6 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.Literal;
 import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.NonLiteral;
 import org.apache.clerezza.rdf.core.Resource;
@@ -135,19 +134,13 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 
 	protected boolean performAdd(Triple triple) {
 		logger.debug("performAdd(Triple {})", triple);
-
-		// If the object is a very long literal we use plan B
-		// Reason:
-		// Virtuoso Error:
-		// SR449: Key is too long, index RDF_QUAD, ruling part is 1901 bytes
-		// that exceeds 1900 byte limit
-		// We use alternative method for literals
 		writeLock.lock();
-		if (triple.getObject() instanceof Literal) {
-			getDataAccess().performAddPlanB(getName(), triple);
-		}else{
-			getDataAccess().insertQuad(getName(), triple);
-		}
+		// XXX This is disabled because of CLEREZZA-908
+//		if (triple.getObject() instanceof Literal && false) {
+//			getDataAccess().performAddPlanB(getName(), triple);
+//		}else{
+		getDataAccess().insertQuad(getName(), triple);
+//		}
 		writeLock.unlock();
 		return true;
 	}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ad8b28e7/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
index ab0c32a..f077d64 100644
--- a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
@@ -103,6 +103,10 @@ public class DataAccess {
 			SELECT_TRIPLES_NULL_P_NULL, SELECT_TRIPLES_S_P_NULL,
 			SELECT_TRIPLES_NULL_P_O, SELECT_TRIPLES_S_NULL_O };
 
+	// rdf:XMLLiteral needs to be shadowed in the storage because of a BUG in virtuoso
+	private final static UriRef XMLLiteral = new UriRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral");
+	private final static UriRef XMLLiteralShadowed = new UriRef("urn:x-clerezza:rdf#XMLLiteral");
+	
 	/**
 	 * Bidirectional map for managing the conversion from virtuoso blank nodes
 	 * (strings) to clerezza blank nodes and vice versa.
@@ -192,7 +196,14 @@ public class DataAccess {
 			TypedLiteral tl = ((TypedLiteral) object);
 			st.setInt(i, 4);
 			st.setString(i + 1, tl.getLexicalForm());
-			st.setString(i + 2, tl.getDataType().getUnicodeString());
+			
+			// XXX Shadow rdf:XMLLiteral datatype
+			// See CLEREZZA-XXX
+			UriRef dt = tl.getDataType();
+			if(dt.equals(XMLLiteral)){
+				dt = XMLLiteralShadowed;
+			}
+			st.setString(i + 2, dt.getUnicodeString());
 		} else if (object instanceof PlainLiteral) {
 			PlainLiteral pl = (PlainLiteral) object;
 			if (pl.getLanguage() != null) {
@@ -614,8 +625,10 @@ public class DataAccess {
 	/**
 	 * The following private methods are used to support the triple addition
 	 * plan B
+	 * 
+	 * XXX This is deprecated. Discussion at CLEREZZA-908
 	 */
-	
+	@Deprecated
 	public boolean performAddPlanB(String graph, Triple triple) {
 
 		StringBuilder b = new StringBuilder();
@@ -848,7 +861,14 @@ public class DataAccess {
 							lang);
 					return new PlainLiteralImpl(value, language);
 				} else {
-					return new TypedLiteralImpl(value, new UriRef(type));
+					// XXX Shadowing XMLLiteral
+					UriRef dt;
+					if(type.equals(XMLLiteralShadowed.getUnicodeString())){
+						dt = XMLLiteral;
+					} else {
+						dt = new UriRef(type);
+					}
+					return new TypedLiteralImpl(value, dt);
 				}
 			} else if (rb.rb_box instanceof VirtuosoExtendedString) {
 				VirtuosoExtendedString vs = (VirtuosoExtendedString) rb.rb_box;
@@ -911,6 +931,13 @@ public class DataAccess {
 			qb.append(">");
 			qb.append("\n");
 		}
+		// XXX Shadowing XMLLiteral
+		// This is not very accurate, but we can't go too much further on this, since it is an
hack to
+		// bypass a virtuoso bug
+		// See CLEREZZA-908
+		if(query.contains(XMLLiteral.getUnicodeString())){
+			query.replace(XMLLiteral.getUnicodeString(), XMLLiteralShadowed.getUnicodeString());
+		}
 		qb.append(query);
 		Object returnThis = null;
 		try {

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ad8b28e7/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/ConnectionTest.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/ConnectionTest.java
b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/ConnectionTest.java
index 2fc6e3f..5425290 100644
--- a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/ConnectionTest.java
+++ b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/ConnectionTest.java
@@ -26,8 +26,6 @@ import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Map.Entry;
-import java.util.Properties;
 
 import org.junit.BeforeClass;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ad8b28e7/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/RdfIOTest.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/RdfIOTest.java
b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/RdfIOTest.java
index 7221c9b..8637393 100644
--- a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/RdfIOTest.java
+++ b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/RdfIOTest.java
@@ -121,7 +121,6 @@ public class RdfIOTest {
 
 	@Test
 	public void longString() throws ClassNotFoundException, SQLException, InterruptedException
{
-		log.info("Test a long xsd:string");
 		StringBuilder longStr = new StringBuilder();
 		int c = 250000;
 		while (c > 0) {
@@ -129,6 +128,7 @@ public class RdfIOTest {
 			c--;
 		}
 		int size = longStr.length();
+		log.info("Test a long xsd:string: {} chars",size);
 		TypedLiteral object = new TypedLiteralImpl(longStr.toString(),
 				new UriRef(XSD + "string"));
 		UriRef subject = new UriRef("urn:io-test:reto");
@@ -347,6 +347,5 @@ public class RdfIOTest {
 		TypedLiteral l = (TypedLiteral) read.getObject();
 		Assert.assertEquals(l.getLexicalForm(), s);
 		Assert.assertEquals(l.getDataType(), new UriRef(XSD + "string"));
-
 	}
 }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ad8b28e7/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraphTest.java
b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraphTest.java
index 0d7b1ec..8705fd9 100644
--- a/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraphTest.java
+++ b/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraphTest.java
@@ -43,7 +43,6 @@ import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -141,7 +140,7 @@ public class VirtuosoMGraphTest {
 		assertTrue(mgraph.filter(enridaga, predicate, objectTyped).next().equals(triple));
 	}
 
-	@Ignore
+//	@Ignore
 	@Test
 	public void testAddSingleXMLLiteral() {
 		log.info("testAddSingleXMLLiteral()");
@@ -171,7 +170,9 @@ public class VirtuosoMGraphTest {
 		log.info(" > o: {} ", rt.getObject());
 		log.info(" > tl?: {} ", rt.getObject() instanceof TypedLiteral);
 		assertTrue(mgraph.filter(enridaga, predicate, objectXml).hasNext());
-		assertTrue(mgraph.filter(enridaga, predicate, objectXml).next().equals(triple));
+		Triple tr = mgraph.filter(enridaga, predicate, objectXml).next();
+		log.info("!! {} {} {} !!", new Object[]{tr.getSubject(), tr.getPredicate(), tr.getObject()});
+		assertTrue(tr.equals(triple));
 	}
 
 
@@ -339,7 +340,7 @@ public class VirtuosoMGraphTest {
 		assertTrue(found);
 	}
 
-	@Ignore
+//	@Ignore
 	@Test
 	public void testFilterObjectXml() {
 		log.info("testFilterObjectXml(); Test filter(null,null,o)");


Mime
View raw message