Permalink
Browse files

bug19798: Illegal resource in Jena reified statememts

<release-note>
bug19798: Illegal resource in Jena reified statememts

Previously, the Jena adapter's createReifiedStatement method
could create reified statements containing illegal blank node
ids that were based on generated UUIDs, manifesting in invalid
part errors from the server.  With this change, these reified
statements are now created using legal resources.  AGGraphMaker
instances can now be created with a specified ReificationStyle
(the default style is ReificationStyle.Minimal).
</release-note>

Added AGReifierTest and ReifiedStatementTests.
make prepush passes.
ant jena-compliance-tests passes.

Change-Id: I0636a5830793f12396141bb4b7a992e85fb7bf9a
Reviewed-on: https://gerrit.franz.com:9080/1597
Reviewed-by: Ahmon Dancy <dancy@franz.com>
Reviewed-by: John O'Rourke <jor@franz.com>
Tested-by: Kevin Layer <layer@franz.com>
  • Loading branch information...
1 parent 014b158 commit b304c16e8e597fd623d6dcd1905217889f43241a Bill Millar committed with dklayer Sep 9, 2010
View
@@ -4,11 +4,11 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/junit-4.8.1.jar" sourcepath="lib/junit-4.8.1-src.jar"/>
<classpathentry kind="lib" path="lib/commons-cli-1.2.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/arq-2.8.1.jar" sourcepath="lib/jena-2.6.2/src/arq-2.8.1-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/arq-2.8.1.jar" sourcepath="lib/jena-2.6.2/arq-2.8.1-sources.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/icu4j-3.4.4.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/iri-0.7.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2-tests.jar" sourcepath="lib/jena-2.6.2/src/jena-2.6.2-test-sources.jar"/>
- <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2.jar" sourcepath="lib/jena-2.6.2/src/jena-2.6.2-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2-tests.jar" sourcepath="lib/jena-2.6.2/jena-2.6.2-test-sources.jar"/>
+ <classpathentry kind="lib" path="lib/jena-2.6.2/jena-2.6.2.jar" sourcepath="lib/jena-2.6.2/jena-2.6.2-sources.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/lucene-core-2.3.1.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/stax-api-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/jena-2.6.2/wstx-asl-3.2.9.jar"/>
@@ -30,15 +30,22 @@
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphUtil;
import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Reifier;
import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.graph.impl.GraphBase;
+import com.hp.hpl.jena.graph.impl.ReifierFragmentHandler;
+import com.hp.hpl.jena.graph.impl.ReifierFragmentsMap;
+import com.hp.hpl.jena.graph.impl.ReifierTripleMap;
+import com.hp.hpl.jena.graph.impl.SimpleReifier;
import com.hp.hpl.jena.shared.AddDeniedException;
import com.hp.hpl.jena.shared.DeleteDeniedException;
import com.hp.hpl.jena.shared.PrefixMapping;
+import com.hp.hpl.jena.shared.ReificationStyle;
import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.util.iterator.NullIterator;
/**
* Implements the Jena Graph interface for AllegroGraph.
@@ -57,6 +64,7 @@
protected String entailmentRegime = "false";
AGGraph(AGGraphMaker maker, Node graphNode) {
+ super(maker.getReificationStyle());
this.maker = maker;
this.graphNode = graphNode;
conn = maker.getRepositoryConnection();
@@ -66,6 +74,7 @@
}
AGGraph(AGGraphMaker maker, Resource context, Resource... contexts) {
+ super(maker.getReificationStyle());
this.maker = maker;
this.graphNode = null;
this.conn = maker.getRepositoryConnection();
@@ -248,4 +257,95 @@ protected int graphBaseSize() {
return size;
}
+ @Override
+ protected Reifier constructReifier() {
+ if (!style.intercepts() && !style.conceals()) {
+ return new SimpleReifier( this, new EmptyReifierTripleMap(), new EmptyReifierFragmentsMap(), style );
+ } else {
+ return new SimpleReifier( this, style );
+ }
+ }
+
+ class EmptyReifierTripleMap implements ReifierTripleMap {
+
+ @Override
+ public Triple getTriple(Node tag) {
+ return null;
+ }
+
+ @Override
+ public boolean hasTriple(Triple t) {
+ return false;
+ }
+
+ @Override
+ public Triple putTriple(Node key, Triple value) {
+ return null;
+ }
+
+ @Override
+ public void removeTriple(Node key) {
+ }
+
+ @Override
+ public void removeTriple(Node key, Triple value) {
+ }
+
+ @Override
+ public void removeTriple(Triple triple) {
+ }
+
+ @Override
+ public ExtendedIterator<Triple> find(TripleMatch m) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public ExtendedIterator<Node> tagIterator() {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public ExtendedIterator<Node> tagIterator(Triple t) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ }
+
+ class EmptyReifierFragmentsMap implements ReifierFragmentsMap {
+
+ @Override
+ public ExtendedIterator<Triple> find(TripleMatch m) {
+ return NullIterator.instance();
+ }
+
+ @Override
+ public int size() {
+ return 0;
+ }
+
+ @Override
+ public ReifierFragmentHandler getFragmentHandler(Triple fragment) {
+ return null;
+ }
+
+ @Override
+ public boolean hasFragments(Node tag) {
+ return false;
+ }
+
+ @Override
+ public void clear() {
+ }
+
+ }
}
@@ -35,15 +35,22 @@
public class AGGraphMaker implements GraphMaker, Closeable {
private AGRepositoryConnection conn;
+ private ReificationStyle style;
private AGGraph defaultGraph;
// TODO make this persistent?
protected Map<String, AGGraph> created = CollectionFactory.createHashedMap();
public AGGraphMaker(AGRepositoryConnection conn) {
this.conn = conn;
+ this.style = ReificationStyle.Minimal;
}
+ public AGGraphMaker(AGRepositoryConnection conn, ReificationStyle style) {
+ this.conn = conn;
+ this.style = style;
+ }
+
public AGRepositoryConnection getRepositoryConnection() {
return conn;
}
@@ -99,7 +106,7 @@ private String absUriFromString(String name) {
@Override
public ReificationStyle getReificationStyle() {
- return ReificationStyle.Minimal;
+ return style;
}
@Override
@@ -19,9 +19,13 @@
import com.franz.agraph.repository.AGRDFFormat;
import com.franz.agraph.repository.AGValueFactory;
import com.franz.util.Closeable;
+import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.rdf.model.AnonId;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.impl.ModelCom;
/**
@@ -77,4 +81,84 @@ public Resource createResource() {
BNode blank = vf.createBNode();
return createResource(new AnonId(blank.stringValue()));
}
+
+
+ /*
+ * Override methods involving StatementImpls,
+ * instead using AGStatements.
+ */
+
+ @Override
+ public AGModel add( Statement [] statements ) {
+ getBulkUpdateHandler().add( AGStatement.asTriples( statements ) );
+ return this;
+ }
+
+ @Override
+ public AGModel remove( Statement [] statements ) {
+ getBulkUpdateHandler().delete( AGStatement.asTriples( statements ) );
+ return this;
+ }
+
+ @Override
+ public AGStatement createStatement(Resource r, Property p, RDFNode o) {
+ return new AGStatement(r, p, o, this );
+ }
+
+ @Override
+ public Statement asStatement( Triple t ) {
+ return AGStatement.toStatement( t, this );
+ }
+
+ /*
+ * Override Reification methods
+ */
+
+ /**
+ A mapper that maps modes to their corresponding ReifiedStatement objects. This
+ cannot be static: getRS cannot be static, because the mapping is model-specific.
+ protected final Map1<QuerySolution, ReifiedStatement> mapToRS = new Map1<QuerySolution, ReifiedStatement>()
+ {
+ public ReifiedStatement map1( QuerySolution result ) {
+ return getRS( result.get("s").asNode() );
+ }
+ };
+ */
+
+ /**
+ Answer a ReifiedStatement that is based on the given node.
+ @param n the node which represents the reification (and is bound to some triple t)
+ @return a ReifiedStatement associating the resource of n with the statement of t.
+ private ReifiedStatement getRS( Node n ) {
+ return ReifiedStatementImpl.createExistingReifiedStatement( this, n );
+ }
+ */
+
+
+ /**
+ @return an iterator which delivers all the ReifiedStatements in this model
+ public RSIterator listReifiedStatements() {
+ String queryString = "SELECT ?s WHERE {?s a rdf:Statement .}";
+ AGQuery sparql = AGQueryFactory.create(queryString);
+ QueryExecution qe = AGQueryExecutionFactory.create(sparql, this);
+ ResultSet results;
+ try {
+ results = qe.execSelect();
+ } finally {
+ qe.close();
+ }
+ return new RSIteratorImpl(new NiceIterator<QuerySolution>().andThen(results).mapWith(mapToRS));
+ }
+ */
+
+ /**
+ @return an iterator each of whose elements is a ReifiedStatement in this
+ model such that it's getStatement().equals( st )
+ public RSIterator listReifiedStatements( final Statement st ) {
+ Filter<ReifiedStatement> f = new Filter<ReifiedStatement>() {public boolean accept(ReifiedStatement rs) {return rs.getStatement().equals(st);};};
+ return new RSIteratorImpl(listReifiedStatements().filterKeep(f));
+ }
+ */
+
+
}
@@ -0,0 +1,53 @@
+package com.franz.agraph.jena;
+
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.ReifiedStatement;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.rdf.model.impl.PropertyImpl;
+import com.hp.hpl.jena.rdf.model.impl.ResourceImpl;
+import com.hp.hpl.jena.rdf.model.impl.StatementImpl;
+
+public class AGStatement extends StatementImpl {
+
+ public AGStatement(Resource subject, Property predicate, RDFNode object) {
+ super(subject, predicate, object);
+ }
+
+ public AGStatement(Resource subject, Property predicate, RDFNode object,
+ AGModel model) {
+ super(subject, predicate, object, model);
+ }
+
+ @Override
+ public AGModel getModel() {
+ return (AGModel)super.getModel();
+ }
+
+ private static long reifiedStatementId = 0;
+
+ /**
+ create a ReifiedStatement corresponding to this Statement
+ */
+ @Override
+ public synchronized ReifiedStatement createReifiedStatement() {
+ reifiedStatementId++;
+ return createReifiedStatement("urn:x-agraph:reifiedStatement"+reifiedStatementId);
+ }
+
+ /**
+ * create a Statement from the triple _t_ in the enhanced graph _eg_. The
+ * Statement has subject, predicate, and object corresponding to those of
+ * _t_.
+ */
+ public static Statement toStatement( Triple t, AGModel eg )
+ {
+ Resource s = new ResourceImpl( t.getSubject(), eg );
+ Property p = new PropertyImpl( t.getPredicate(), eg );
+ RDFNode o = createObject( t.getObject(), eg );
+ return new AGStatement( s, p, o, eg );
+ }
+
+}
Oops, something went wrong. Retry.

0 comments on commit b304c16

Please sign in to comment.