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/03/29 19:05:26 UTC

[3/5] CLEREZZA-813 Moved the two virtuoso modules to the clerezza root folder. Added to the main pom.xml

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccessTest.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccessTest.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccessTest.java
deleted file mode 100644
index 3ca89f0..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccessTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage.access;
-
-import java.sql.SQLException;
-
-import org.apache.clerezza.rdf.core.BNode;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.virtuoso.storage.TestUtils;
-import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class DataAccessTest {
-
-	private static DataAccess da = null;
-
-	static Logger log = LoggerFactory.getLogger(DataAccessTest.class);
-	
-	@BeforeClass
-	public static void assume(){
-		org.junit.Assume.assumeTrue(!TestUtils.SKIP);
-	}
-	
-	@Before
-	public void before() throws ClassNotFoundException, SQLException {
-		da = TestUtils.getProvider().createDataAccess();
-		da.clearGraph( "urn:x-test:DataAccessTest" );
-	}
-
-	@After
-	public void after() {
-		da.clearGraph( "urn:x-test:DataAccessTest" );
-		da.close();
-		da = null;
-	}
-
-	private void testTriple(Triple t){
-		String g = "urn:x-test:DataAccessTest";
-		da.insertQuad(g, t);
-		
-		Assert.assertTrue(da.filter(g, null, null, null).hasNext());
-
-		Assert.assertTrue(da.filter(g, t.getSubject(), null, null).hasNext());
-		Assert.assertTrue(da.filter(g, null, t.getPredicate(), null).hasNext());
-		Assert.assertTrue(da.filter(g, null, null, t.getObject()).hasNext());
-		
-		Assert.assertTrue(da.filter(g, null, t.getPredicate(), t.getObject()).hasNext());
-		Assert.assertTrue(da.filter(g, t.getSubject(), null, t.getObject()).hasNext());
-		Assert.assertTrue(da.filter(g, t.getSubject(), t.getPredicate(), null).hasNext());
-		Assert.assertTrue(da.filter(g, t.getSubject(), null, t.getObject()).hasNext());
-
-		Assert.assertTrue(da.filter(g, t.getSubject(), t.getPredicate(), t.getObject()).hasNext());
-
-		Assert.assertTrue(da.size(g) == 1);
-		
-		da.deleteQuad(g, t);
-		
-		Assert.assertTrue(da.size(g) == 0);
-	}
-
-	@Test
-	public void test_Uri_Uri_Uri(){
-		Triple t = new TripleImpl(new UriRef("urn:subject"), new UriRef("urn:predicate"), new UriRef("urn:object"));
-		testTriple(t);
-	}
-
-	@Test
-	public void test_Uri_Uri_PlainLiteral(){
-		Triple t = new TripleImpl(new UriRef("urn:subject"), new UriRef("urn:predicate"), new PlainLiteralImpl("Lorem Ipsum"));
-		testTriple(t);
-	}
-	
-	@Test
-	public void test_Uri_Uri_BNode(){
-		Triple t = new TripleImpl(new UriRef("urn:subject"), new UriRef("urn:predicate"), new BNode());
-		testTriple(t);
-	}
-	
-	@Test
-	public void testRenew(){
-		int i = 100;
-		while(i>0){
-			test_Uri_Uri_Uri();
-			test_Uri_Uri_PlainLiteral();
-			i--;
-		}
-		da.renew();
-		i = 100;
-		while(i>0){
-			test_Uri_Uri_Uri();
-			test_Uri_Uri_PlainLiteral();
-			i--;
-		}
-		da.renew();
-		i = 100;
-		while(i>0){
-			test_Uri_Uri_Uri();
-			test_Uri_Uri_PlainLiteral();
-			i--;
-		}
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProviderTest.java
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProviderTest.java b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProviderTest.java
deleted file mode 100644
index 0ac3a27..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/java/org/apache/clerezza/rdf/virtuoso/storage/access/VirtuosoWeightedProviderTest.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.clerezza.rdf.virtuoso.storage.access;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.clerezza.rdf.core.Graph;
-import org.apache.clerezza.rdf.core.MGraph;
-import org.apache.clerezza.rdf.core.NonLiteral;
-import org.apache.clerezza.rdf.core.PlainLiteral;
-import org.apache.clerezza.rdf.core.Resource;
-import org.apache.clerezza.rdf.core.Triple;
-import org.apache.clerezza.rdf.core.UriRef;
-import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.virtuoso.storage.TestUtils;
-import org.apache.clerezza.rdf.virtuoso.storage.access.VirtuosoWeightedProvider;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import virtuoso.jdbc4.VirtuosoException;
-
-/**
- * 
- * Tests the VirtuosoWeightedProvider
- * 
- * @author enridaga
- * 
- */
-public class VirtuosoWeightedProviderTest {
-	static final Logger log = LoggerFactory
-			.getLogger(VirtuosoWeightedProviderTest.class);
-
-	private static final String TEST_GRAPH_URI = "VirtuosoWeightedProviderTest";
-
-	private static VirtuosoWeightedProvider wp = null;
-
-	@BeforeClass
-	public static void before() throws ClassNotFoundException, SQLException {
-		org.junit.Assume.assumeTrue(!TestUtils.SKIP);
-		
-		log.info("Preparing VirtuosoWeightedProvider for test");
-		wp = TestUtils.getProvider();
-	}
-
-	@Test
-	public void weight() {
-		log.info("Test setting the weight");
-		int w = 200;
-		wp.setWeight(w);
-		assertTrue(wp.getWeight() == w);
-	}
-
-	@Test
-	public void listGraphs() {
-		log.info("Test listGraphs()");
-		Set<UriRef> gs = wp.listGraphs();
-		Iterator<UriRef> it = gs.iterator();
-		log.debug("Graphs:");
-		while (it.hasNext()) {
-			UriRef r = it.next();
-			// Must not be null
-			assertNotNull(r);
-			// Must not be empty string
-			assertFalse(r.getUnicodeString().equals(""));
-			log.debug(" > {}", r.getUnicodeString());
-		}
-	}
-
-	@Test
-	public void listGraphsIsUnmodifiable() {
-		log.info("Test listGraphsIsUnmodifiable()");
-		Set<UriRef> gs = wp.listGraphs();
-		boolean exception = false;
-		try {
-			gs.add(new UriRef("example"));
-		} catch (UnsupportedOperationException e) {
-			log.debug(
-					"Great, we had an {} exception while modifying an immutable set!",
-					e.getClass());
-			exception = true;
-		}
-		assertTrue(exception);
-	}
-
-	@Test
-	public void listMGraphs() {
-		log.info("Test listMGraphs()");
-		Set<UriRef> mg = wp.listMGraphs();
-		log.debug("Graphs:");
-		for (UriRef r : mg) {
-			// Must not be null
-			assertNotNull(r);
-			// Must not be empty string
-			assertFalse(r.getUnicodeString().equals(""));
-			log.debug("MGraph iri: {}", r.getUnicodeString());
-		}
-	}
-
-	final UriRef enridaga = new UriRef("enridaga");
-	final UriRef alexdma = new UriRef("alexdma");
-	final UriRef anuzzolese = new UriRef("anuzzolese");
-	final UriRef predicate = new UriRef("http://property/name");
-	final PlainLiteral object = new PlainLiteralImpl("Enrico Daga");
-	final UriRef knows = new UriRef(TestUtils.FOAF_NS + "knows");
-
-	@Test
-	public void createMGraph() {
-		log.info("createMGraph()");
-		try {
-			MGraph mgraph = wp.createMGraph(new UriRef(TEST_GRAPH_URI));
-			assertNotNull(mgraph);
-			if (log.isDebugEnabled()) {
-				log.debug("Created mgraph, adding a triple");
-				log.debug("MGraph size is {}", mgraph.size());
-			}
-			mgraph.add(new Triple() {
-
-				@Override
-				public NonLiteral getSubject() {
-					return enridaga;
-				}
-
-				@Override
-				public UriRef getPredicate() {
-					return knows;
-				}
-
-				@Override
-				public Resource getObject() {
-					return anuzzolese;
-				}
-			});
-			log.debug("MGraph size is {}", mgraph.size());
-			assertTrue(mgraph.size() == 1);
-		} catch (RuntimeException re) {
-			log.error("ERROR! ", re);
-			assertFalse(true);
-		}
-	}
-
-	@Test
-	public void createGraph() throws VirtuosoException, ClassNotFoundException,
-			SQLException {
-		MGraph smg = new SimpleMGraph();
-		Triple t = new Triple() {
-
-			@Override
-			public NonLiteral getSubject() {
-				return enridaga;
-			}
-
-			@Override
-			public UriRef getPredicate() {
-				return knows;
-			}
-
-			@Override
-			public Resource getObject() {
-				return anuzzolese;
-			}
-		};
-		smg.add(t);
-		UriRef name = new UriRef(TEST_GRAPH_URI);
-		Graph g = wp.createGraph(name, smg);
-		// Graph must contain the triple
-		assertTrue(g.contains(t));
-		// Graph size must be 1
-		assertTrue(g.size() == 1);
-		// Graph retrieved by id must contain the triple
-		assertTrue(wp.getGraph(name).contains(t));
-		// Graph retrieved by id must be equal to g
-		assertTrue(wp.getGraph(name).equals(g));
-	}
-
-	@Test
-	public void testEquals() {
-		log.info("testEquals()");
-		UriRef name = new UriRef(TEST_GRAPH_URI);
-		MGraph g = wp.createMGraph(name);
-		// Equals
-		log.debug("Should be equal: {}", g.equals(wp.getMGraph(name)));
-		assertTrue(g.equals(wp.getMGraph(name)));
-		log.debug("{}  <->  {}", g.getClass(), g.getGraph().getClass());
-		log.debug("Should not be equal: {}", g.equals(g.getGraph()));
-		// Not equals
-		assertFalse(g.equals(g.getGraph()));
-	}
-
-	@Before
-	@After
-	public void clear() throws VirtuosoException, ClassNotFoundException,
-			SQLException {
-		log.info("clear()");
-		log.debug("Removing test graphs <{}>", TEST_GRAPH_URI);
-		try {
-			wp.deleteTripleCollection(new UriRef(TEST_GRAPH_URI));
-		} catch (NoSuchEntityException nsee) {
-			// Nothing to do
-		}
-		try {
-			wp.deleteTripleCollection(new UriRef("urn:my-empty-graph"));
-		} catch (NoSuchEntityException nsee) {
-			// Nothing to do
-		}
-		try {
-			wp.deleteTripleCollection(new UriRef("urn:my-non-empty-graph"));
-		} catch (NoSuchEntityException nsee) {
-			// Nothing to do
-		}
-	}
-	
-	@Test
-	public void testCreateEmptyMGraph(){
-		log.info("testCreateEmptyMGraph()");
-//		try {
-			UriRef ur = new UriRef("urn:my-empty-graph");
-			Assert.assertFalse(wp.listGraphs().contains(ur));
-			Assert.assertFalse(wp.listMGraphs().contains(ur));
-			wp.createMGraph(ur);
-			Assert.assertTrue(wp.canRead(ur));
-			Assert.assertTrue(wp.canModify(ur));
-			Assert.assertTrue(wp.listGraphs().contains(ur));
-			Assert.assertTrue(wp.listMGraphs().contains(ur));
-			wp.deleteTripleCollection(ur);
-			Assert.assertFalse(wp.listGraphs().contains(ur));
-			Assert.assertFalse(wp.listMGraphs().contains(ur));
-//		} catch (NoSuchEntityException nsee) {
-//			// Nothing to do
-//		}
-	}
-	
-	@Test
-	public void testEmptyAndNonEmptyGraphs(){
-		log.info("testEmptyAndNonEmptyGraphs()");
-		
-		UriRef ur = new UriRef("urn:my-empty-graph");
-		UriRef nur = new UriRef("urn:my-non-empty-graph");
-		
-		Assert.assertFalse(wp.listGraphs().contains(ur));
-		Assert.assertFalse(wp.listMGraphs().contains(ur));
-		wp.createMGraph(ur);
-		Assert.assertTrue(wp.canRead(ur));
-		Assert.assertTrue(wp.canModify(ur));
-		wp.createMGraph(nur);
-		Assert.assertTrue(wp.canRead(nur));
-		Assert.assertTrue(wp.canModify(nur));
-		Assert.assertTrue(wp.listGraphs().contains(nur));
-		Assert.assertTrue(wp.listMGraphs().contains(nur));
-		
-		// Add a triple to the non-empty graph
-		Triple t = new TripleImpl(new UriRef("urn:test:subject"), new UriRef("urn:test:predicate"), 
-				new PlainLiteralImpl("A literal"));
-		wp.getMGraph(nur).add(t);
-		// Show inserted triple
-		Iterator<Triple> ti = wp.getMGraph(nur).iterator();
-		while(ti.hasNext()){
-			log.info(" > {}", ti.next());
-		}
-		Assert.assertTrue(wp.getMGraph(nur).contains(t));
-		Assert.assertTrue(wp.getMGraph(ur).isEmpty());
-		// We delete the empty graph
-		wp.deleteTripleCollection(ur);
-		Assert.assertFalse(wp.listGraphs().contains(ur));
-		Assert.assertFalse(wp.listMGraphs().contains(ur));
-		// But the other is still there
-		Assert.assertTrue(wp.listGraphs().contains(nur));
-		Assert.assertTrue(wp.listMGraphs().contains(nur));
-		// And it still contains its triple
-		Assert.assertTrue(wp.getMGraph(nur).contains(t));
-		// We delete the triple
-		wp.getMGraph(nur).remove(t);
-		Assert.assertFalse(wp.getMGraph(nur).contains(t));
-		Assert.assertTrue(wp.getMGraph(nur).isEmpty());
-		// We delete the non empty graph
-		wp.deleteTripleCollection(nur);
-		Assert.assertFalse(wp.listGraphs().contains(nur));
-		Assert.assertFalse(wp.listMGraphs().contains(nur));
-
-	}
-}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/clerezza-virtuoso/rdf.virtuoso.storage/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/resources/log4j.properties b/clerezza-virtuoso/rdf.virtuoso.storage/src/test/resources/log4j.properties
deleted file mode 100644
index ad89d4d..0000000
--- a/clerezza-virtuoso/rdf.virtuoso.storage/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,6 +0,0 @@
-log4j.rootLogger=INFO, S
-log4j.appender.S = org.apache.log4j.ConsoleAppender
-log4j.appender.S.layout = org.apache.log4j.PatternLayout
-log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
-
-log4j.logger.rdf.virtuoso.storage=DEBUG

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/pom.xml
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/pom.xml b/ext.virtuoso.jdbc/pom.xml
new file mode 100644
index 0000000..1bf0bd1
--- /dev/null
+++ b/ext.virtuoso.jdbc/pom.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.clerezza</groupId>
+		<artifactId>clerezza</artifactId>
+		<version>0.5-SNAPSHOT</version>
+		<relativePath>../parent</relativePath>
+	</parent>
+	<artifactId>ext.virtuoso.jdbc</artifactId>
+	<name>Clerezza Ext - Virtuoso JDBC OSGi Bundle</name>
+	<description>Virtuoso JDBC</description>
+		<version>0.3-SNAPSHOT</version>
+	<repositories>
+		<repository>
+			<releases>
+				<updatePolicy>always</updatePolicy>
+			</releases>
+			<snapshots>
+				<updatePolicy>always</updatePolicy>
+			</snapshots>
+			<id>virtuoso-jdbc4-embedded</id>
+			<url>file://localhost/${project.basedir}/src/main/resources/maven/repo</url>
+		</repository>
+	</repositories>
+	<dependencies>
+		<dependency>
+			<groupId>virtuoso</groupId>
+			<artifactId>virtjdbc</artifactId>
+			<type>jar</type>
+			<version>4.1</version>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.felix</groupId>
+				<artifactId>maven-bundle-plugin</artifactId>
+				<extensions>true</extensions>
+				<configuration>
+					<instructions>
+						<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+						<Embed-Dependency>*;scope=compile;artifactId=!slf4j-api</Embed-Dependency>
+						<!-- Embed-Transitive>true</Embed-Transitive -->
+						<!-- Import-Package> </Import-Package -->
+						<Export-Package>
+							openlink.util.*,
+							virtuoso.javax.*,
+							virtuoso.jdbc4.*,
+							virtuoso.sql.*
+						</Export-Package>
+					</instructions>
+				</configuration>
+			</plugin>
+		</plugins>
+		<pluginManagement>
+			<plugins>
+				<!--This plugin's configuration is used to store Eclipse m2e settings 
+					only. It has no influence on the Maven build itself. -->
+				<plugin>
+					<groupId>org.eclipse.m2e</groupId>
+					<artifactId>lifecycle-mapping</artifactId>
+					<version>1.0.0</version>
+					<configuration>
+						<lifecycleMappingMetadata>
+							<pluginExecutions>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>
+											org.apache.felix
+										</groupId>
+										<artifactId>
+											maven-scr-plugin
+										</artifactId>
+										<versionRange>
+											[1.7.0,)
+										</versionRange>
+										<goals>
+											<goal>scr</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<ignore></ignore>
+									</action>
+								</pluginExecution>
+							</pluginExecutions>
+						</lifecycleMappingMetadata>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
+	<packaging>bundle</packaging>
+	<profiles>
+		<profile>
+			<!-- This profile allows for installing/updating a bundle in a running 
+				Sling instance right after building it. Example: mvn clean install -P installBundle 
+				-Dsling.url=http://localhost:8080/system/console Or, to make it faster without 
+				cleaning up or running tests: mvn -o install -DskipTests -P installBundle 
+				-Dsling.url=http://localhost:8080/system/console -->
+			<id>installBundle</id>
+			<activation>
+				<activeByDefault>false</activeByDefault>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.apache.sling</groupId>
+						<artifactId>maven-sling-plugin</artifactId>
+						<executions>
+							<execution>
+								<id>install-bundle</id>
+								<goals>
+									<goal>install</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar
new file mode 100644
index 0000000..b207f0c
Binary files /dev/null and b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.jar differ

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
new file mode 100644
index 0000000..02fa48e
--- /dev/null
+++ b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.0/virtjdbc-4.0.pom
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>virtuoso</groupId>
+  <artifactId>virtjdbc</artifactId>
+  <version>4.0</version>
+  <description>POM was created from install:install-file</description>
+</project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar
new file mode 100755
index 0000000..1c6ccec
Binary files /dev/null and b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.jar differ

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
new file mode 100644
index 0000000..87605c7
--- /dev/null
+++ b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/4.1/virtjdbc-4.1.pom
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>virtuoso</groupId>
+  <artifactId>virtjdbc</artifactId>
+  <version>4.1</version>
+  <description>POM was created from install:install-file</description>
+</project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
new file mode 100644
index 0000000..a0d93d6
--- /dev/null
+++ b/ext.virtuoso.jdbc/src/main/resources/maven/repo/virtuoso/virtjdbc/maven-metadata-local.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><metadata>
+  <groupId>virtuoso</groupId>
+  <artifactId>virtjdbc</artifactId>
+  <versioning>
+    <release>4.1</release>
+    <versions>
+      <version>4.1</version>
+      <version>4.0</version>
+    </versions>
+  </versioning>
+</metadata>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7eebb9d..cf42652 100644
--- a/pom.xml
+++ b/pom.xml
@@ -156,6 +156,10 @@
                 <module>web.resources.yui</module>
                 <module>rdf.storage.externalizer</module>
                 <module>rdf.storage.web</module>
+
+		<module>ext.virtuoso.jdbc</module>
+		<module>rdf.virtuoso.storage</module>
+		<module>platform.launcher.virtuoso</module>
             </modules>
         </profile>
         <profile>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/rdf.virtuoso.storage/README.md
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/README.md b/rdf.virtuoso.storage/README.md
new file mode 100644
index 0000000..31fa1ab
--- /dev/null
+++ b/rdf.virtuoso.storage/README.md
@@ -0,0 +1,49 @@
+# rdf.virtuoso.storage
+
+This module includes an implementation of the storage SPI of Clerezza that connects to a Virtuoso instance.
+
+## Build and Install
+To build this project you need Maven. 
+
+### Simple build
+
+ $ mvn clean install
+
+This module depends on:
+* ext.virtuoso.jdbc : contains JDBC drivers form Virtuoso
+
+Bundle is in the /target folder:
+* rdf.virtuoso.storage/target/rdf.virtuoso.storage-<version>.jar
+
+### Build forcing tests
+You must have a Virtuoso running server to do tests.
+Tests are skipped by default.
+To activate tests, you can set the system property "virtuoso.test" to true:
+
+ $ mvn test -Dvirtuoso.test=true
+ 
+By default, the tests will use the parameters configured in the pom.xml. Change the parameters' values to the ones that fit your installation of Virtuoso.
+
+You can configure the following parameters:
+
+* virtuoso.test (default is null)
+* virtuoso.driver (default is 'virtuoso.jdbc4.Driver')
+* virtuoso.host (default is 'localhost')
+* virtuoso.port (default is '1111')
+* virtuoso.user (default is 'dba')
+* virtuoso.password (default is 'dba')
+
+To override them from cli, you can also do the following:
+
+ $ mvn test -Dvirtuoso.test=true -DargLine="-Dvirtuoso.password=mypassword -Dvirtuoso.port=1234"
+
+### Deploy
+This bundle needs the following:
+* org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.1.Final
+* org.apache.clerezza:ext.virtuoso.jdbc:0.3
+
+To deploy the bundle in a running Felix instance you can do:
+
+ $ mvn install -PinstallBundle -Dsling.url=http://localhost:8080/system/console (change this to be the actual server admin interface)
+
+

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/rdf.virtuoso.storage/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/pom.xml b/rdf.virtuoso.storage/pom.xml
new file mode 100644
index 0000000..fd88a50
--- /dev/null
+++ b/rdf.virtuoso.storage/pom.xml
@@ -0,0 +1,271 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+        <artifactId>clerezza</artifactId>
+        <groupId>org.apache.clerezza</groupId>
+        <version>0.5-SNAPSHOT</version>
+        <relativePath>../parent</relativePath>
+	</parent>
+	<artifactId>rdf.virtuoso.storage</artifactId>
+	<name>Clerezza - SCB Virtuoso storage provider</name>
+	<description>A virtuoso based storage provider</description>
+	<packaging>bundle</packaging>
+	<version>0.3-SNAPSHOT</version>
+	
+	<dependencies>
+		<!-- CLEREZZA -->
+		<dependency>
+			<groupId>org.apache.clerezza</groupId>
+			<artifactId>rdf.core</artifactId>
+			<version>0.14-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<dependency>
+			<groupId>org.wymiwyg</groupId>
+			<artifactId>wymiwyg-commons-core</artifactId>
+		</dependency>
+		<!-- VIRTUOSO Dependencies -->
+		<dependency>
+			<groupId>clerezza-virtuoso</groupId>
+			<artifactId>ext.virtuoso.jdbc</artifactId>
+			<version>0.3-SNAPSHOT</version>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- OSGI -->
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.core</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.osgi</groupId>
+			<artifactId>org.osgi.compendium</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.scr.annotations</artifactId>
+		</dependency>
+
+		<!-- LOGGING -->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<scope>provided</scope>
+		</dependency>
+
+		<!-- TEST (generic) -->
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<scope>test</scope>
+		</dependency>
+<!-- 		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-log4j12</artifactId>
+			<scope>test</scope>
+			<version></version>
+		</dependency>
+-->
+		<dependency>
+			<groupId>org.slf4j</groupId>
+			<artifactId>slf4j-simple</artifactId>
+			<scope>test</scope>
+		</dependency>
+	
+	 <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>com.hp.hpl.jena</groupId>
+	 	<artifactId>jena</artifactId>
+	 	<version>2.6.4</version>
+	 	<scope>test</scope>
+	 	<exclusions>
+		 	<exclusion>
+	          <groupId>org.slf4j</groupId>
+	          <artifactId>slf4j-log4j12</artifactId>
+	        </exclusion>
+	 	</exclusions>
+	 </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>
+			<id>virtuoso-do-tests</id>
+			<activation>
+				<activeByDefault>false</activeByDefault>
+			</activation>
+			<properties>
+				<virtuoso.test>true</virtuoso.test>
+			</properties>
+		</profile>
+	</profiles>
+	<build>
+	   <plugins>
+	   	<plugin>
+				<artifactId>maven-surefire-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>default-test</id>
+						<phase>test</phase>
+						<goals>
+							<goal>test</goal>
+						</goals>
+						<configuration>
+							<systemPropertyVariables>
+								<virtuoso.test>${virtuoso.test}</virtuoso.test>
+								<virtuoso.driver>virtuoso.jdbc4.Driver</virtuoso.driver>
+								<virtuoso.host>localhost</virtuoso.host>
+								<virtuoso.port>1111</virtuoso.port>
+								<virtuoso.user>dba</virtuoso.user>
+								<virtuoso.password>dba</virtuoso.password>
+							</systemPropertyVariables>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		
+	       <plugin>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>maven-scr-plugin</artifactId>
+                    <executions>
+                        <execution>
+                            <id>generate-scr-scrdescriptor</id>
+                            <goals>
+                                <goal>scr</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                    <!-- see http://felix.apache.org/site/apache-felix-scr-plugin-faq.html#ApacheFelixSCRPluginFAQ-NoClassDefFoundErrorduringbuild -->
+                    <dependencies>
+                        <dependency>
+                            <groupId>org.slf4j</groupId>
+                            <artifactId>slf4j-simple</artifactId>
+                            <version>1.6.1</version>
+                        </dependency>
+                    </dependencies>
+                </plugin>
+                <plugin>
+                    <groupId>org.apache.felix</groupId>
+                    <artifactId>maven-bundle-plugin</artifactId>
+                    <extensions>true</extensions>
+                    <configuration>
+                        <instructions>
+                        <Include-Resource>
+                            src/main/resources,
+                            target/scr-plugin-generated
+                        </Include-Resource>
+                        <Service-Component>
+                          OSGI-INF/serviceComponents.xml
+                        </Service-Component>
+                            <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
+                        </instructions>
+                    </configuration>
+                </plugin>
+	   </plugins>
+		<pluginManagement>
+			<plugins>
+			 
+				<!--  plugin>
+					<groupId>org.apache.felix</groupId>
+					<artifactId>maven-bundle-plugin</artifactId>
+					<extensions>true</extensions>
+					<configuration>
+						<instructions>
+							<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+							<Embed-Dependency>*;scope=compile|runtime;artifactId=!slf4j-api</Embed-Dependency>
+							<Import-Package>*</Import-Package>
+							<Export-Package>
+								rdf.virtuoso.storage.*
+							</Export-Package>
+						</instructions>
+					</configuration>
+				</plugin -->
+
+				<!--This plugin's configuration is used to store Eclipse m2e settings 
+					only. It has no influence on the Maven build itself. -->
+				<plugin>
+					<groupId>org.eclipse.m2e</groupId>
+					<artifactId>lifecycle-mapping</artifactId>
+					<version>1.0.0</version>
+					<configuration>
+						<lifecycleMappingMetadata>
+							<pluginExecutions>
+								<pluginExecution>
+									<pluginExecutionFilter>
+										<groupId>
+											org.apache.felix
+										</groupId>
+										<artifactId>
+											maven-scr-plugin
+										</artifactId>
+										<versionRange>
+											[1.7.0,)
+										</versionRange>
+										<goals>
+											<goal>scr</goal>
+										</goals>
+									</pluginExecutionFilter>
+									<action>
+										<ignore></ignore>
+									</action>
+								</pluginExecution>
+							</pluginExecutions>
+						</lifecycleMappingMetadata>
+					</configuration>
+				</plugin>
+			</plugins>
+		</pluginManagement>
+	</build>
+</project>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
new file mode 100644
index 0000000..e8cc46f
--- /dev/null
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoBNode.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.virtuoso.storage;
+
+import org.apache.clerezza.rdf.core.BNode;
+
+public class VirtuosoBNode extends BNode {
+	private String skolemId;
+	public VirtuosoBNode(String skolemId) {
+		this.skolemId = skolemId;
+	}
+	
+	public String getSkolemId(){
+		return skolemId;
+	}
+	
+	public String asSkolemIri(){
+		return new StringBuilder().append('<').append(skolemId).append('>').toString();
+	}
+	
+	public String toString(){
+		return skolemId;
+	}
+	
+	@Override
+	public boolean equals(Object obj) {
+		return (obj instanceof VirtuosoBNode) && (obj.toString().equals(toString()));
+	}
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
----------------------------------------------------------------------
diff --git a/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
new file mode 100644
index 0000000..2516fdc
--- /dev/null
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoGraph.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.virtuoso.storage;
+
+import java.util.Collection;
+
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * This is a read-only version of {@link VirtuosoMGraph}
+ * @author enridaga
+ *
+ */
+public class VirtuosoGraph extends VirtuosoMGraph implements Graph{
+
+	/**
+	 * Logger
+	 */
+	protected Logger logger = LoggerFactory
+			.getLogger(VirtuosoGraph.class);
+	
+	public VirtuosoGraph(String name, DataAccess dataAccess) {
+		super(name, dataAccess);
+	}
+
+	@Override
+	public synchronized boolean add(Triple e) {
+		logger.warn("Attempting modifying an immutable graph");
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public synchronized boolean addAll(Collection<? extends Triple> c) {
+		logger.warn("Attempting modifying an immutable graph");
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public synchronized void clear() {
+		logger.warn("Attempting modifying an immutable graph");
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public synchronized boolean remove(Object o) {
+		logger.warn("Attempting modifying an immutable graph");
+		throw new UnsupportedOperationException();
+	}
+
+	@Override
+	public synchronized boolean removeAll(Collection<?> col) {
+		logger.warn("Attempting modifying an immutable graph");
+		throw new UnsupportedOperationException();
+	}
+	
+	/**
+	 * Must be a VirtuosoGraph with the same name.
+	 */
+	@Override
+	public boolean equals(Object o) {
+		logger.debug("equals({})",o.getClass());
+		if (o instanceof VirtuosoGraph) {
+			logger.debug("{} is a VirtuosoGraph)",o);
+			if (((VirtuosoGraph) o).getName().equals(this.getName())) {
+				logger.debug("Names are equal! They are equal!");
+				return true;
+			}
+		}else{
+			logger.debug("Not a VirtuosoGraph instance: {}",o.getClass());
+		}
+		return false;
+	}
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/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
new file mode 100644
index 0000000..e4dc6d6
--- /dev/null
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/VirtuosoMGraph.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.virtuoso.storage;
+
+import java.util.Iterator;
+import java.util.concurrent.locks.Lock;
+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;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.impl.AbstractMGraph;
+import org.apache.clerezza.rdf.virtuoso.storage.access.DataAccess;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Implementation of MGraph for the Virtuoso quad store.
+ * 
+ * @author enridaga
+ * 
+ */
+public class VirtuosoMGraph extends AbstractMGraph implements MGraph,
+		LockableMGraph {
+	
+	private final ReadWriteLock lock = new ReentrantReadWriteLock();
+	private final Lock readLock = lock.readLock();
+	private final Lock writeLock = lock.writeLock();
+
+	/**
+	 * Logger
+	 */
+	protected Logger logger = LoggerFactory.getLogger(VirtuosoMGraph.class);
+
+	/**
+	 * The name of the graph
+	 */
+	private String name = null;
+	// private int size = 0;
+
+	private VirtuosoGraph readOnly = null;
+	private DataAccess dataAccess = null;
+
+	/**
+	 * Creates a {@link VirtuosoMGraph} Virtuoso MGraph binds directly to the
+	 * store.
+	 * 
+	 * @param connection
+	 */
+	public VirtuosoMGraph(String name, DataAccess dataAccess) {
+		logger.debug("VirtuosoMGraph(String {}, DataAccess {})", name,
+				dataAccess);
+		this.name = name;
+		// this.provider = provider;
+		this.dataAccess = dataAccess;
+	}
+
+	@Override
+	public ReadWriteLock getLock() {
+		logger.debug("getLock()");
+		return lock;
+	}
+
+	@Override
+	public Graph getGraph() {
+		logger.debug("getGraph()");
+		return asVirtuosoGraph();
+	}
+
+	public VirtuosoGraph asVirtuosoGraph() {
+		logger.debug("asVirtuosoGraph()");
+		if (this.readOnly == null) {
+			logger.debug("create embedded singleton read-only instance");
+			this.readOnly = new VirtuosoGraph(name, getDataAccess());
+		}
+		return readOnly;
+	}
+
+	protected DataAccess getDataAccess() {
+		return this.dataAccess;
+	}
+
+	@Override
+	protected Iterator<Triple> performFilter(NonLiteral subject,
+			UriRef predicate, Resource object) {
+		readLock.lock();
+		Iterator<Triple> tit = getDataAccess().filter(getName(), subject,
+				predicate, object);
+		readLock.unlock();
+		return tit;
+	}
+
+	/**
+	 * We load the size every time it is requested.
+	 */
+	@Override
+	public int size() {
+		logger.debug("size()");
+		readLock.lock();
+		int size = getDataAccess().size(getName());
+		readLock.unlock();
+		return size;
+	}
+
+	@Override
+	public void clear() {
+		logger.debug("clear()");
+		writeLock.lock();
+		getDataAccess().clearGraph(getName());
+		writeLock.unlock();
+	}
+
+	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);
+		}
+		writeLock.unlock();
+		return true;
+	}
+
+	protected boolean performRemove(Triple triple) {
+		logger.debug("performRemove(Triple triple)", triple);
+		writeLock.lock();
+		getDataAccess().deleteQuad(getName(), triple);
+		writeLock.unlock();
+		return true;
+	}
+
+	/**
+	 * Returns the graph name
+	 * 
+	 * @return
+	 */
+	public String getName() {
+		logger.debug("getName()");
+		return name;
+	}
+
+	/**
+	 * Must be a VirtuosoMGraph with the same name. Subclasses are not assumed
+	 * to be equals (VirtuosoGraph is not the same as VirtuosoMGraph)
+	 */
+	public boolean equals(Object o) {
+		logger.debug("equals({})", o.getClass());
+		// It must be an instance of VirtuosoMGraph
+		if (o.getClass().equals(VirtuosoMGraph.class)) {
+			logger.debug("{} is a VirtuosoMGraph)", o);
+			if (((VirtuosoMGraph) o).getName().equals(this.getName())) {
+				logger.debug("Names are equal! They are equal!");
+				return true;
+			}
+		} else {
+			logger.debug("Not a VirtuosoMGraph instance: {}", o.getClass());
+		}
+		return false;
+	}
+}

http://git-wip-us.apache.org/repos/asf/clerezza/blob/bb87e83f/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
new file mode 100644
index 0000000..5bc29fc
--- /dev/null
+++ b/rdf.virtuoso.storage/src/main/java/org/apache/clerezza/rdf/virtuoso/storage/access/DataAccess.java
@@ -0,0 +1,949 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.clerezza.rdf.virtuoso.storage.access;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Language;
+import org.apache.clerezza.rdf.core.NonLiteral;
+import org.apache.clerezza.rdf.core.PlainLiteral;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TypedLiteral;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
+import org.apache.clerezza.rdf.virtuoso.storage.VirtuosoBNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.wymiwyg.commons.util.collections.BidiMap;
+import org.wymiwyg.commons.util.collections.BidiMapImpl;
+
+import virtuoso.jdbc4.VirtuosoConnection;
+import virtuoso.jdbc4.VirtuosoException;
+import virtuoso.jdbc4.VirtuosoExtendedString;
+import virtuoso.jdbc4.VirtuosoPreparedStatement;
+import virtuoso.jdbc4.VirtuosoRdfBox;
+import virtuoso.jdbc4.VirtuosoResultSet;
+
+/**
+ * 
+ * @author enridaga
+ *
+ */
+public class DataAccess {
+	private Logger logger = LoggerFactory.getLogger(DataAccess.class);
+
+	final static String DRIVER = "virtuoso.jdbc4.Driver";
+
+	// XXX This is only used to create a new bnode identifier in virtuoso
+	final static String INSERT_NEW_BNODE = "SPARQL INSERT INTO iri(??) { [] `iri(??)` "
+			+ "`iri(??)`}";
+
+	// XXX This is only used to delete a new bnode identifier in virtuoso
+	final static String DELETE_NEW_BNODE = "SPARQL DELETE FROM iri(??) { ?s ?p ?o } WHERE { ?s ?p ?o . filter( ?p = iri(??) && "
+			+ " ?o = iri(??) ) }";
+
+	final static String INSERT_QUAD = "SPARQL INSERT INTO iri(??) {`iri(??)` `iri(??)` "
+			+ "`bif:__rdf_long_from_batch_params(??,??,??)`}";
+	final static String DELETE_QUAD = "SPARQL DELETE FROM iri(??) { ?s ?p ?o } WHERE { ?s ?p ?o . filter( ?s = iri(??) && ?p = iri(??) && "
+			+ " ?o = bif:__rdf_long_from_batch_params(??,??,??) ) } ";
+	final static String LIST_GRAPHS = "SPARQL SELECT DISTINCT ?G WHERE {GRAPH ?G {[] [] []} }";
+	final static String CLEAR_GRAPH = "SPARQL CLEAR GRAPH iri(??)";
+	final static String COUNT_TRIPLES_OF_GRAPH = "SPARQL SELECT COUNT(*) WHERE { bind( iri(??) as ?graph ) . graph ?graph { [] [] [] } }";
+	final static String SELECT__ = "SPARQL SELECT ?subject ?predicate ?object WHERE { bind( iri(??) as ?graph ) . GRAPH ?graph { ?subject ?predicate ?object ";
+	final static String SELECT_TRIPLES_NULL_NULL_NULL = SELECT__ + " } }";
+	final static String SELECT_TRIPLES_S_NULL_NULL = SELECT__ + " . FILTER( ?subject = iri(??) ) } }";
+	final static String SELECT_TRIPLES_S_P_NULL = SELECT__ + " . FILTER( ?subject = iri(??) && ?predicate = iri(??) ) } }";
+	final static String SELECT_TRIPLES_S_P_O = SELECT__ + " . FILTER( ?subject = iri(??) && ?predicate = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
+	final static String SELECT_TRIPLES_NULL_P_NULL = SELECT__ + " . FILTER( ?predicate = iri(??) ) } }";
+	final static String SELECT_TRIPLES_NULL_P_O = SELECT__ + " . FILTER( ?predicate = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
+	final static String SELECT_TRIPLES_NULL_NULL_O = SELECT__ + " . FILTER( ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
+	final static String SELECT_TRIPLES_S_NULL_O = SELECT__ + " . FILTER( ?subject = iri(??) && ?object = bif:__rdf_long_from_batch_params(??,??,??) ) } }";
+
+	private final static String[] filterQueries = new String[] {
+			SELECT_TRIPLES_NULL_NULL_NULL, SELECT_TRIPLES_S_NULL_NULL,
+			SELECT_TRIPLES_S_P_O, SELECT_TRIPLES_NULL_NULL_O,
+			SELECT_TRIPLES_NULL_P_NULL, SELECT_TRIPLES_S_P_NULL,
+			SELECT_TRIPLES_NULL_P_O, SELECT_TRIPLES_S_NULL_O };
+
+	/**
+	 * Bidirectional map for managing the conversion from virtuoso blank nodes
+	 * (strings) to clerezza blank nodes and vice versa.
+	 */
+	private final BidiMap<VirtuosoBNode, BNode> bnodesMap;
+
+	private Map<String, VirtuosoPreparedStatement> preparedStatements = null;
+	private VirtuosoConnection connection = null;
+	private String connectionString;
+	private String user;
+	private String pwd;
+
+	// We protect the constructor from outside the package...
+	DataAccess(String connectionString, String user, String pwd) {
+		this.connectionString = connectionString;
+		this.user = user;
+		this.pwd = pwd;
+		
+		connection = createConnection(connectionString, user, pwd);
+		
+		// Init collections
+		this.preparedStatements = new HashMap<String,VirtuosoPreparedStatement>();
+		this.bnodesMap = new BidiMapImpl<VirtuosoBNode, BNode>();
+
+	}
+
+	private VirtuosoConnection createConnection(final String cs, final String u, final String p) {
+		try {
+			VirtuosoConnection c =  AccessController.doPrivileged(
+					new PrivilegedAction<VirtuosoConnection>() {
+				          public VirtuosoConnection run() {
+				        	  try {
+								Class.forName(VirtuosoWeightedProvider.DRIVER, true, this
+											.getClass().getClassLoader());
+								return  (VirtuosoConnection) DriverManager
+					  					.getConnection(cs, u, p);
+							} catch (ClassNotFoundException e) {
+								throw new RuntimeException(e);
+							} catch (SQLException e) {
+								throw new RuntimeException(e);
+							}
+				          } 
+				        } 
+				     ); 
+			c.setAutoCommit(true);
+			return c;
+		} catch (SQLException e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	// A simple renewal policy
+	private int statementCalls = 0;
+	protected PreparedStatement getStatement(String query)
+			throws VirtuosoException {
+		if(statementCalls >= 10000){
+			statementCalls=0; 
+			renew();
+		}else{
+			statementCalls++;
+		}
+		if (!preparedStatements.containsKey(query)) {
+			VirtuosoPreparedStatement ps = (VirtuosoPreparedStatement) connection
+					.prepareStatement(query);
+			preparedStatements.put(query, ps);
+		}
+		return preparedStatements.get(query);
+	}
+
+	private VirtuosoBNode toVirtBnode(BNode bnode) {
+		logger.debug("toVirtBnode(BNode {})", bnode);
+		if (bnode instanceof VirtuosoBNode) {
+			return ((VirtuosoBNode) bnode);
+		} else {
+			VirtuosoBNode virtBnode = bnodesMap.getKey(bnode);
+			if (virtBnode == null) {
+				// We create a local bnode mapped to the BNode given
+				virtBnode = nextVirtBnode(bnode);
+				bnodesMap.put(virtBnode, bnode);
+			}
+			return virtBnode;
+		}
+	}
+
+	public void renew() {
+		logger.trace("renewing...");
+		close();
+		connection = createConnection(connectionString, user, pwd);
+	}
+
+	public void close() {
+		logger.trace("closing resources...");
+		Collection<VirtuosoPreparedStatement> pss = preparedStatements.values();
+		for (VirtuosoPreparedStatement ps : pss) {
+			try {
+				logger.trace("Closing prepared statement {}", ps);
+				ps.close();
+			} catch (Exception e) {
+				logger.error("Cannot close statement", e);
+			}
+		}
+		logger.trace("closed {} statements.", pss.size());
+		preparedStatements.clear();
+		try {
+			connection.close();
+			logger.trace("Connection closed");
+		} catch (Exception e) {
+			logger.error("Cannot close connection", e);
+		}
+	}
+	
+	private void close(String statementId){
+		try {
+			VirtuosoPreparedStatement ps = preparedStatements.get(statementId);
+			if (ps == null) {
+				logger.warn(
+						"Attempting to close a statement that was not prepared: {}",
+						statementId);
+			} else {
+				logger.trace("Closing prepared statement {}", ps);
+				ps.close();
+			}
+		} catch (Exception e) {
+			logger.error("Cannot close statement", e);
+		} finally {
+			// We won't reuse a statement that thrown a n exception on close...
+			preparedStatements.remove(statementId);
+		}
+	}
+
+	private void bindValue(PreparedStatement st, int i, Resource object)
+			throws SQLException {
+		if (object instanceof UriRef) {
+			st.setInt(i, 1);
+			st.setString(i + 1, ((UriRef) object).getUnicodeString());
+			st.setNull(i + 2, java.sql.Types.VARCHAR);
+		} else if (object instanceof BNode) {
+			st.setInt(i, 1);
+			st.setString(i + 1, ((VirtuosoBNode) object).getSkolemId());
+			st.setNull(i + 2, java.sql.Types.VARCHAR);
+		} else if (object instanceof TypedLiteral) {
+			TypedLiteral tl = ((TypedLiteral) object);
+			st.setInt(i, 4);
+			st.setString(i + 1, tl.getLexicalForm());
+			st.setString(i + 2, tl.getDataType().getUnicodeString());
+		} else if (object instanceof PlainLiteral) {
+			PlainLiteral pl = (PlainLiteral) object;
+			if (pl.getLanguage() != null) {
+				st.setInt(i, 5);
+				st.setString(i + 1, pl.getLexicalForm());
+				st.setString(i + 2, pl.getLanguage().toString());
+			} else {
+				st.setInt(i, 3);
+				st.setString(i + 1, pl.getLexicalForm());
+				st.setNull(i + 2, java.sql.Types.VARCHAR);
+			}
+		} else
+			throw new IllegalArgumentException(object.toString());
+	}
+
+	private void bindPredicate(PreparedStatement st, int i, UriRef predicate)
+			throws SQLException {
+		st.setString(i, predicate.getUnicodeString());
+	}
+
+	private void bindSubject(PreparedStatement st, int i, NonLiteral subject)
+			throws SQLException {
+		if (subject instanceof UriRef) {
+			st.setString(i, ((UriRef) subject).getUnicodeString());
+		} else {
+			st.setString(i, ((VirtuosoBNode) subject).getSkolemId());
+		}
+	}
+
+	private void bindGraph(PreparedStatement st, int i, UriRef uriRef)
+			throws SQLException {
+		st.setString(i, uriRef.getUnicodeString());
+	}
+	
+
+	private void bindGraph(PreparedStatement st, int i, String uri)
+			throws SQLException {
+		st.setString(i, uri);
+	}
+
+	/**
+	 * Generate a new local bnode to be used in virtuoso queries
+	 * 
+	 * @return
+	 */
+	private VirtuosoBNode nextVirtBnode(BNode bn) {
+		logger.debug("nextVirtBnode(BNode)");
+		/**
+		 * XXX Here we force virtuoso to generate a valid skolem uri for a blank
+		 * node we are going to insert for the first time.
+		 * 
+		 * All this process should be more efficient, possibly invoking a native
+		 * procedure, instead of insert/select/delete a fake triple as it is
+		 * now.
+		 */
+		UriRef g = new UriRef("urn:x-virtuoso:bnode-tmp");
+		UriRef p = new UriRef("urn:x-virtuoso:bnode:object");
+		UriRef o = new UriRef(new StringBuilder()
+				.append("urn:x-virtuoso:bnode:").append(bn).toString());
+
+		Exception e = null;
+		VirtuosoResultSet rs = null;
+
+		String bnodeId = null;
+		// insert
+		try {
+			PreparedStatement insert = getStatement(INSERT_NEW_BNODE);
+			bindGraph(insert, 1, g);
+			bindPredicate(insert, 2, p);
+			bindSubject(insert, 3, o);
+			insert.executeUpdate();
+
+			// select
+			PreparedStatement select = getStatement(SELECT_TRIPLES_NULL_P_O);
+			bindGraph(select, 1, g);
+			bindPredicate(select, 2, p);
+			bindValue(select, 3, o);
+			rs = (VirtuosoResultSet) select.executeQuery();
+			rs.next();
+			bnodeId = rs.getString(1);
+			rs.close();
+
+			// delete
+			PreparedStatement delete = getStatement(DELETE_NEW_BNODE);
+			bindGraph(delete, 1, g);
+			bindPredicate(delete, 2, p);
+			bindSubject(delete, 3, o); // It is a IRI
+			delete.executeUpdate();
+
+		} catch (VirtuosoException ve) {
+			logger.error("ERROR while executing statement", ve);
+			e = ve;
+		} catch (SQLException se) {
+			logger.error("ERROR while executing statement", se);
+			e = se;
+		} finally {
+			try {
+				if (rs != null)
+					rs.close();
+			} catch (Exception ex) {
+				logger.error("Error attempting to close result set", ex);
+			}
+		}
+		if (e != null) {
+			close(INSERT_NEW_BNODE);
+			close(SELECT_TRIPLES_NULL_P_O);
+			close(DELETE_NEW_BNODE);
+			throw new RuntimeException(e);
+		}
+		return new VirtuosoBNode(bnodeId);
+
+	}
+	public void insertQuad(String graph, Triple triple) {
+		NonLiteral s = triple.getSubject(); 
+		UriRef p = triple.getPredicate() ;
+		Resource o = triple.getObject();
+		
+		// Skolemize bnodes
+		if(s instanceof BNode){
+			s = toVirtBnode((BNode) s);
+		}
+		if(o instanceof BNode){
+			o = toVirtBnode((BNode) o);
+		}
+		
+		try {
+			PreparedStatement st = getStatement(INSERT_QUAD);
+			bindGraph(st, 1, graph);
+			bindSubject(st, 2, s);
+			bindPredicate(st, 3, p);
+			bindValue(st, 4, o);
+			st.executeUpdate();
+		} catch (VirtuosoException e) {
+			logger.error("Cannot execute statement", e);
+			throw new RuntimeException(e);
+		} catch (SQLException e) {
+			logger.error("Cannot execute statement", e);
+			throw new RuntimeException(e);
+		}
+	}
+
+	public void deleteQuad(String graph,  Triple triple) {
+		NonLiteral s = triple.getSubject(); 
+		UriRef p = triple.getPredicate() ;
+		Resource o = triple.getObject();
+
+		// Skolemize bnodes
+		if(s instanceof BNode){
+			s = toVirtBnode((BNode) s);
+		}
+		if(o instanceof BNode){
+			o = toVirtBnode((BNode) o);
+		}
+		Exception e = null;
+		try {
+			PreparedStatement st = getStatement(DELETE_QUAD);
+			bindGraph(st, 1, graph);
+			bindSubject(st, 2, s);
+			bindPredicate(st, 3, p);
+			bindValue(st, 4, o);
+			st.executeUpdate();
+		} catch (VirtuosoException ex) {
+			logger.error("Cannot execute statement", ex);
+			e = ex;
+		} catch (SQLException ex) {
+			logger.error("Cannot execute statement", ex);
+			e = ex;
+		}
+		
+		if (e != null) {
+			close(DELETE_QUAD);
+			throw new RuntimeException(e);
+		}
+	}
+
+	public Set<UriRef> listGraphs() {
+		Exception e = null;
+
+		Set<UriRef> graphs = new HashSet<UriRef>();
+		try {
+			PreparedStatement st = getStatement(LIST_GRAPHS);
+			ResultSet rs = st.executeQuery();
+			while (rs.next()) {
+				UriRef graph = new UriRef(rs.getString(1));
+				logger.debug(" > Graph {}", graph);
+				graphs.add(graph);
+			}
+		} catch (VirtuosoException ex) {
+			logger.error("Cannot execute query", ex);
+			e = ex;
+		} catch (SQLException ex) {
+			logger.error("Cannot execute query", ex);
+			e = ex;
+		}
+		
+		if(e != null){
+			close(LIST_GRAPHS);
+			throw new RuntimeException(e);
+		}
+		
+		return Collections.unmodifiableSet(graphs);
+	}
+
+	public void clearGraph(String graph) {
+		Exception e = null;
+		try {
+			PreparedStatement st = getStatement(CLEAR_GRAPH);
+			bindGraph(st, 1, graph);
+			st.executeUpdate();
+		} catch (VirtuosoException ex) {
+			logger.error("Cannot execute statement", ex);
+			e = ex;
+		} catch (SQLException ex) {
+			logger.error("Cannot execute statement", ex);
+			e = ex;
+		} 
+		
+		if(e != null){
+			close(CLEAR_GRAPH);
+			throw new RuntimeException(e);
+		}
+	}
+
+	private VirtuosoBNode toBNode(String virtbnode) {
+		VirtuosoBNode bnode;
+		bnode = new VirtuosoBNode(virtbnode);
+		return bnode;
+	}
+
+	public Iterator<Triple> filter(String graph, NonLiteral subject,
+			UriRef predicate, Resource object) {
+		logger.debug("filter(String graph, NonLiteral s, UriRef p, Resource o)");
+
+		// Override blank node object to be a skolemized IRI
+		if (object != null && object instanceof BNode) {
+			object = new UriRef(toVirtBnode((BNode) object).getSkolemId());
+		}
+
+		// Override blank node subjects to be a skolemized IRI
+		if (subject != null && subject instanceof BNode) {
+			subject = new UriRef(toVirtBnode((BNode) subject).getSkolemId());
+		}
+		
+		if (logger.isTraceEnabled()) {
+			logger.trace(" > g: {}", graph);
+			logger.trace(" > s: {}", subject);
+			logger.trace(" > p: {}", predicate);
+			logger.trace(" > o: {}", object);
+		}
+
+		List<Triple> list = null;
+		Exception e = null;
+		Set<String> filters = new HashSet<String>(Arrays.asList(filterQueries));
+
+		//
+		if (subject == null) {
+			filters.remove(SELECT_TRIPLES_S_P_O);
+			filters.remove(SELECT_TRIPLES_S_NULL_NULL);
+			filters.remove(SELECT_TRIPLES_S_P_NULL);
+			filters.remove(SELECT_TRIPLES_S_NULL_O);
+		} else {
+			filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_NULL_O);
+			filters.remove(SELECT_TRIPLES_NULL_P_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_P_O);
+		}
+		if (predicate == null) {
+			filters.remove(SELECT_TRIPLES_S_P_O);
+			filters.remove(SELECT_TRIPLES_NULL_P_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_P_O);
+			filters.remove(SELECT_TRIPLES_S_P_NULL);
+		} else {
+			filters.remove(SELECT_TRIPLES_S_NULL_O);
+			filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_NULL_O);
+			filters.remove(SELECT_TRIPLES_S_NULL_NULL);
+		}
+		if (object == null) {
+			filters.remove(SELECT_TRIPLES_S_P_O);
+			filters.remove(SELECT_TRIPLES_S_NULL_O);
+			filters.remove(SELECT_TRIPLES_NULL_P_O);
+			filters.remove(SELECT_TRIPLES_NULL_NULL_O);
+		} else {
+			filters.remove(SELECT_TRIPLES_S_P_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_NULL_NULL);
+			filters.remove(SELECT_TRIPLES_NULL_P_NULL);
+			filters.remove(SELECT_TRIPLES_S_NULL_NULL);
+		}
+
+		// There must be only 1 boss
+		String filter = filters.iterator().next();
+		PreparedStatement ps = null;
+		VirtuosoResultSet rs = null;
+		try {
+			logger.debug("query: {}", filter);
+			ps = getStatement(filter);
+			// In any case the first binding is the graph
+			bindGraph(ps, 1, graph);
+
+			int index = 2;
+			if (subject != null) {
+				bindSubject(ps, index, subject);
+				index++;
+			}
+			if (predicate != null) {
+				bindPredicate(ps, index, predicate);
+				index++;
+			}
+			if (object != null) {
+				bindValue(ps, index, object);
+			}
+
+			rs = (VirtuosoResultSet) ps.executeQuery();
+			list = new ArrayList<Triple>();
+
+			while (rs.next()) {
+				list.add(new TripleBuilder(rs.getObject(1), rs.getObject(2), rs
+						.getObject(3)).build());
+			}
+		} catch (VirtuosoException e1) {
+			logger.error("ERROR while executing statement", ps);
+			e = e1;
+		} catch (SQLException e1) {
+			logger.error("ERROR while executing statement", ps);
+			e = e1;
+		} finally {
+			try {
+				if (rs != null)
+					rs.close();
+			} catch (Throwable ex) {
+				logger.error("Cannot close result set", ex);
+			}
+		}
+
+		if (list == null || e != null) {
+			// We also close the statement
+			close(filter);
+			throw new RuntimeException(e);
+		}
+		return list.iterator();
+	}
+
+	public int size(String graph){
+		logger.trace("called size({})", graph);
+		Exception e = null;
+		PreparedStatement ps = null;
+		VirtuosoResultSet rs = null;
+		int size = -1;
+		try {
+			ps = getStatement(COUNT_TRIPLES_OF_GRAPH);
+			logger.trace("statement got: {}", ps);
+			// In any case the first binding is the graph
+			bindGraph(ps, 1, graph);
+			logger.trace("bound value: {}", graph);
+			boolean r = ps.execute();
+			logger.trace("Executed statement: {}", r);
+			if(r){
+				rs = (VirtuosoResultSet) ps.getResultSet();
+				logger.trace("Got result set, has next?");
+				boolean hn = rs.next();
+				logger.trace(" > {}", hn);
+				if(hn){
+					size = rs.getInt(1);
+				}else{
+					e = new RuntimeException("Incosistent result. A result row was expected. None obtained.");
+				}
+			}else{
+				e = new RuntimeException("Incosistent result. ResultSet expected but 'false' returned by statement execute() ");
+			}
+		} catch (VirtuosoException e1) {
+			logger.error("ERROR while executing statement", ps);
+			e = e1;
+		} catch (SQLException e1) {
+			logger.error("ERROR while executing statement", ps);
+			e = e1;
+		} finally {
+			try {
+				if (rs != null)
+					rs.close();
+			} catch (Throwable ex) {
+				logger.error("Cannot close result set", ex);
+			}
+		}
+		
+		if (size == -1 || e != null) {
+			// We also close the statement
+			close(COUNT_TRIPLES_OF_GRAPH);
+			throw new RuntimeException(e);
+		}
+
+		return size;	
+	}
+	
+	/**
+	 * Builds a clerezza Triple from Virtuoso result types
+	 * 
+	 */
+	private class TripleBuilder {
+
+		Object s = null;
+		Object p = null;
+		Object o = null;
+
+		public TripleBuilder(Object s, Object p, Object o) {
+			if (logger.isDebugEnabled()) {
+				logger.debug("TripleBuilder(Object s, Object p, Object o)");
+				logger.debug("> s: {}", s);
+				logger.debug("> p: {}", p);
+				logger.debug("> o: {}", o);
+			}
+			this.s = s;
+			this.p = p;
+			this.o = o;
+		}
+
+		private NonLiteral buildSubject() {
+			logger.debug("TripleBuilder.getSubject() : {}", s);
+			if (s instanceof VirtuosoExtendedString) {
+				VirtuosoExtendedString vs = (VirtuosoExtendedString) s;
+				if (vs.iriType == VirtuosoExtendedString.IRI
+						&& (vs.strType & 0x01) == 0x01) {
+					// Subject is IRI
+					return new UriRef(vs.str);
+				} else if (vs.iriType == VirtuosoExtendedString.BNODE) {
+					return DataAccess.this.toBNode(vs.str);
+				} else {
+					// !Cannot happen
+					throw new IllegalStateException(
+							"Subject must be an IRI or a BNODE");
+				}
+			} else {
+				throw new IllegalStateException(
+						"Subject must be an instance of VirtuosoExtendedString");
+			}
+		}
+
+		private UriRef buildPredicate() {
+			logger.debug("TripleBuilder.getPredicate() : {}", p);
+			if (p instanceof VirtuosoExtendedString) {
+				VirtuosoExtendedString vs = (VirtuosoExtendedString) p;
+				if (vs.iriType == VirtuosoExtendedString.IRI
+						&& (vs.strType & 0x01) == 0x01) {
+					// Subject is IRI
+					return new UriRef(vs.str);
+				} else {
+					// !Cannot happen
+					throw new IllegalStateException("Predicate must be an IRI ");
+				}
+			} else {
+				throw new IllegalStateException("Predicate must be an IRI");
+			}
+		}
+
+		Resource buildObject() {
+			logger.debug("TripleBuilder.getObject() : {}", o);
+
+			if (o instanceof VirtuosoExtendedString) {
+				// In case is IRI
+				VirtuosoExtendedString vs = (VirtuosoExtendedString) o;
+				if (vs.iriType == VirtuosoExtendedString.IRI
+						&& (vs.strType & 0x01) == 0x01) {
+					// Is IRI
+					return new UriRef(vs.str);
+				} else if (vs.iriType == VirtuosoExtendedString.BNODE) {
+					//
+					return DataAccess.this.toBNode(vs.str);
+				} else {
+					// Is a plain literal
+					return new PlainLiteralImpl(vs.str);
+				}
+			} else if (o instanceof VirtuosoRdfBox) {
+				// In case is typed literal
+				VirtuosoRdfBox rb = (VirtuosoRdfBox) o;
+
+				String value;
+				if (rb.rb_box.getClass().isAssignableFrom(String.class)) {
+					value = (String) rb.rb_box;
+					String lang = rb.getLang();
+					String type = rb.getType();
+					if (type == null) {
+						Language language = lang == null ? null : new Language(
+								lang);
+						return new PlainLiteralImpl(value, language);
+					} else {
+						return new TypedLiteralImpl(value, new UriRef(type));
+					}
+				} else if (rb.rb_box instanceof VirtuosoExtendedString) {
+					VirtuosoExtendedString vs = (VirtuosoExtendedString) rb.rb_box;
+
+					if (vs.iriType == VirtuosoExtendedString.IRI
+							&& (vs.strType & 0x01) == 0x01) {
+						// Is IRI
+						return new UriRef(vs.str);
+					} else if (vs.iriType == VirtuosoExtendedString.BNODE) {
+						//
+						return DataAccess.this.toBNode(vs.str);
+					} else {
+						String type = rb.getType();
+						if (type == null) {
+							String lang = rb.getLang();
+							if (lang != null) {
+								return new PlainLiteralImpl(vs.str,
+										new Language(lang));
+							}
+							// Is a plain literal
+							return new PlainLiteralImpl(vs.str);
+						} else {
+							return new TypedLiteralImpl(vs.str,
+									new UriRef(type));
+						}
+					}
+				}
+			} else if (o == null) {
+				// Raise an exception
+				throw new IllegalStateException("Object cannot be NULL!");
+			}
+
+			// FIXME (not clear this...)
+			return new PlainLiteralImpl(o.toString());
+		}
+
+		public Triple build() {
+			logger.debug("TripleBuilder.build()");
+			return new TripleImpl(buildSubject(), buildPredicate(),
+					buildObject());
+		}
+	}
+
+	/**
+	 * The following private methods are used to support the triple addition
+	 * plan B
+	 */
+	
+	public boolean performAddPlanB(String graph, Triple triple) {
+
+		StringBuilder b = new StringBuilder();
+		b.append(toVirtSubject(triple.getSubject())).append(" ")
+				.append(toVirtPredicate(triple.getPredicate())).append(" ")
+				.append(toVirtObject(triple.getObject())).append(" . ");
+		String sql = new StringBuilder().append("db.dba.ttlp(?, '', '").append(graph).append("', 0)").toString();
+		logger.debug("Exec Plan B: {}", sql);
+		Exception e = null;
+		PreparedStatement st = null;
+		try {
+			st = getStatement(sql);
+			String s = b.toString();
+			logger.trace(" TTL is \n{}\n", s);
+			st.setNString(1, b.toString());
+			st.execute();
+		} catch (VirtuosoException ve) {
+			logger.error("ERROR while executing statement", ve);
+			e = ve;
+		} catch (SQLException se) {
+			logger.error("ERROR while executing statement", se);
+			e = se;
+		}
+		if (e != null) {
+			close(sql);
+			if(logger.isDebugEnabled()){
+				logger.error("S {}", triple.getSubject());
+				logger.error("P {}", triple.getPredicate());
+				logger.error("O {}", triple.getObject());
+				logger.error(" O length: {}", triple.getObject().toString()
+					.length());
+			}
+			logger.error("Sql: {}", sql);
+			throw new RuntimeException(e);
+		}
+		return true;
+	}
+
+	/**
+	 * Returns a string to be used inline in SQL statements as Object of a
+	 * triple.
+	 * 
+	 * @param object
+	 * @return
+	 */
+	private String toVirtObject(Resource object) {
+		logger.debug("toVirtObject(Resource {})", object);
+		if (object == null)
+			return null;
+		if (object instanceof UriRef) {
+			return toVirtIri((UriRef) object);
+		} else if (object instanceof BNode) {
+			return toVirtBnode((BNode) object).asSkolemIri();
+		} else if (object instanceof PlainLiteral) {
+			return toVirtPlainLiteral((PlainLiteral) object);
+		} else if (object instanceof TypedLiteral) {
+			return toVirtTypedLiteral((TypedLiteral) object);
+		}
+		// XXX throw exception here?
+		return null;
+	}
+
+	/**
+	 * Returns a string to be used in SQL statements.
+	 * 
+	 * @param object
+	 * @return
+	 */
+	private String toVirtTypedLiteral(TypedLiteral object) {
+		logger.debug("toVirtTypedLiteral(TypedLiteral {})", object);
+		UriRef dt = object.getDataType();
+		String literal = object.getLexicalForm();// .replaceAll("\"", "\\\\\"");
+		StringBuilder prepared;
+		// If XMLLiteral, prepare XML entities
+		prepared = prepareString(
+				literal,
+				dt.getUnicodeString()
+						.equals("http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"));
+		return new StringBuilder().append('"').append('"').append('"')
+				.append(prepared).append('"').append('"').append('"')
+				.append("^^").append(toVirtIri(dt)).toString();
+	}
+
+	private StringBuilder prepareString(String str, boolean xml) {
+		StringBuilder retStr = new StringBuilder();
+		for (int i = 0; i < str.length(); i++) {
+			int cp = Character.codePointAt(str, i);
+			int charCount = Character.charCount(cp);
+			if (charCount > 1) {
+				i += charCount - 1; // 2.
+				if (i >= str.length()) {
+					throw new IllegalArgumentException("truncated unexpectedly");
+				}
+			}
+
+			if (cp < 128) {
+				retStr.appendCodePoint(cp);
+			} else {
+				if (xml) {
+					retStr.append(String.format("&#x%04x;", cp));
+				} else {
+					retStr.append(String.format("\\u%04x", cp));
+				}
+			}
+		}
+		return retStr;
+	}
+
+	/**
+	 * Returns a string to be used in SQL statements.
+	 * 
+	 * @param object
+	 * @return
+	 */
+	private String toVirtPlainLiteral(PlainLiteral object) {
+		logger.debug("toVirtPlainLiteral(PlainLiteral {})", object);
+		Language lang = object.getLanguage();
+		String literal = object.getLexicalForm();
+		StringBuilder sb = new StringBuilder().append('"').append('"')
+				.append('"').append(prepareString(literal, false)).append('"')
+				.append('"').append('"');
+		if (lang == null) {
+			return sb.toString();
+		} else {
+			return sb.append("@").append(lang).toString();
+		}
+	}
+
+	/**
+	 * Returns a string to be used in SQL statements as Predicate of a triple.
+	 * 
+	 * @param predicate
+	 * @return
+	 */
+	private String toVirtPredicate(UriRef predicate) {
+		logger.debug("toVirtPredicate(UriRef {}) ", predicate);
+		if (predicate == null)
+			return null;
+		return toVirtIri(predicate);
+	}
+
+	private String toVirtIri(UriRef ur) {
+		logger.debug("toVirtIri(UriRef {})", ur);
+		return "<" + ur.getUnicodeString() + ">";
+	}
+
+	/**
+	 * Returns a string to be used in SQL statements as Subject of a triple.
+	 * 
+	 * @param subject
+	 * @return
+	 */
+	private String toVirtSubject(NonLiteral subject) {
+		logger.debug("toVirtSubject(NonLiteral {})", subject);
+		if (subject == null) {
+			return null;
+		}
+		if (subject instanceof UriRef) {
+			return toVirtIri((UriRef) subject);
+		} else if (subject instanceof BNode) {
+			return toVirtBnode((BNode) subject).asSkolemIri();
+		} else {
+			// These should be the only 2 implementations
+			throw new IllegalArgumentException(
+					"subject must be BNode or UriRef");
+		}
+	}
+
+}