Search in sources :

Example 1 with Element

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

the class AbstractTestUpdateGraph method testInsert4.

@Test
public void testInsert4() {
    DatasetGraph gStore = getEmptyDatasetGraph();
    defaultGraphData(gStore, graph1);
    UpdateModify insert = new UpdateModify();
    insert.getInsertAcc().addTriple(SSE.parseTriple("(?s <http://example/p> 1066)"));
    Element element = QueryFactory.createElement("{ ?s <http://example/p> 2007 }");
    insert.setElement(element);
    UpdateAction.execute(insert, gStore);
    assertTrue(graphContains(gStore.getDefaultGraph(), triple2));
}
Also used : Element(org.apache.jena.sparql.syntax.Element) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 2 with Element

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

the class AbstractTestUpdateGraph method testModify1.

@Test
public void testModify1() {
    DatasetGraph gStore = getEmptyDatasetGraph();
    defaultGraphData(gStore, data2());
    namedGraphData(gStore, graphIRI, Factory.createDefaultGraph());
    UpdateModify modify = new UpdateModify();
    Element element = QueryFactory.createElement("{ ?s <http://example/p> ?o }");
    modify.setElement(element);
    modify.getInsertAcc().addQuad(new Quad(graphIRI, triple1));
    modify.getDeleteAcc().addTriple(SSE.parseTriple("(?s <http://example/p> ?o)"));
    modify.getDeleteAcc().addQuad(SSE.parseQuad("(<http://example/graph> ?s <http://example/p> ?o)"));
    UpdateAction.execute(modify, gStore);
    assertFalse(graphEmpty(gStore.getGraph(graphIRI)));
    assertTrue(graphEmpty(gStore.getDefaultGraph()));
    assertTrue(graphContains(gStore.getGraph(graphIRI), triple1));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Element(org.apache.jena.sparql.syntax.Element) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 3 with Element

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

the class ParserSPARQL10 method parseElement.

public static Element parseElement(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser10 parser) throws Exception {
            Element el = parser.GroupGraphPattern();
            query.setQueryPattern(el);
        }
    };
    perform(query, string, action);
    return query.getQueryPattern();
}
Also used : Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element) SPARQLParser10(org.apache.jena.sparql.lang.sparql_10.SPARQLParser10)

Example 4 with Element

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

the class ParserSPARQL11 method parseElement.

public static Element parseElement(String string) {
    final Query query = new Query();
    Action action = new Action() {

        @Override
        public void exec(SPARQLParser11 parser) throws Exception {
            Element el = parser.GroupGraphPattern();
            query.setQueryPattern(el);
        }
    };
    perform(query, string, action);
    return query.getQueryPattern();
}
Also used : SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element)

Example 5 with Element

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

the class QueryTransformOps method transform.

/** Transform a query using {@link ElementTransform} and {@link ExprTransform}.
     *  It is the responsibility of these transforms to transofmr to a legal SPARQL query.
     */
public static Query transform(Query query, ElementTransform transform, ExprTransform exprTransform) {
    Query q2 = QueryTransformOps.shallowCopy(query);
    // "Shallow copy with transform."
    transformVarExprList(q2.getProject(), exprTransform);
    transformVarExprList(q2.getGroupBy(), exprTransform);
    transformExprList(q2.getHavingExprs(), exprTransform);
    if (q2.getOrderBy() != null) {
        transformSortConditions(q2.getOrderBy(), exprTransform);
    }
    // ?? DOES NOT WORK: transformExprListAgg(q2.getAggregators(), exprTransform) ; ??
    // if ( q2.hasHaving() ) {}
    // if ( q2.hasAggregators() ) {}
    Element el = q2.getQueryPattern();
    Element el2 = ElementTransformer.transform(el, transform, exprTransform);
    // Top level is always a group.
    if (!(el2 instanceof ElementGroup)) {
        ElementGroup eg = new ElementGroup();
        eg.addElement(el2);
        el2 = eg;
    }
    q2.setQueryPattern(el2);
    return q2;
}
Also used : Query(org.apache.jena.query.Query) Element(org.apache.jena.sparql.syntax.Element) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Aggregations

Element (org.apache.jena.sparql.syntax.Element)21 Test (org.junit.Test)9 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)8 Query (org.apache.jena.query.Query)7 Quad (org.apache.jena.sparql.core.Quad)6 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)4 Node (org.apache.jena.graph.Node)3 Var (org.apache.jena.sparql.core.Var)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)3 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)2 Triple (org.apache.jena.graph.Triple)2 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)2 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)2 Update (org.apache.jena.update.Update)2 ContractTest (org.xenei.junit.contract.ContractTest)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 E_Random (org.apache.jena.sparql.expr.E_Random)1