use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class QuadBlockCompilerMain method compile.
//@Override
@Override
public final SqlNode compile(QuadBlock quads) {
SqlNode sqlNode = slotCompiler.start(quads);
// Copy it because it's modified.
quads = new QuadBlock(quads);
// ---- Stage builder
SqlStageList sList = new SqlStageList();
// Potential concurrent modification - need to use an explicit index.
for (int i = 0; i < quads.size(); ) {
Quad q = quads.get(i);
if (patternTable != null && patternTable.trigger(q)) {
// Removes current quad
SqlStage stage = patternTable.process(i, quads);
if (stage != null) {
if (quads.get(i) == q)
throw new SDBInternalError("Pattern table returned a stage but did not remove the first quad");
sList.add(stage);
continue;
}
}
sList.add(new SqlStageBasicQuad(q));
i++;
}
// ---- and now turn the stages into SqlNodes
SqlNode sqlStages = sList.build(request, slotCompiler);
// --- Join the initial node (constants).
sqlNode = SqlBuilder.innerJoin(request, sqlNode, sqlStages);
sqlNode = slotCompiler.finish(sqlNode, quads);
// Insert DISTINCT if accessing the RDF merge of all named graphs
// An RDF Merge is the DISTINCT results of query over the union of all graphs.
// Or in TransformSDB
boolean needDistinct = false;
// Either it's the uniongraph ...
if (quads.getGraphNode().equals(Quad.unionGraph))
needDistinct = true;
else // Or it's the union graph via redirected defaultGraph
if (Quad.isDefaultGraphGenerated(quads.getGraphNode()) && request.getContext().isTrue(SDB.unionDefaultGraph))
needDistinct = true;
if (needDistinct) {
// DISTINCT -- over the named variables but not * (which includes the graph node).
String renameName = request.genId("A");
//sqlNode = SqlRename.view(renameName, sqlNode) ;
sqlNode = SqlBuilder.view(request, sqlNode);
sqlNode = SqlBuilder.distinct(request, sqlNode);
}
return sqlNode;
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class QBR_SubType method rewrite.
@Override
public QuadBlock rewrite(SDBRequest request, QuadBlock quadBlock) {
if (!quadBlock.contains(null, null, rdfType, null))
return quadBlock;
quadBlock = new QuadBlock(quadBlock);
int i = 0;
// Better/clearer : do as copy over from one block to another.
while ((i = quadBlock.findFirst(i, null, null, rdfType, null)) != -1) {
// { :s rdf:type :C } => { :s rdf:type ?V . ?V rdfs:subClassOf :C }
Quad rdfTypeQuad = quadBlock.get(i);
Var var = request.genVar();
Quad q1 = new Quad(rdfTypeQuad.getGraph(), rdfTypeQuad.getSubject(), rdfType, var);
Quad q2 = new Quad(rdfTypeQuad.getGraph(), var, RDFS.subClassOf.asNode(), rdfTypeQuad.getObject());
// replace rdf:type statement
quadBlock.set(i, q1);
// add subClassOf statement
quadBlock.add(i + 1, q2);
// Skip the two statements.
i = i + 2;
}
return quadBlock;
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class T_QuadsObjectIsNull method dump.
private static void dump(DatasetGraphTransaction dsg) {
dsg.begin(ReadWrite.READ);
Iterator<Quad> iter = dsg.find();
for (; iter.hasNext(); ) {
Quad q = iter.next();
System.out.println(q);
}
//RiotWriter.writeNQuads(System.out, dsg) ;
dsg.commit();
dsg.end();
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestConcurrentAccess method mrswDataset1.
@Test(expected = ConcurrentModificationException.class)
public void mrswDataset1() {
DatasetGraph dsg = create().asDatasetGraph();
Quad quad = SSE.parseQuad("(<g> <y> <p> 99)");
Iterator<Quad> iter = dsg.find();
dsg.add(quad);
// Bad - after an update.
iter.hasNext();
iter.next();
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestConcurrentAccess method mrswSPARQL1.
@Test
public void mrswSPARQL1() {
Dataset ds = create();
Query query = QueryFactory.create("SELECT * { ?s ?p ?o}");
try (QueryExecution qExec = QueryExecutionFactory.create(query, ds)) {
ResultSet rs = qExec.execSelect();
while (rs.hasNext()) rs.next();
}
DatasetGraph dsg = ds.asDatasetGraph();
Quad quad = SSE.parseQuad("(<g> <y> <p> 99)");
dsg.add(quad);
Iterator<Quad> iter = dsg.find();
iter.hasNext();
iter.next();
}
Aggregations