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