use of org.apache.jena.sparql.syntax.Element in project jena by apache.
the class WhereClauseTest method testBindExprVar.
@ContractTest
public void testBindExprVar() {
Var v = Var.alloc("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
builder.setVar(v, NodeFactory.createURI("three"));
Query q = builder.build();
ElementGroup eg = (ElementGroup) q.getQueryPattern();
List<Element> lst = eg.getElements();
assertEquals("Should only be one element", 1, lst.size());
assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
assertTrue("ElementGroup should be empty", etb.isEmpty());
}
use of org.apache.jena.sparql.syntax.Element in project jena by apache.
the class QuerySerializer method visitQueryPattern.
@Override
public void visitQueryPattern(Query query) {
if (query.getQueryPattern() != null) {
out.print("WHERE");
out.incIndent(BLOCK_INDENT);
out.newline();
Element el = query.getQueryPattern();
fmtElement.visitAsGroup(el);
//el.visit(fmtElement) ;
out.decIndent(BLOCK_INDENT);
out.newline();
}
}
use of org.apache.jena.sparql.syntax.Element in project jena by apache.
the class UpdateWriterVisitor method visit.
@Override
public void visit(UpdateModify update) {
out.ensureStartOfLine();
if (update.getWithIRI() != null) {
//out.ensureStartOfLine() ;
out.print("WITH ");
output(update.getWithIRI());
}
if (update.hasDeleteClause()) {
List<Quad> deleteQuads = update.getDeleteQuads();
out.ensureStartOfLine();
out.print("DELETE ");
outputQuadsBraced(deleteQuads);
}
if (update.hasInsertClause()) {
List<Quad> insertQuads = update.getInsertQuads();
out.ensureStartOfLine();
out.print("INSERT ");
outputQuadsBraced(insertQuads);
}
if (!update.hasInsertClause() && !update.hasDeleteClause()) {
// Fake a clause to make it legal syntax.
out.ensureStartOfLine();
out.println("INSERT { }");
}
for (Node x : update.getUsing()) {
out.ensureStartOfLine();
out.print("USING ");
output(x);
}
for (Node x : update.getUsingNamed()) {
out.ensureStartOfLine();
out.print("USING NAMED ");
output(x);
}
Element el = update.getWherePattern();
out.ensureStartOfLine();
out.print("WHERE");
out.incIndent(BLOCK_INDENT);
out.newline();
if (el != null) {
FormatterElement fmtElement = prepareElementFormatter();
fmtElement.visitAsGroup(el);
} else
out.print("{}");
out.decIndent(BLOCK_INDENT);
}
use of org.apache.jena.sparql.syntax.Element in project jena by apache.
the class ARQParserBase method createQueryPattern.
protected ElementGroup createQueryPattern(Template t) {
ElementGroup elg = new ElementGroup();
Map<Node, BasicPattern> graphs = t.getGraphPattern();
for (Node n : graphs.keySet()) {
Element el = new ElementPathBlock(graphs.get(n));
if (!Quad.defaultGraphNodeGenerated.equals(n)) {
ElementGroup e = new ElementGroup();
e.addElement(el);
el = new ElementNamedGraph(n, e);
}
elg.addElement(el);
}
return elg;
}
use of org.apache.jena.sparql.syntax.Element in project jena by apache.
the class ExprTransformNodeElement method transform.
@Override
public Expr transform(ExprFunctionOp funcOp, ExprList args, Op opArg) {
// Syntax phased only - ignore args and opArg
Element elt = funcOp.getElement();
Element elt1 = ElementTransformer.transform(elt, elementTransform, this, beforeVisitor, afterVisitor);
if (elt == elt1)
return funcOp;
else {
if (funcOp instanceof E_Exists)
return new E_Exists(elt1);
if (funcOp instanceof E_NotExists)
return new E_NotExists(elt1);
throw new InternalErrorException("Unknown ExprFunctionOp: " + funcOp.getFunctionSymbol());
}
}
Aggregations