Search in sources :

Example 1 with ASTWhereClause

use of org.eclipse.rdf4j.query.parser.sparql.ast.ASTWhereClause 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)

Example 2 with ASTWhereClause

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

the class WildcardProjectionProcessor method process.

public static void process(ASTOperationContainer container) throws MalformedQueryException {
    ASTOperation operation = container.getOperation();
    // scan for nested SELECT clauses in the operation's WHERE clause
    if (operation != null) {
        ASTWhereClause whereClause = operation.getWhereClause();
        // DESCRIBE queries and certain update operations can be without a WHERE clause
        if (whereClause != null) {
            SelectClauseCollector collector = new SelectClauseCollector();
            try {
                whereClause.jjtAccept(collector, null);
                Set<ASTSelect> selectClauses = collector.getSelectClauses();
                for (ASTSelect selectClause : selectClauses) {
                    if (selectClause.isWildcard()) {
                        ASTSelectQuery q = (ASTSelectQuery) selectClause.jjtGetParent();
                        addQueryVars(q.getWhereClause(), selectClause);
                        selectClause.setWildcard(false);
                    }
                }
            } catch (VisitorException e) {
                throw new MalformedQueryException(e);
            }
        }
    }
    if (operation instanceof ASTSelectQuery) {
        // check for wildcard in upper SELECT query
        ASTSelectQuery selectQuery = (ASTSelectQuery) operation;
        ASTSelect selectClause = selectQuery.getSelect();
        if (selectClause.isWildcard()) {
            addQueryVars(selectQuery.getWhereClause(), selectClause);
            selectClause.setWildcard(false);
        }
    } else if (operation instanceof ASTDescribeQuery) {
        // check for possible wildcard in DESCRIBE query
        ASTDescribeQuery describeQuery = (ASTDescribeQuery) operation;
        ASTDescribe describeClause = describeQuery.getDescribe();
        if (describeClause.isWildcard()) {
            addQueryVars(describeQuery.getWhereClause(), describeClause);
            describeClause.setWildcard(false);
        }
    }
}
Also used : ASTOperation(org.eclipse.rdf4j.query.parser.sparql.ast.ASTOperation) ASTWhereClause(org.eclipse.rdf4j.query.parser.sparql.ast.ASTWhereClause) MalformedQueryException(org.eclipse.rdf4j.query.MalformedQueryException) ASTSelectQuery(org.eclipse.rdf4j.query.parser.sparql.ast.ASTSelectQuery) VisitorException(org.eclipse.rdf4j.query.parser.sparql.ast.VisitorException) ASTDescribeQuery(org.eclipse.rdf4j.query.parser.sparql.ast.ASTDescribeQuery) ASTDescribe(org.eclipse.rdf4j.query.parser.sparql.ast.ASTDescribe) ASTSelect(org.eclipse.rdf4j.query.parser.sparql.ast.ASTSelect)

Aggregations

ASTWhereClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTWhereClause)2 MalformedQueryException (org.eclipse.rdf4j.query.MalformedQueryException)1 Modify (org.eclipse.rdf4j.query.algebra.Modify)1 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)1 ASTDeleteClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTDeleteClause)1 ASTDescribe (org.eclipse.rdf4j.query.parser.sparql.ast.ASTDescribe)1 ASTDescribeQuery (org.eclipse.rdf4j.query.parser.sparql.ast.ASTDescribeQuery)1 ASTInsertClause (org.eclipse.rdf4j.query.parser.sparql.ast.ASTInsertClause)1 ASTModify (org.eclipse.rdf4j.query.parser.sparql.ast.ASTModify)1 ASTOperation (org.eclipse.rdf4j.query.parser.sparql.ast.ASTOperation)1 ASTSelect (org.eclipse.rdf4j.query.parser.sparql.ast.ASTSelect)1 ASTSelectQuery (org.eclipse.rdf4j.query.parser.sparql.ast.ASTSelectQuery)1 VisitorException (org.eclipse.rdf4j.query.parser.sparql.ast.VisitorException)1