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));
}
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));
}
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();
}
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();
}
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;
}
Aggregations