use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class ExQuadFilter method setup.
/** Example setup - in-memory dataset with two graphs, one triple in each */
private static Dataset setup() {
Dataset ds = TDBFactory.createDataset();
DatasetGraph dsg = ds.asDatasetGraph();
Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)");
Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)");
dsg.add(q1);
dsg.add(q2);
return ds;
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class IsoMatcher method tuplesQuads.
private static List<Tuple<Node>> tuplesQuads(Iterator<Quad> iter) {
List<Tuple<Node>> tuples = new ArrayList<>();
for (; iter.hasNext(); ) {
Quad q = iter.next();
Tuple<Node> tuple = tuple(q.getGraph(), q.getSubject(), q.getPredicate(), q.getObject());
tuples.add(tuple);
}
return tuples;
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractJenaConnectionTests method connection_statement_query_select_04.
/**
* Runs a SELECT query on a non-empty database and checks it returns
* non-empty results. Uses high compatibility level to ensure that column
* type detection doesn't consume the first row.
*
* @throws SQLException
*/
@Test
public void connection_statement_query_select_04() throws SQLException {
// Prepare a dataset
Dataset ds = DatasetFactory.createTxnMem();
ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createURI("http://example/object")));
// Work with the connection
JenaConnection conn = this.getConnection(ds);
conn.setJdbcCompatibilityLevel(JdbcCompatibility.HIGH);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }");
Assert.assertNotNull(rset);
Assert.assertFalse(rset.isClosed());
Assert.assertTrue(rset.isBeforeFirst());
// Check result set metadata
checkSelectMetadata(rset, 4);
// Should have a row
Assert.assertTrue(rset.next());
Assert.assertTrue(rset.isFirst());
Assert.assertEquals(1, rset.getRow());
// Should be no further rows
Assert.assertFalse(rset.next());
Assert.assertTrue(rset.isAfterLast());
Assert.assertFalse(rset.isClosed());
// Close things
rset.close();
Assert.assertTrue(rset.isClosed());
stmt.close();
Assert.assertTrue(stmt.isClosed());
conn.close();
Assert.assertTrue(conn.isClosed());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class AbstractJenaConnectionTests method connection_statement_query_select_02.
/**
* Runs a SELECT query on a non-empty database and checks it returns
* non-empty results
*
* @throws SQLException
*/
@Test
public void connection_statement_query_select_02() throws SQLException {
// Prepare a dataset
Dataset ds = DatasetFactory.createTxnMem();
ds.asDatasetGraph().add(new Quad(NodeFactory.createURI("http://example/graph"), NodeFactory.createURI("http://example/subject"), NodeFactory.createURI("http://example/predicate"), NodeFactory.createURI("http://example/object")));
// Work with the connection
JenaConnection conn = this.getConnection(ds);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * WHERE { GRAPH ?g { ?s ?p ?o } }");
Assert.assertNotNull(rset);
Assert.assertFalse(rset.isClosed());
Assert.assertTrue(rset.isBeforeFirst());
// Check result set metadata
checkSelectMetadata(rset, 4);
// Should have a row
Assert.assertTrue(rset.next());
Assert.assertTrue(rset.isFirst());
Assert.assertEquals(1, rset.getRow());
// Should be no further rows
Assert.assertFalse(rset.next());
Assert.assertTrue(rset.isAfterLast());
Assert.assertFalse(rset.isClosed());
// Close things
rset.close();
Assert.assertTrue(rset.isClosed());
stmt.close();
Assert.assertTrue(stmt.isClosed());
conn.close();
Assert.assertTrue(conn.isClosed());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class PatternTable method process.
// Start a table from the i'th quad
// Must remove the quad at index i if return is not null.
public SqlStage process(int i, QuadBlock quadBlock) {
QuadBlock tableQuads = new QuadBlock();
Set<Node> predicates = new HashSet<Node>(cols.keySet());
// Use the fact that i'th quad is the trigger
Quad trigger = quadBlock.get(i);
Node subject = trigger.getSubject();
Node graph = trigger.getGraph();
for (Node p : predicates) {
int idx = quadBlock.findFirst(i, graph, subject, p, null);
if (idx < 0)
// Liberal - any predicates
continue;
Quad q = quadBlock.get(idx);
tableQuads.add(q);
}
quadBlock.removeAll(tableQuads);
SqlStagePatternTable stage = new SqlStagePatternTable(graph, subject, tableQuads);
return stage;
}
Aggregations