use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph5.
@Test
public void mrswGraph5() {
Dataset d = TDBFactory.createDataset();
Model m = d.getNamedModel("http://example");
GraphUtil.addInto(m.getGraph(), buildGraph());
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
while (iter1.hasNext()) iter1.next();
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().delete(t);
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph4.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph4() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listLiteralStatements(r, null, 1);
assertNotNull(iter1.next());
// and now the iterator has implicitly finished.
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().add(t);
// Bad - modification of the dataset occurred.
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestConcurrentAccess method mrswGraph2.
@Test(expected = ConcurrentModificationException.class)
public void mrswGraph2() {
Model m = create().getDefaultModel();
Resource r = m.createResource("x");
ExtendedIterator<Statement> iter1 = m.listStatements(r, null, (RDFNode) null);
assertNotNull(iter1.next());
Triple t = SSE.parseTriple("(<y> <p> 99)");
m.getGraph().add(t);
// Bad
iter1.hasNext();
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class ModelHelper method statements.
// /**
// * Create an array of Statements parsed from a semi-separated string.
// *
// * @param lockModel
// * a model to serve as a statement factory
// * @param facts
// * a sequence of semicolon-separated "S P O" facts
// * @return a Statement[] of the (S P O) statements from the string
// */
// public static Statement[] statements(Model m, String facts) {
// ArrayList<Statement> sl = new ArrayList<Statement>();
// StringTokenizer st = new StringTokenizer(facts, ";");
// while (st.hasMoreTokens())
// sl.add(statement(m, st.nextToken()));
// return sl.toArray(new Statement[sl.size()]);
// }
/**
* Create an array of Statements parsed from a semi-separated string.
*
* @param facts
* a sequence of semicolon-separated "S P O" facts
* @return a Statement[] of the (S P O) statements from the string
*/
public static Statement[] statements(String facts) {
ArrayList<Statement> sl = new ArrayList<>();
StringTokenizer st = new StringTokenizer(facts, ";");
while (st.hasMoreTokens()) sl.add(statement(st.nextToken()));
return sl.toArray(new Statement[sl.size()]);
}
use of org.apache.jena.rdf.model.Statement in project jena by apache.
the class TestInMemDatasetAssembler method directDataLinkToQuads.
@Test
public void directDataLinkToQuads() throws IOException {
// first make a file of quads to load later
final Model model = createDefaultModel();
final Path quads = createTempFile("quadExample", ".nq");
final Resource quadsURI = model.createResource(quads.toFile().toURI().toString());
final Resource simpleExample = model.createResource("test:simpleExample");
simpleExample.addProperty(type, DatasetAssemblerVocab.tDatasetTxnMem);
simpleExample.addProperty(data, quadsURI);
final DatasetGraph dsg = createTxnMem().asDatasetGraph();
model.listStatements().mapWith(Statement::asTriple).mapWith(t -> new Quad(quadsURI.asNode(), t)).forEachRemaining(dsg::add);
try (OutputStream out = new FileOutputStream(quads.toFile())) {
write(out, dsg, NQUADS);
}
final Dataset dataset = assemble(simpleExample);
final Model assembledDefaultModel = dataset.getDefaultModel();
final Model assembledNamedModel = dataset.getNamedModel(quadsURI.getURI());
assertTrue(assembledDefaultModel.isEmpty());
assertTrue(assembledNamedModel.contains(assembledNamedModel.createStatement(simpleExample, data, quadsURI)));
}
Aggregations