Search in sources :

Example 1 with ASTModify

use of org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify in project rdf4j by eclipse.

the class DatasetDeclProcessor method process.

/**
 * Extracts a SPARQL {@link Dataset} from an ASTQueryContainer, if one is contained. Returns null
 * otherwise.
 *
 * @param qc
 *        The query model to resolve relative URIs in.
 * @throws MalformedQueryException
 *         If DatasetClause does not contain a valid URI.
 */
public static Dataset process(ASTOperationContainer qc) throws MalformedQueryException {
    SimpleDataset dataset = null;
    ASTOperation op = qc.getOperation();
    if (op != null) {
        List<ASTDatasetClause> datasetClauses = op.getDatasetClauseList();
        if (!datasetClauses.isEmpty()) {
            dataset = new SimpleDataset();
            for (ASTDatasetClause dc : datasetClauses) {
                ASTIRI astIri = dc.jjtGetChild(ASTIRI.class);
                try {
                    IRI uri = SESAME.NIL;
                    if (astIri != null) {
                        uri = SimpleValueFactory.getInstance().createIRI(astIri.getValue());
                    }
                    boolean withClause = false;
                    if (op instanceof ASTModify) {
                        if (dc.equals(((ASTModify) op).getWithClause())) {
                            withClause = true;
                            dataset.setDefaultInsertGraph(uri);
                            dataset.addDefaultRemoveGraph(uri);
                        }
                    }
                    // clauses.
                    if (!withClause || datasetClauses.size() == 1) {
                        if (dc.isNamed()) {
                            dataset.addNamedGraph(uri);
                        } else {
                            dataset.addDefaultGraph(uri);
                        }
                    }
                } catch (IllegalArgumentException e) {
                    throw new MalformedQueryException(e.getMessage(), e);
                }
            }
        }
    }
    return dataset;
}
Also used : ASTIRI(org.eclipse.rdf4j.query.parser.sparql.ast.ASTIRI) IRI(org.eclipse.rdf4j.model.IRI) ASTModify(org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify) ASTOperation(org.eclipse.rdf4j.query.parser.sparql.ast.ASTOperation) ASTDatasetClause(org.eclipse.rdf4j.query.parser.sparql.ast.ASTDatasetClause) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) SimpleDataset(org.eclipse.rdf4j.query.impl.SimpleDataset) ASTIRI(org.eclipse.rdf4j.query.parser.sparql.ast.ASTIRI)

Example 2 with ASTModify

use of org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify in project rdf4j by eclipse.

the class UpdateExprBuilder method visit.

@Override
public Modify visit(ASTModify node, Object data) throws VisitorException {
    ASTWhereClause whereClause = node.getWhereClause();
    TupleExpr where = null;
    if (whereClause != null) {
        where = (TupleExpr) whereClause.jjtAccept(this, data);
    }
    TupleExpr delete = null;
    ASTDeleteClause deleteNode = node.getDeleteClause();
    if (deleteNode != null) {
        delete = (TupleExpr) deleteNode.jjtAccept(this, data);
    }
    TupleExpr insert = null;
    ASTInsertClause insertNode = node.getInsertClause();
    if (insertNode != null) {
        insert = (TupleExpr) insertNode.jjtAccept(this, data);
    }
    Modify modifyExpr = new Modify(delete, insert, where);
    return modifyExpr;
}
Also used : ASTWhereClause(org.eclipse.rdf4j.query.parser.sparql.ast.ASTWhereClause) ASTDeleteClause(org.eclipse.rdf4j.query.parser.sparql.ast.ASTDeleteClause) Modify(org.eclipse.rdf4j.query.algebra.Modify) ASTModify(org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr) ASTInsertClause(org.eclipse.rdf4j.query.parser.sparql.ast.ASTInsertClause)

Aggregations

ASTModify (org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify)2 IRI (org.eclipse.rdf4j.model.IRI)1 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 Modify (org.eclipse.rdf4j.query.algebra.Modify)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 SimpleDataset (org.eclipse.rdf4j.query.impl.SimpleDataset)1 ASTDatasetClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTDatasetClause)1 ASTDeleteClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTDeleteClause)1 ASTIRI (org.eclipse.rdf4j.query.parser.sparql.ast.ASTIRI)1 ASTInsertClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTInsertClause)1 ASTOperation (org.eclipse.rdf4j.query.parser.sparql.ast.ASTOperation)1 ASTWhereClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTWhereClause)1