use of org.apache.jena.sparql.core.Var in project jena by apache.
the class BuilderNode method buildVars.
public static List<Var> buildVars(ItemList list) {
list = BuilderLib.skipTag(list, Tags.tagVars);
List<Var> x = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Item item = list.get(i);
Var var = BuilderNode.buildVar(item);
x.add(Var.alloc(item.getNode()));
}
return x;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class BuilderNode method buildVarList.
public static List<Var> buildVarList(ItemList list) {
if (list.size() > 0 && list.getFirst().isSymbol(Tags.tagVars))
list = list.cdr();
List<Var> vars = new ArrayList<>();
for (Item x : list) {
Var v = buildVar(x);
vars.add(v);
}
return vars;
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class UpdateBuilderTest method testInsertAndDeleteWithVar.
@Test
public void testInsertAndDeleteWithVar() {
UpdateBuilder builder = new UpdateBuilder();
Var v = Var.alloc("v");
builder.addInsert(new Quad(g, s, v, o));
builder.addDelete(new Triple(s, v, o));
builder.addWhere(null, v, "foo");
builder.setVar(v, p);
Update update = builder.build();
assertTrue(update instanceof UpdateModify);
UpdateModify um = (UpdateModify) update;
List<Quad> quads = um.getInsertQuads();
assertEquals(1, quads.size());
Quad q = quads.get(0);
assertEquals(g, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
quads = um.getDeleteQuads();
assertEquals(1, quads.size());
q = quads.get(0);
assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
Element e = um.getWherePattern();
assertTrue(e instanceof ElementGroup);
ElementGroup eg = (ElementGroup) e;
assertEquals(1, eg.getElements().size());
ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
Triple t = epb.getPattern().get(0).asTriple();
assertEquals(Node.ANY, t.getSubject());
assertEquals(p, t.getPredicate());
assertEquals(builder.makeNode("foo"), t.getObject());
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SelectClauseTest method testAddVarNode.
@ContractTest
public void testAddVarNode() throws Exception {
Var v = Var.alloc("one");
SelectClause<?> selectClause = getProducer().newInstance();
selectClause.addVar("one");
Query query = getQuery(selectClause.addVar(NodeFactory.createVariable("one")));
VarExprList expr = query.getProject();
assertEquals(1, expr.size());
assertTrue(expr.contains(v));
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SelectClauseTest method testAddVarString.
@ContractTest
public void testAddVarString() throws Exception {
Var v = Var.alloc("one");
SelectClause<?> selectClause = getProducer().newInstance();
selectClause.addVar("one");
Query query = getQuery(selectClause.addVar("one"));
VarExprList expr = query.getProject();
assertEquals(1, expr.size());
assertTrue(expr.contains(v));
}
Aggregations