Search in sources :

Example 1 with QueryBuildException

use of org.apache.jena.query.QueryBuildException in project jena by apache.

the class SPARQL_Update method execute.

private void execute(HttpAction action, InputStream input) {
    // OPTIONS
    if (action.request.getMethod().equals(HttpNames.METHOD_OPTIONS)) {
        // Share with update via SPARQL_Protocol.
        doOptions(action);
        return;
    }
    UsingList usingList = processProtocol(action.request);
    // If the dsg is transactional, then we can parse and execute the update in a streaming fashion.
    // If it isn't, we need to read the entire update request before performing any updates, because
    // we have to attempt to make the request atomic in the face of malformed updates
    UpdateRequest req = null;
    if (!action.isTransactional()) {
        try {
            req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
        } catch (UpdateException ex) {
            ServletOps.errorBadRequest(ex.getMessage());
            return;
        } catch (QueryParseException ex) {
            ServletOps.errorBadRequest(messageForQueryException(ex));
            return;
        }
    }
    action.beginWrite();
    try {
        if (req == null)
            UpdateAction.parseExecute(usingList, action.getActiveDSG(), input, UpdateParseBase, Syntax.syntaxARQ);
        else
            UpdateAction.execute(req, action.getActiveDSG());
        action.commit();
    } catch (UpdateException ex) {
        action.abort();
        incCounter(action.getEndpoint().getCounters(), UpdateExecErrors);
        ServletOps.errorOccurred(ex.getMessage());
    } catch (QueryParseException | QueryBuildException ex) {
        action.abort();
        // Counter inc'ed further out.
        ServletOps.errorBadRequest(messageForQueryException(ex));
    } catch (Throwable ex) {
        if (!(ex instanceof ActionErrorException)) {
            try {
                action.abort();
            } catch (Exception ex2) {
            }
            ServletOps.errorOccurred(ex.getMessage(), ex);
        }
    } finally {
        action.endWrite();
    }
}
Also used : UsingList(org.apache.jena.sparql.modify.UsingList) UpdateRequest(org.apache.jena.update.UpdateRequest) QueryBuildException(org.apache.jena.query.QueryBuildException) UpdateException(org.apache.jena.update.UpdateException) ServletException(javax.servlet.ServletException) QueryParseException(org.apache.jena.query.QueryParseException) QueryBuildException(org.apache.jena.query.QueryBuildException) IOException(java.io.IOException) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 2 with QueryBuildException

use of org.apache.jena.query.QueryBuildException in project jena by apache.

the class ValuesHandlerTest method twoVarOneData.

@Test
public void twoVarOneData() {
    Node n = NodeFactory.createLiteral("hello");
    Var v = Var.alloc("x");
    Var v2 = Var.alloc("y");
    handler.addValueVar(v, Arrays.asList(n));
    handler.addValueVar(v2, null);
    try {
        handler.build();
        fail("Shoud have thrown QueryBuildException");
    } catch (QueryBuildException expected) {
    // do nothing.
    }
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryBuildException(org.apache.jena.query.QueryBuildException) Test(org.junit.Test)

Example 3 with QueryBuildException

use of org.apache.jena.query.QueryBuildException in project jena by apache.

the class ValuesHandler method build.

@Override
public void build() {
    // remove all the vars that have been set
    List<Var> vars = new ArrayList<Var>(valuesTable.keySet());
    vars.removeAll(valueMap.keySet());
    if (vars.isEmpty()) {
        return;
    }
    List<Binding> bindings = new ArrayList<Binding>();
    int count = valuesTable.get(vars.get(0)).size();
    for (int i = 0; i < count; i++) {
        BindingHashMap b = new BindingHashMap();
        for (Var var : vars) {
            List<Node> lst = valuesTable.get(var);
            // must be square
            if (lst.size() != count) {
                throw new QueryBuildException(String.format("The number of data items for %s (%s) is not the same as for %s (%s)", var, lst.size(), vars.get(0), count));
            }
            Node n = lst.get(i);
            if (n != null) {
                if (valueMap.containsKey(n)) {
                    n = valueMap.get(n);
                }
                b.add(var, n);
            }
        }
        if (!b.isEmpty()) {
            bindings.add(b);
        }
    }
    if (!bindings.isEmpty()) {
        query.setValuesDataBlock(vars, bindings);
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryBuildException(org.apache.jena.query.QueryBuildException) ArrayList(java.util.ArrayList) BindingHashMap(org.apache.jena.sparql.engine.binding.BindingHashMap)

Example 4 with QueryBuildException

use of org.apache.jena.query.QueryBuildException in project jena by apache.

the class TextQueryPF method build.

@Override
public void build(PropFuncArg argSubject, Node predicate, PropFuncArg argObject, ExecutionContext execCxt) {
    super.build(argSubject, predicate, argObject, execCxt);
    DatasetGraph dsg = execCxt.getDataset();
    textIndex = chooseTextIndex(execCxt, dsg);
    if (argSubject.isList()) {
        int size = argSubject.getArgListSize();
        if (size != 2 && size != 3) {
            throw new QueryBuildException("Subject has " + argSubject.getArgList().size() + " elements, not 2 or 3: " + argSubject);
        }
    }
    if (argObject.isList()) {
        List<Node> list = argObject.getArgList();
        if (list.size() == 0)
            throw new QueryBuildException("Zero-length argument list");
        if (list.size() > 4)
            throw new QueryBuildException("Too many arguments in list : " + list);
    }
}
Also used : QueryBuildException(org.apache.jena.query.QueryBuildException) Node(org.apache.jena.graph.Node)

Aggregations

QueryBuildException (org.apache.jena.query.QueryBuildException)4 Node (org.apache.jena.graph.Node)3 Var (org.apache.jena.sparql.core.Var)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 BindingHashMap (org.apache.jena.sparql.engine.binding.BindingHashMap)1 UsingList (org.apache.jena.sparql.modify.UsingList)1 UpdateException (org.apache.jena.update.UpdateException)1 UpdateRequest (org.apache.jena.update.UpdateRequest)1 Test (org.junit.Test)1