use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class TupleLib method quad.
private static Quad quad(NodeTable nodeTable, NodeId g, NodeId s, NodeId p, NodeId o) {
Node gNode = nodeTable.getNodeForNodeId(g);
Node sNode = nodeTable.getNodeForNodeId(s);
Node pNode = nodeTable.getNodeForNodeId(p);
Node oNode = nodeTable.getNodeForNodeId(o);
if (gNode == null)
throw new InternalErrorException("Invalid id node for graph (null node): " + fmt(g, s, p, o));
if (sNode == null)
throw new InternalErrorException("Invalid id node for subject (null node): " + fmt(g, s, p, o));
if (pNode == null)
throw new InternalErrorException("Invalid id node for predicate (null node): " + fmt(g, s, p, o));
if (oNode == null)
throw new InternalErrorException("Invalid id node for object (null node): " + fmt(g, s, p, o));
return Quad.create(gNode, sNode, pNode, oNode);
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class PageBlockMgr method promoteInPlace.
/**
* Promote a page to be writable in-place (block id does not change, hence page does not change id).
*/
public void promoteInPlace(Page page) {
Block block = page.getBackingBlock();
block.getByteBuffer().rewind();
Block block2 = blockMgr.promote(block);
block2.setReadOnly(false);
if (block2.getId() != block.getId())
throw new InternalErrorException("Block id changed");
if (block2 == block)
return;
// Change - reset Block in page.
// The details should not have changed.
// page.reset(block2);
}
use of org.apache.jena.atlas.lib.InternalErrorException in project jena by apache.
the class ShexValidationTest method run.
@Override
public void run() {
Graph graph = RDFDataMgr.loadGraph(data.getURI());
try {
if (ShexTests.dumpTest)
describeTest();
ShexReport report;
switch(this.testType) {
case ShapeFocus:
report = ShexValidator.get().validate(graph, shapes, shape, focus);
break;
case ShapeMap:
report = ShexValidator.get().validate(graph, shapes, shapeMap);
break;
case StartFocus:
{
ShexShape startShape = shapes.getStart();
report = ShexValidator.get().validate(graph, shapes, startShape, focus);
break;
}
default:
throw new InternalErrorException("No test type");
}
boolean b = (positiveTest == report.conforms());
if (!b) {
if (!ShexTests.dumpTest)
describeTest();
}
assertEquals(entry.getName(), positiveTest, report.conforms());
} catch (java.lang.AssertionError ex) {
throw ex;
} catch (Throwable ex) {
describeTest();
System.out.println("Exception: " + ex.getMessage());
if (!(ex instanceof Error))
ex.printStackTrace(System.out);
else
System.out.println(ex.getClass().getName());
Shex.printSchema(shapes);
throw ex;
}
}
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 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