Search in sources :

Example 1 with QuadAcc

use of org.apache.jena.sparql.modify.request.QuadAcc in project jena by apache.

the class QueryTransformOps method mutateConstruct.

// Transform CONSTRUCT query template
private static void mutateConstruct(Query query, Query query2, ElementTransform transform) {
    if (query.isConstructQuad()) {
        Template template = query.getConstructTemplate();
        List<Quad> quads = template.getQuads();
        QuadAcc accQuads = new QuadAcc();
        quads.forEach(quad1 -> {
            Quad quad2 = transform.transform(quad1);
            accQuads.addQuad(quad2);
        });
        Template template2 = new Template(accQuads);
        query2.setConstructTemplate(template2);
        return;
    }
    if (query.isConstructType()) {
        Template template = query.getConstructTemplate();
        List<Triple> triples = template.getBGP().getList();
        BasicPattern accTriple = new BasicPattern();
        triples.forEach(triple1 -> {
            Triple triple2 = transform.transform(triple1);
            accTriple.add(triple2);
        });
        Template template2 = new Template(accTriple);
        query2.setConstructTemplate(template2);
        return;
    }
}
Also used : Triple(org.apache.jena.graph.Triple) QuadAcc(org.apache.jena.sparql.modify.request.QuadAcc)

Example 2 with QuadAcc

use of org.apache.jena.sparql.modify.request.QuadAcc in project jena by apache.

the class UpdateBuilder method buildWhere.

// build updates with where clauses
private Update buildWhere() {
    UpdateModify retval = new UpdateModify();
    if (with != null) {
        Node graph = values.get(with);
        if (graph == null) {
            graph = with;
        }
        retval.setWithIRI(graph);
    }
    QuadAcc acc;
    Iterator<Quad> iter;
    if (!inserts.isEmpty()) {
        retval.setHasInsertClause(true);
        acc = retval.getInsertAcc();
        iter = getQuads(inserts);
        while (iter.hasNext()) {
            acc.addQuad(iter.next());
        }
    }
    if (!deletes.isEmpty()) {
        retval.setHasDeleteClause(true);
        acc = retval.getDeleteAcc();
        iter = getQuads(deletes);
        while (iter.hasNext()) {
            acc.addQuad(iter.next());
        }
    }
    retval.setElement(whereProcessor.setVars(values).build());
    return retval;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) UpdateModify(org.apache.jena.sparql.modify.request.UpdateModify) Node(org.apache.jena.graph.Node) QuadAcc(org.apache.jena.sparql.modify.request.QuadAcc)

Example 3 with QuadAcc

use of org.apache.jena.sparql.modify.request.QuadAcc in project jena by apache.

the class QueryTransformOps method mutateByQueryType.

// Do the result form part of the cloned query.
private static void mutateByQueryType(Query q2, ElementTransform transform, ExprTransform exprTransform) {
    switch(q2.queryType()) {
        case ASK:
            break;
        case CONSTRUCT:
            // case CONSTRUCT_QUADS :
            // Variables in CONSTRUCT template.
            Template template = q2.getConstructTemplate();
            QuadAcc acc = new QuadAcc();
            List<Quad> quads = template.getQuads();
            template.getQuads().forEach(q -> {
                Node g = transform(q.getGraph(), exprTransform);
                Node s = transform(q.getSubject(), exprTransform);
                Node p = transform(q.getPredicate(), exprTransform);
                Node o = transform(q.getObject(), exprTransform);
                acc.addQuad(Quad.create(g, s, p, o));
            });
            Template template2 = new Template(acc);
            q2.setConstructTemplate(template2);
            break;
        case DESCRIBE:
            // Variables in describe.
            mutateDescribeVar(q2.getProjectVars(), q2.getResultURIs(), exprTransform);
            break;
        case SELECT:
            mutateVarExprList(q2.getProject(), exprTransform);
            break;
        case CONSTRUCT_JSON:
            throw new UnsupportedOperationException("Transform of JSON template queries");
        case UNKNOWN:
            throw new JenaException("Unknown qu ery type");
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node) QuadAcc(org.apache.jena.sparql.modify.request.QuadAcc)

Aggregations

QuadAcc (org.apache.jena.sparql.modify.request.QuadAcc)3 Node (org.apache.jena.graph.Node)2 Triple (org.apache.jena.graph.Triple)1 RDFNode (org.apache.jena.rdf.model.RDFNode)1 JenaException (org.apache.jena.shared.JenaException)1 Quad (org.apache.jena.sparql.core.Quad)1 UpdateModify (org.apache.jena.sparql.modify.request.UpdateModify)1