use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestConnection method connection_1.
@Test
public void connection_1() {
SDBConnection conn1 = SDBFactory.createConnection(conn);
Store store1 = StoreFactory.create(storeDesc, conn1);
// Reset
store1.getTableFormatter().format();
SDBConnection conn2 = SDBFactory.createConnection(conn);
Store store2 = StoreFactory.create(storeDesc, conn2);
Model model1 = SDBFactory.connectDefaultModel(store1);
Model model2 = SDBFactory.connectDefaultModel(store2);
Resource s = model1.createResource();
Property p = model1.createProperty("http://example/p");
// These are autocommit so two stores should be OK (but not a good design paradigm)
model1.add(s, p, "model1");
model2.add(s, p, "model2");
assertEquals(2, model1.size());
assertEquals(2, model2.size());
assertTrue(model1.isIsomorphicWith(model2));
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestAssembler method model_5.
@Test
public void model_5() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xDft = assem.getResource("http://example/test#graphDft");
Store store = create(assem);
// Default graph: Check they are connected to the same place in the store
Model model2 = (Model) Assembler.general.open(xDft);
Model model3 = (Model) Assembler.general.open(xDft);
Resource s = model2.createResource();
Property p = model2.createProperty("http://example/p");
// Check two models connected to the same graph
Literal o2 = model2.createLiteral("xyz");
model2.add(s, p, o2);
assertTrue(model3.contains(s, p, o2));
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class TestAssembler method model_4.
@Test
public void model_4() {
Model assem = FileManager.get().loadModel(dir + "graph-assembler.ttl");
Resource xDft = assem.getResource("http://example/test#graphDft");
Resource xNamed = assem.getResource("http://example/test#graphNamed");
Store store = create(assem);
Model model1 = (Model) Assembler.general.open(xDft);
Model model2 = (Model) Assembler.general.open(xNamed);
// Check they are not connected to the same place in the store
Resource s = model1.createResource();
Property p = model1.createProperty("http://example/p");
Literal o = model1.createLiteral("foo");
model1.add(s, p, o);
assertTrue(model1.contains(s, p, o));
assertTrue(model1.size() == 1);
assertTrue(model2.size() == 0);
assertFalse(model1.isIsomorphicWith(model2));
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class T_TDBWriteTransaction method run.
public static void run(String location) {
if (false) {
Journal journal = Journal.create(Location.create(location));
JournalControl.print(journal);
journal.close();
}
//String location = args[0]; // + "/" + UUID.randomUUID().toString();
//String baseGraphName = "com.ibm.test.graphNamePrefix.";
long totalExecTime = 0L;
long size = 0;
Dataset dataset = TDBFactory.createDataset(location);
Dataset dataset1 = TDBFactory.createDataset(location);
if (bracketWithReader)
dataset1.begin(ReadWrite.READ);
for (int i = 0; i < TOTAL; i++) {
List<String> lastProcessedUris = new ArrayList<>();
for (int j = 0; j < 10 * i; j++) {
String lastProcessedUri = "http://test.net/xmlns/test/1.0/someUri" + j;
lastProcessedUris.add(lastProcessedUri);
}
//Dataset dataset = TDBFactory.createDataset(location);
//String graphName = baseGraphName + i;
long t = System.currentTimeMillis();
try {
dataset.begin(ReadWrite.WRITE);
Model m = dataset.getDefaultModel();
m.removeAll();
Resource subject = m.createResource(INDEX_INFO_SUBJECT);
Property predicate = m.createProperty(TIMESTAMP_PREDICATE);
m.addLiteral(subject, predicate, System.currentTimeMillis());
predicate = m.createProperty(URI_PREDICATE);
for (String uri : lastProcessedUris) {
m.add(subject, predicate, m.createResource(uri));
}
predicate = m.createProperty(VERSION_PREDICATE);
m.addLiteral(subject, predicate, 1.0);
size += m.size() + 1;
predicate = m.createProperty(INDEX_SIZE_PREDICATE);
m.addLiteral(subject, predicate, size);
dataset.commit();
} catch (Throwable e) {
dataset.abort();
throw new RuntimeException(e);
} finally {
dataset.end();
long writeOperationDuration = System.currentTimeMillis() - t;
totalExecTime += writeOperationDuration;
System.out.println("Write operation " + i + " took " + writeOperationDuration + "ms");
}
}
if (bracketWithReader)
dataset1.end();
System.out.println("All " + TOTAL + " write operations wrote " + size + " triples and took " + totalExecTime + "ms");
}
use of org.apache.jena.rdf.model.Property in project jena by apache.
the class AbstractWholeFileQuadInputFormatTests method writeGoodTuples.
private void writeGoodTuples(OutputStream output, int num) {
Dataset ds = DatasetFactory.createGeneral();
Model m = ModelFactory.createDefaultModel();
Resource currSubj = m.createResource("http://example.org/subjects/0");
Property predicate = m.createProperty("http://example.org/predicate");
for (int i = 0; i < num; i++) {
if (i % 100 == 0) {
ds.addNamedModel("http://example.org/graphs/" + (i / 100), m);
m = ModelFactory.createDefaultModel();
}
if (i % 10 == 0) {
currSubj = m.createResource("http://example.org/subjects/" + (i / 10));
}
m.add(currSubj, predicate, m.createTypedLiteral(i));
}
if (!m.isEmpty()) {
ds.addNamedModel("http://example.org/graphs/extra", m);
}
this.writeTuples(ds, output);
}
Aggregations