use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class LibSDB method findTriples.
/** Find triples, in the default graph or a named graph. */
public static Iterator<Triple> findTriples(DatasetGraph dsg, Node g, Node s, Node p, Node o) {
if (Var.isVar(g))
throw new InternalErrorException("Graph node is a variable : " + g);
final Node vs = varOrConst(s, "s");
final Node vp = varOrConst(p, "p");
final Node vo = varOrConst(o, "o");
// Evaluate as an algebra expression
Triple triple = new Triple(vs, vp, vo);
BasicPattern pattern = new BasicPattern();
pattern.add(triple);
Op op = (g != null) ? new OpQuadPattern(g, pattern) : new OpBGP(pattern);
Plan plan = QueryEngineSDB.getFactory().create(op, dsg, BindingRoot.create(), null);
QueryIterator qIter = plan.iterator();
Iterator<Binding> iter;
if (SDB.getContext().isTrue(SDB.streamGraphAPI)) {
// Assumes iterator closed properly.
iter = qIter;
} else {
// ---- Safe version:
List<Binding> x = Iter.toList(qIter);
Iterator<Binding> qIter2 = x.iterator();
qIter.close();
iter = qIter2;
}
return Iter.map(iter, (b) -> bindingToTriple(vs, vp, vo, b));
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class TupleLib method triple.
private static Triple triple(NodeTable nodeTable, NodeId s, NodeId p, NodeId o) {
if (!NodeId.isConcrete(s))
throw new InternalErrorException("Invalid id for subject: " + fmt(s, p, o));
if (!NodeId.isConcrete(p))
throw new InternalErrorException("Invalid id for predicate: " + fmt(s, p, o));
if (!NodeId.isConcrete(o))
throw new InternalErrorException("Invalid id for object: " + fmt(s, p, o));
Node sNode = nodeTable.getNodeForNodeId(s);
if (sNode == null)
throw new InternalErrorException("Invalid id node for subject (null node): " + fmt(s, p, o));
Node pNode = nodeTable.getNodeForNodeId(p);
if (pNode == null) {
nodeTable.getNodeForNodeId(p);
throw new InternalErrorException("Invalid id node for predicate (null node): " + fmt(s, p, o));
}
Node oNode = nodeTable.getNodeForNodeId(o);
if (oNode == null)
throw new InternalErrorException("Invalid id node for object (null node): " + fmt(s, p, o));
return new Triple(sNode, pNode, oNode);
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class DatasetGraphInMemory method _commit.
private void _commit() {
withLock(systemLock, () -> {
quadsIndex().commit();
defaultGraph().commit();
quadsIndex().end();
defaultGraph().end();
if (transactionType().equals(WRITE)) {
if (version.get() != generation.get())
throw new InternalErrorException(String.format("Version=%d, Generation=%d", version.get(), generation.get()));
generation.incrementAndGet();
}
});
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class NodeTransformExpr method transform.
/** Transform node then create a {@link ExprVar} or {@link NodeValue}. */
private Expr transform(Node input) {
Node n = transform.apply(input);
if (n == null)
throw new InternalErrorException("NodeTransform creates a null");
if (!Var.isVar(n))
return NodeValue.makeNode(n);
String name = Var.alloc(n).getVarName();
return new ExprVar(n.getName());
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class SPARQL_QueryGeneral method datasetFromDescription.
/**
* Construct a Dataset based on a dataset description.
*/
protected static Dataset datasetFromDescription(HttpAction action, DatasetDescription datasetDesc) {
try {
if (datasetDesc == null)
return null;
if (datasetDesc.isEmpty())
return null;
List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
if (graphURLs.size() == 0 && namedGraphs.size() == 0)
return null;
Dataset dataset = DatasetFactory.createGeneral();
// ---- Default graph
{
Model model = ModelFactory.createDefaultModel();
for (String uri : graphURLs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Default graph URI is null or the empty string");
try {
//TODO Clearup - RIOT integration.
GraphLoadUtils.loadModel(model, uri, MaxTriples);
log.info(format("[%d] Load (default graph) %s", action.id, uri));
} catch (RiotException ex) {
log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
errorBadRequest("Failed to load URL " + uri);
}
}
dataset.setDefaultModel(model);
}
// ---- Named graphs
if (namedGraphs != null) {
for (String uri : namedGraphs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Named graph URI is null or the empty string");
try {
Model model = ModelFactory.createDefaultModel();
GraphLoadUtils.loadModel(model, uri, MaxTriples);
log.info(format("[%d] Load (named graph) %s", action.id, uri));
dataset.addNamedModel(uri, model);
} catch (RiotException ex) {
log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
errorBadRequest("Failed to load URL " + uri);
}
}
}
return dataset;
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
errorBadRequest("Parameter error: " + ex.getMessage());
return null;
}
}
Aggregations