Skip to content

Commit

Permalink
resolves JENA-1739
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudenw committed Aug 9, 2019
1 parent e9a7b95 commit 56b3cfc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private Object makeNodeOrPath(Object o)
return makeNodeOrPath(o, query.getPrefixMapping() );
}

private Object makeNodeOrPath(Object o, PrefixMapping pMapping)
public static Object makeNodeOrPath(Object o, PrefixMapping pMapping)
{
if (o == null) {
return Node.ANY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.apache.jena.sparql.modify.request.UpdateDataInsert;
import org.apache.jena.sparql.modify.request.UpdateDeleteWhere;
import org.apache.jena.sparql.modify.request.UpdateModify;
import org.apache.jena.sparql.path.Path;
import org.apache.jena.update.Update;
import org.apache.jena.update.UpdateRequest;
import org.apache.jena.util.iterator.ExtendedIterator;
Expand Down Expand Up @@ -233,6 +234,41 @@ private Update buildWhere() {

}

/**
* Make a triple path from the objects.
*
* For subject, predicate and objects nodes
* <ul>
* <li>Will return Node.ANY if object is null.</li>
* <li>Will return the enclosed Node from a FrontsNode</li>
* <li>Will return the object if it is a Node.</li>
* <li>If the object is a String
* <ul>
* <li>For <code>predicate</code> only will attempt to parse as a path</li>
* <li>for subject, predicate and object will call NodeFactoryExtra.parseNode()
* using the currently defined prefixes if the object is a String</li>
* </ul></li>
* <li>Will create a literal representation if the parseNode() fails or for
* any other object type.</li>
* </ul>
*
* @param s The subject object
* @param p the predicate object
* @param o the object object.
* @return a TriplePath
*/
public TriplePath makeTriplePath(Object s, Object p, Object o) {
final Object po = AbstractQueryBuilder.makeNodeOrPath( p, prefixHandler.getPrefixes() );
if (po instanceof Path)
{
return new TriplePath(makeNode(s), (Path)po, makeNode(o));
} else
{
return new TriplePath( new Triple( makeNode(s), (Node)po, makeNode(o)));
}

}

/**
* Convert the object to a node.
*
Expand Down Expand Up @@ -1009,7 +1045,7 @@ public UpdateBuilder addWhere(FrontsTriple t) {
* @return The Builder for chaining.
*/
public UpdateBuilder addWhere(Object s, Object p, Object o) {
return addWhere(new Triple(makeNode(s), makeNode(p), makeNode(o)));
return addWhere(makeTriplePath(s, p, o));
}

/**
Expand Down Expand Up @@ -1049,7 +1085,7 @@ public UpdateBuilder addOptional(FrontsTriple t) {
* @return The Builder for chaining.
*/
public UpdateBuilder addOptional(Object s, Object p, Object o) {
return addOptional(new Triple(makeNode(s), makeNode(p), makeNode(o)));
return addOptional(makeTriplePath( s, p, o ));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.apache.jena.sparql.modify.request.UpdateDataDelete;
import org.apache.jena.sparql.modify.request.UpdateDataInsert;
import org.apache.jena.sparql.modify.request.UpdateModify;
import org.apache.jena.sparql.path.P_Link;
import org.apache.jena.sparql.path.Path;
import org.apache.jena.sparql.syntax.Element;
import org.apache.jena.sparql.syntax.ElementGroup;
import org.apache.jena.sparql.syntax.ElementPathBlock;
Expand Down Expand Up @@ -490,4 +492,23 @@ public void example1() {

}

@Test
public void testPathInWhereClause() {
Node p = NodeFactory.createURI("http://example.com/p");
Path path = new P_Link( p );

// JENA-1739 fails here
new UpdateBuilder().addDelete( "?s", "<x>", "?p")
.addWhere( "?s", path, "?p").build();
}

@Test
public void testPathInOptionalClause() {
Node p = NodeFactory.createURI("http://example.com/p");
Path path = new P_Link( p );

// JENA-1739 fails here
new UpdateBuilder().addDelete( "?s", "<x>", "?p")
.addOptional( "?s", path, "?p").build();
}
}

0 comments on commit 56b3cfc

Please sign in to comment.