Permalink
Browse files

bug19847: support BNode usage in a federation

<release-note>
bug19847: support BNode usage in a federation

Previously, exceptions would be thrown when BNodes were
created or returned in results from a federation; this
was partly due to BNode creation requiring writes to the
read-only federation.  With this change, the client can
create BNodes locally, and results that contain blank
nodes will parse to BNodes without throwing an exception.
</release-note>

Added FederationTests to prepush tests
make prepush passes
ant tutorial runs

Change-Id: Ic4dda508924f9780a89334c20e047ece64bd3edd
Reviewed-on: https://gerrit.franz.com:9080/994
Reviewed-by: Mike Hinchey <mhinchey@franz.com>
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent dae0f7c commit 27d78529e21d7a34eba5e2165a925b1ad564159d Bill Millar committed with dklayer Nov 16, 2010
View
3 src/com/franz/agraph/http/AGResponseHandler.java
@@ -153,8 +153,7 @@ public void handleResponse(HttpMethod method) throws IOException, RepositoryExce
// TODO:
// .matchMIMEType(mimeType,
// rdfFormats);
- RDFParser parser = Rio.createParser(format, repository
- .getValueFactory());
+ RDFParser parser = Rio.createParser(format, repository.getValueFactory());
parser.setPreserveBNodeIDs(true);
parser.setRDFHandler(rdfhandler);
parser.parse(response, method.getURI().getURI());
View
6 src/com/franz/agraph/repository/AGValueFactory.java
@@ -81,7 +81,11 @@ public BNode createBNode(String nodeID) {
@Override
public BNode createBNode() {
- return createBNode(null);
+ if (repository instanceof AGRepository) {
+ return createBNode(null);
+ } else {
+ return super.createBNode();
+ }
}
/**
View
16 src/com/franz/agraph/repository/AGVirtualRepository.java
@@ -2,7 +2,6 @@
import java.io.File;
-import org.openrdf.model.BNode;
import org.openrdf.model.Resource;
import org.openrdf.repository.RepositoryException;
@@ -16,24 +15,11 @@
private String spec;
private AGValueFactory vf;
- private class AGFederatedValueFactory extends AGValueFactory {
- public AGFederatedValueFactory() {
- super(null);
- }
-
- public BNode createBNode(String nodeID) {
- throw new RuntimeException("Can not create a blank node for a federated store.");
- }
- }
-
public AGVirtualRepository(AGServer server, String spec, AGRepository wrapped) {
this.server = server;
this.spec = spec;
this.wrapped = wrapped;
- if (wrapped == null)
- vf = new AGFederatedValueFactory();
- else
- vf = new AGValueFactory(wrapped);
+ vf = new AGValueFactory(wrapped);
}
public AGServer getServer() {
View
51 src/test/FederationTests.java
@@ -0,0 +1,51 @@
+/******************************************************************************
+** Copyright (c) 2008-2010 Franz Inc.
+** All rights reserved. This program and the accompanying materials
+** are made available under the terms of the Eclipse Public License v1.0
+** which accompanies this distribution, and is available at
+** http://www.eclipse.org/legal/epl-v10.html
+******************************************************************************/
+
+package test;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.openrdf.model.BNode;
+import org.openrdf.model.vocabulary.RDF;
+import org.openrdf.query.BindingSet;
+import org.openrdf.query.QueryLanguage;
+import org.openrdf.query.TupleQueryResult;
+import org.openrdf.repository.RepositoryException;
+
+import com.franz.agraph.repository.AGRepositoryConnection;
+import com.franz.agraph.repository.AGTupleQuery;
+import com.franz.agraph.repository.AGVirtualRepository;
+
+public class FederationTests extends AGAbstractTest {
+
+ @Test
+ @Category(TestSuites.Prepush.class)
+ public void federationBNodes() throws Exception {
+ BNode bnode = vf.createBNode();
+ conn.add(bnode, RDF.TYPE, vf.createURI("http://Foo"));
+ AGVirtualRepository fed = server.federate(repo,repo);
+ AGRepositoryConnection conn2 = fed.getConnection();
+ // Should be able to create BNodes for a federation
+ conn2.getValueFactory().createBNode();
+ conn2.getValueFactory().createBNode("foo");
+ try {
+ conn2.add(bnode, RDF.TYPE, vf.createURI("http://Boo"));
+ Assert.fail("expected can't write to federation.");
+ } catch (RepositoryException e) {
+ //expected
+ }
+ AGTupleQuery q = conn2.prepareTupleQuery(QueryLanguage.SPARQL, "select ?s {?s ?p ?o}");
+ TupleQueryResult result = q.evaluate();
+ Assert.assertTrue(result.hasNext());
+ BindingSet bind = result.next();
+ Assert.assertEquals(bnode.stringValue(), bind.getValue("s").stringValue());
+ }
+
+}
View
3 src/test/TestSuites.java
@@ -55,7 +55,8 @@
JenaTests.class,
BulkModeTests.class,
IndexManagementTests.class,
- EncodableNamespaceTests.class
+ EncodableNamespaceTests.class,
+ FederationTests.class
})
public static class Prepush {}

0 comments on commit 27d7852

Please sign in to comment.