You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by en...@apache.org on 2014/01/28 00:21:58 UTC

git commit: CLEREZZA-870 Fixed an issue with literals serialization and exception handling in performAdd method of VirtuosoMGraph. Added a test with the clerezza default system graph.

Updated Branches:
  refs/heads/master b39deccf8 -> ecef9fa62


CLEREZZA-870 Fixed an issue with literals serialization and exception handling in performAdd method of VirtuosoMGraph. Added a test with the clerezza default system graph.


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

Branch: refs/heads/master
Commit: ecef9fa6205f478ef56896db5c9c8c704e0c7f9e
Parents: b39decc
Author: enridaga <en...@apache.org>
Authored: Mon Jan 27 23:21:46 2014 +0000
Committer: enridaga <en...@apache.org>
Committed: Mon Jan 27 23:21:46 2014 +0000

----------------------------------------------------------------------
 clerezza-virtuoso/rdf.virtuoso.storage/pom.xml  | 43 +++++++++++++++++++-
 .../rdf/virtuoso/storage/VirtuosoMGraph.java    | 21 ++++++----
 .../java/rdf/virtuoso/storage/RdfIOTest.java    | 30 ++++++++++++++
 3 files changed, 85 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/ecef9fa6/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml b/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
index 0432b84..db67830 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/pom.xml
@@ -95,7 +95,48 @@
 			<scope>test</scope>
 		</dependency>
 	 -->
-	 </dependencies>
+	 <dependency>
+	 	<groupId>org.apache.clerezza</groupId>
+	 	<artifactId>platform.config</artifactId>
+	 	<version>0.3-incubating</version>
+	 	<type>bundle</type>
+	 	<scope>test</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.clerezza</groupId>
+	 	<artifactId>rdf.jena.parser</artifactId>
+	 	<version>0.11</version>
+	 	<type>bundle</type>
+	 	<scope>test</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.clerezza</groupId>
+	 	<artifactId>platform</artifactId>
+	 	<version>0.1-incubating</version>
+	 	<type>bundle</type>
+	 	<scope>test</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>com.hp.hpl.jena</groupId>
+	 	<artifactId>jena</artifactId>
+	 	<version>2.6.4</version>
+	 	<scope>test</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.clerezza</groupId>
+	 	<artifactId>rdf.jena.facade</artifactId>
+	 	<version>0.13</version>
+	 	<type>bundle</type>
+	 	<scope>test</scope>
+	 </dependency>
+	 <dependency>
+	 	<groupId>org.apache.clerezza</groupId>
+	 	<artifactId>rdf.jena.commons</artifactId>
+	 	<version>0.6</version>
+	 	<type>bundle</type>
+	 	<scope>test</scope>
+	 </dependency>
+	</dependencies>
 
 	<profiles>
 		<profile>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ecef9fa6/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
index cf2b56e..33ef98c 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/src/main/java/rdf/virtuoso/storage/VirtuosoMGraph.java
@@ -71,7 +71,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 	 * (strings) to clerezza blank nodes and vice versa.
 	 */
 	private final BidiMap<String, BNode> bnodesMap;
-	private int maxVirtBnodeIndex = 0;
+//	private int maxVirtBnodeIndex = 0;
 
 	/**
 	 * Logger
@@ -359,7 +359,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 	protected boolean performAdd(Triple triple) {
 		logger.debug("performAdd(Triple {})", triple);
 		String sql = getAddSQLStatement(triple);
-		logger.debug("Executing SQL: {}", sql);
+		logger.info("Executing SQL: {}", sql);
 		// logger.info("--- {} ", sql);
 		writeLock.lock();
 		VirtuosoConnection connection = null;
@@ -370,10 +370,10 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 			st = connection.createStatement();
 			st.execute(sql);
 		} catch (VirtuosoException ve) {
-			logger.error("ERROR while executing statement", e);
+			logger.error("ERROR while executing statement", ve);
 			e = ve;
 		} catch (SQLException se) {
-			logger.error("ERROR while executing statement", e);
+			logger.error("ERROR while executing statement", se);
 			e = se;
 		} catch (ClassNotFoundException e1) {
 			e = e1;
@@ -394,7 +394,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 			}
 		}
 		if (e != null) {
-			return false;
+			throw new RuntimeException(e);
 		}
 		return true;
 	}
@@ -433,7 +433,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 			}
 		}
 		if (e != null) {
-			return false;
+			throw new RuntimeException(e);
 		}
 		return true;
 	}
@@ -511,6 +511,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 			logger.error("ERROR while executing statement", se);
 			e = se;
 		} catch (ClassNotFoundException e1) {
+			logger.error("ERROR while executing statement", e1);
 			e = e1;
 		} finally {
 			writeLock.unlock();
@@ -534,6 +535,9 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 				}
 			}
 		}
+		if(e!=null){
+			throw new RuntimeException(e);
+		}
 		return new StringBuilder().append('<').append(bnodeId).append('>').toString();
 	}
 
@@ -603,6 +607,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 		} else if (object instanceof TypedLiteral) {
 			return toVirtTypedLiteral((TypedLiteral) object);
 		}
+		// XXX throw exception here?
 		return null;
 	}
 
@@ -615,7 +620,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 	private String toVirtTypedLiteral(TypedLiteral object) {
 		logger.debug("toVirtTypedLiteral(TypedLiteral {})", object);
 		UriRef dt = object.getDataType();
-		String literal = object.getLexicalForm();
+		String literal = object.getLexicalForm().replaceAll("\"", "\\\\\"");
 		return new StringBuilder().append('"').append(literal).append('"')
 				.append("^^").append(toVirtIri(dt)).toString();
 	}
@@ -629,7 +634,7 @@ public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
 	private String toVirtPlainLiteral(PlainLiteral object) {
 		logger.debug("toVirtPlainLiteral(PlainLiteral {})", object);
 		Language lang = object.getLanguage();
-		String literal = object.getLexicalForm();
+		String literal = object.getLexicalForm().replaceAll("\"", "\\\\\"");
 		StringBuilder sb = new StringBuilder().append('"').append(literal)
 				.append('"');
 		if (lang == null) {

http://git-wip-us.apache.org/repos/asf/clerezza/blob/ecef9fa6/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
index caa01c0..7860395 100644
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
+++ b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/rdf/virtuoso/storage/RdfIOTest.java
@@ -18,11 +18,15 @@
  */
 package rdf.virtuoso.storage;
 
+import java.io.IOException;
+import java.net.URL;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.Iterator;
 
+import org.apache.clerezza.platform.config.SystemConfig;
 import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.MGraph;
 import org.apache.clerezza.rdf.core.NonLiteral;
 import org.apache.clerezza.rdf.core.Resource;
 import org.apache.clerezza.rdf.core.Triple;
@@ -30,6 +34,9 @@ import org.apache.clerezza.rdf.core.TypedLiteral;
 import org.apache.clerezza.rdf.core.UriRef;
 import org.apache.clerezza.rdf.core.impl.TripleImpl;
 import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
+import org.apache.clerezza.rdf.core.serializedform.ParsingProvider;
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat;
+import org.apache.clerezza.rdf.jena.parser.JenaParserProvider;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -327,4 +334,27 @@ public class RdfIOTest {
 		Assert.assertEquals(n, 1);
 
 	}
+	
+	@Test
+	public void sysconfigTest(){
+		if (TestUtils.SKIP) {
+			log.warn("SKIPPED");
+			return;
+		}
+		
+		SystemConfig sc = new SystemConfig();
+		MGraph systemGraph = mgraph;
+		URL config = sc.getClass().getResource(SystemConfig.CONFIG_FILE);
+        if (config == null) {
+            throw new RuntimeException("no config file found");
+        }
+        ParsingProvider parser = new JenaParserProvider();
+        try {
+            parser.parse(systemGraph, config.openStream(),
+                    SupportedFormat.RDF_XML, null);
+        } catch (IOException ex) {
+            log.warn("Cannot parse coniguration at URL: {}", config);
+            throw new RuntimeException(ex);
+        }
+	}
 }