use of org.apache.jena.graph.Graph in project jena by apache.
the class TestAPI method testARQConstructQuad_bnodes.
@Test
public void testARQConstructQuad_bnodes() {
String queryString = "PREFIX : <http://example/> CONSTRUCT { :s :p :o GRAPH _:a { :s :p :o1 } } WHERE { }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Dataset ds = qExec.execConstructDataset();
assertEquals(1, Iter.count(ds.asDatasetGraph().listGraphNodes()));
Node n = ds.asDatasetGraph().listGraphNodes().next();
assertTrue(n.isBlank());
Graph g = ds.asDatasetGraph().getGraph(n);
assertNotNull(g);
assertFalse(g.isEmpty());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestAssemblerGroup method assertMemoryModel.
protected void assertMemoryModel(Object object) {
if (object instanceof Model) {
Graph g = ((Model) object).getGraph();
assertInstanceOf(GraphMemBase.class, g);
} else
fail("expected a Model, but got a " + object.getClass());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class AbstractTripleBlankNodeTests method writeTuples.
@Override
protected void writeTuples(File f, List<Triple> tuples) throws FileNotFoundException {
Graph g = GraphFactory.createGraphMem();
for (Triple t : tuples) {
g.add(t);
}
RDFDataMgr.write(new FileOutputStream(f), g, getLanguage());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestEmbeddedFuseki method embedded_04.
@Test
public void embedded_04() {
DatasetGraph dsg = dataset();
Txn.executeWrite(dsg, () -> {
Quad q = SSE.parseQuad("(_ :s :p _:b)");
dsg.add(q);
});
// A service with just being able to do quads operations
// That is, GET, POST, PUT on "/data" in N-quads and TriG.
DataService dataService = new DataService(dsg);
dataService.addEndpoint(OperationName.Quads_RW, "");
dataService.addEndpoint(OperationName.Query, "");
dataService.addEndpoint(OperationName.Update, "");
int port = FusekiLib.choosePort();
FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
server.start();
try {
// Put data in.
String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
Graph g = SSE.parseGraph(data);
HttpEntity e = graphToHttpEntity(g);
HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
// Get data out.
try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
Graph g2 = GraphFactory.createDefaultGraph();
RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
assertTrue(g.isIsomorphicWith(g2));
}
// Query.
query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(3, x);
});
// Update
UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
// Query again.
query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
ResultSet rs = qExec.execSelect();
int x = ResultSetFormatter.consume(rs);
assertEquals(0, x);
});
} finally {
server.stop();
}
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class TestConnectionPooled method reuseJDBCConection.
@Test
public void reuseJDBCConection() {
Triple t1 = SSE.parseTriple("(:x1 :p :z)");
Triple t2 = SSE.parseTriple("(:x2 :p :z)");
boolean explicitTransactions = false;
// Make store.
{
SDBConnection sConn1 = SDBConnectionFactory.create(conn);
Store store1 = StoreFactory.create(sConn1, store.getLayoutType(), store.getDatabaseType());
if (explicitTransactions)
store1.getConnection().getTransactionHandler().begin();
Graph graph1 = SDBFactory.connectDefaultGraph(store1);
graph1.add(t1);
assertTrue(graph1.contains(t1));
if (explicitTransactions) {
store1.getConnection().getTransactionHandler().commit();
assertTrue(graph1.contains(t1));
}
//store1.close() ;
}
// Mythically return conn to the pool.
// Get from pool
// i.e. same connection. Make a store around it
{
SDBConnection sConn2 = SDBConnectionFactory.create(conn);
Store store2 = StoreFactory.create(sConn2, store.getLayoutType(), store.getDatabaseType());
if (explicitTransactions)
store2.getConnection().getTransactionHandler().begin();
Graph graph2 = SDBFactory.connectDefaultGraph(store2);
assertTrue(graph2.contains(t1));
graph2.add(t2);
assertTrue(graph2.contains(t2));
if (explicitTransactions)
store2.getConnection().getTransactionHandler().commit();
//store2.close() ;
}
System.exit(0);
}
Aggregations