Skip to content

Commit

Permalink
bug19847: support BNode usage in a federation
Browse files Browse the repository at this point in the history
<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
Bill Millar authored and dklayer committed Dec 15, 2010
1 parent dae0f7c commit 27d7852
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 19 deletions.
3 changes: 1 addition & 2 deletions src/com/franz/agraph/http/AGResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion src/com/franz/agraph/repository/AGValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand Down
16 changes: 1 addition & 15 deletions src/com/franz/agraph/repository/AGVirtualRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;

import org.openrdf.model.BNode;
import org.openrdf.model.Resource;
import org.openrdf.repository.RepositoryException;

Expand All @@ -16,24 +15,11 @@ public class AGVirtualRepository implements AGAbstractRepository, Closeable {
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() {
Expand Down
51 changes: 51 additions & 0 deletions src/test/FederationTests.java
Original file line number Diff line number Diff line change
@@ -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());
}

}
3 changes: 2 additions & 1 deletion src/test/TestSuites.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static class Temp {}
JenaTests.class,
BulkModeTests.class,
IndexManagementTests.class,
EncodableNamespaceTests.class
EncodableNamespaceTests.class,
FederationTests.class
})
public static class Prepush {}

Expand Down

0 comments on commit 27d7852

Please sign in to comment.