Search in sources :

Example 21 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddOptionalTriple.

@ContractTest
public void testAddOptionalTriple() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addOptional(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
    epb.addTriple(t);
    WhereValidator visitor = new WhereValidator(optional);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 22 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddMinus.

@ContractTest
public void testAddMinus() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addMinus(sb);
    Query query = builder.build();
    ElementPathBlock epb = new ElementPathBlock();
    ElementMinus minus = new ElementMinus(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    WhereValidator visitor = new WhereValidator(minus);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementMinus(org.apache.jena.sparql.syntax.ElementMinus) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 23 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddOptionalString.

@ContractTest
public void testAddOptionalString() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addOptional("<one>", "<two>", "three");
    ElementPathBlock epb = new ElementPathBlock();
    ElementOptional optional = new ElementOptional(epb);
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
    epb.addTriple(t);
    WhereValidator visitor = new WhereValidator(optional);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementOptional(org.apache.jena.sparql.syntax.ElementOptional) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 24 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddWhereStrings.

@ContractTest
public void testAddWhereStrings() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere("<one>", "<two>", "three");
    ElementPathBlock epb = new ElementPathBlock();
    Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
    epb.addTriple(t);
    WhereValidator visitor = new WhereValidator(epb);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 25 with ElementPathBlock

use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.

the class WhereClauseTest method testAddSubQuery.

@ContractTest
public void testAddSubQuery() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "urn:uri:").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
    Query query = builder.build();
    Query q2 = new Query();
    q2.setQuerySelectType();
    q2.addProjectVars(Arrays.asList(Var.alloc("x")));
    ElementPathBlock epb = new ElementPathBlock();
    q2.setQueryPattern(epb);
    epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("urn:uri:one"), NodeFactory.createURI("urn:uri:two"), NodeFactory.createURI("urn:uri:three"))));
    ElementSubQuery esq = new ElementSubQuery(q2);
    WhereValidator visitor = new WhereValidator(esq);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) FrontsTriple(org.apache.jena.graph.FrontsTriple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)78 Triple (org.apache.jena.graph.Triple)62 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)60 TriplePath (org.apache.jena.sparql.core.TriplePath)56 Test (org.junit.Test)44 Query (org.apache.jena.query.Query)32 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)27 Node (org.apache.jena.graph.Node)26 ContractTest (org.xenei.junit.contract.ContractTest)25 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)22 FrontsTriple (org.apache.jena.graph.FrontsTriple)22 ElementOptional (org.apache.jena.sparql.syntax.ElementOptional)18 Var (org.apache.jena.sparql.core.Var)14 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)11 Element (org.apache.jena.sparql.syntax.Element)10 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)8 ExprVar (org.apache.jena.sparql.expr.ExprVar)7 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)7 Quad (org.apache.jena.sparql.core.Quad)5 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)5