use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.
the class LoaderMain method executeData.
/**
* Create data ingestion and primary index building of a {@link LoaderPlan}.
* In phase 1, separate threads for parsing, node table loading and primary index building,
*
* Used by {@link InputStage#MULTI}.
*/
private static StreamRDFCounting executeData(LoaderPlan loaderPlan, DatasetGraphTDB dsgtdb, Map<String, TupleIndex> indexMap, List<BulkStartFinish> dataProcess, MonitorOutput output) {
StoragePrefixesTDB dps = (StoragePrefixesTDB) dsgtdb.getStoragePrefixes();
PrefixHandlerBulk prefixHandler = new PrefixHandlerBulk(dps, output);
dataProcess.add(prefixHandler);
// -- Phase 2 block. Indexer and Destination (blocks of Tuple<NodeId>)
TupleIndex[] idx3 = PhasedOps.indexSetFromNames(loaderPlan.primaryLoad3(), indexMap);
Indexer indexer3 = new Indexer(output, idx3);
TupleIndex[] idx4 = PhasedOps.indexSetFromNames(loaderPlan.primaryLoad4(), indexMap);
Indexer indexer4 = new Indexer(output, idx4);
dataProcess.add(indexer3);
dataProcess.add(indexer4);
Destination<Tuple<NodeId>> functionIndexer3 = indexer3.index();
Destination<Tuple<NodeId>> functionIndexer4 = indexer4.index();
// -- Phase 2 block.
// -- Phase 1.
// This is the other way round to AsyncParser.
// Here, we return a StreamRDF to pump data into and the rest of the
// processing is on other threads. AsyncParser has the processing on the caller thread
// and so the current thread continues when the processing from the parser is finished.
DataToTuples dtt = new DataToTuples(dsgtdb, functionIndexer3, functionIndexer4, output);
DataBatcher dataBatcher = new DataBatcher(dtt.data(), prefixHandler.handler(), output);
dataProcess.add(dtt);
dataProcess.add(dataBatcher);
return dataBatcher;
}
use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.
the class TestDatabaseOps method compact_delete.
@Test
public void compact_delete() {
assumeFalse(Sys.isWindows);
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable) dsg;
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB) dsg1).getLocation();
Txn.executeWrite(dsg, () -> {
dsg.add(quad2);
dsg.add(quad1);
});
DatabaseMgr.compact(dsg, true);
// https://bugs.openjdk.java.net/browse/JDK-4715154
if (!Sys.isWindows)
assertFalse(IO_DB.asFile(loc1).exists());
DatasetGraph dsg2 = dsgs.get();
Location loc2 = ((DatasetGraphTDB) dsg2).getLocation();
assertNotEquals(dsg1, dsg2);
assertNotEquals(loc1, loc2);
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(quad2));
assertTrue(dsg.contains(quad1));
});
Txn.executeRead(dsg, () -> assertTrue(dsg.contains(quad2)));
Txn.executeRead(dsg2, () -> assertTrue(dsg2.contains(quad2)));
}
use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.
the class TestDatabaseOps method compact_graph_2.
@Test
public void compact_graph_2() {
// graphs across compaction.
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Graph g = dsg.getDefaultGraph();
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable) dsg;
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB) dsg1).getLocation();
Txn.executeWrite(dsg, () -> {
dsg.add(quad2);
dsg.add(quad1);
});
DatabaseMgr.compact(dsg, false);
Txn.executeRead(dsg, () -> {
assertEquals(2, g.size());
assertTrue(g.contains(triple2));
});
// Check is not attached to the old graph.
DatasetGraph dsgOld = StoreConnection.connectCreate(loc1).getDatasetGraph();
Txn.executeWrite(dsgOld, () -> dsgOld.getDefaultGraph().delete(triple2));
Txn.executeRead(dsg, () -> assertTrue(g.contains(triple2)));
Txn.executeWrite(dsg, () -> g.add(triple3));
Txn.executeRead(dsgOld, () -> assertFalse(dsgOld.getDefaultGraph().contains(triple3)));
}
use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.
the class TestDatabaseOps method compact_prefixes_3_test.
private void compact_prefixes_3_test() {
// prefixes across compaction.
DatasetGraph dsg = DatabaseMgr.connectDatasetGraph(dir);
Graph g = dsg.getDefaultGraph();
Txn.executeWrite(dsg, () -> g.getPrefixMapping().setNsPrefix("ex", "http://example/"));
Txn.executeRead(dsg, () -> {
assertEquals("ex", g.getPrefixMapping().getNsURIPrefix("http://example/"));
assertEquals("http://example/", g.getPrefixMapping().getNsPrefixURI("ex"));
});
DatasetGraphSwitchable dsgs = (DatasetGraphSwitchable) dsg;
assertNotNull("DatasetGraphSwitchable created", dsgs.getLocation());
DatasetGraph dsg1 = dsgs.get();
Location loc1 = ((DatasetGraphTDB) dsg1).getLocation();
// Before
int x1 = Txn.calculateRead(dsg, () -> dsg.prefixes().size());
assertTrue("Prefxies count", x1 > 0);
// HERE
DatabaseMgr.compact(dsgs, false);
// After
int x2 = Txn.calculateRead(dsg, () -> dsg.prefixes().size());
assertEquals("Before and after prefix count", x1, x2);
Graph g2 = dsgs.getDefaultGraph();
Txn.executeRead(dsgs, () -> {
assertEquals("ex", g2.getPrefixMapping().getNsURIPrefix("http://example/"));
assertEquals("http://example/", g2.getPrefixMapping().getNsPrefixURI("ex"));
});
// Check is not attached to the old graph.
DatasetGraph dsgOld = StoreConnection.connectCreate(loc1).getDatasetGraph();
Txn.executeWrite(dsgOld, () -> dsgOld.getDefaultGraph().getPrefixMapping().removeNsPrefix("ex"));
Txn.executeRead(dsg, () -> assertEquals("http://example/", g.getPrefixMapping().getNsPrefixURI("ex")));
Txn.executeWrite(dsg, () -> g.getPrefixMapping().setNsPrefix("ex2", "http://exampl2/"));
Txn.executeRead(dsgOld, () -> assertNull(dsgOld.getDefaultGraph().getPrefixMapping().getNsPrefixURI("ex")));
}
use of org.apache.jena.tdb2.store.DatasetGraphTDB in project jena by apache.
the class AbstractTestStoreConnectionBasics method store_02.
@Test
public void store_02() {
StoreConnection sConn = StoreConnection.connectCreate(location);
{
// Isolate to stop mix ups on variables.
DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
Txn.executeWrite(dsg, () -> {
dsg.add(q1);
});
Txn.executeWrite(dsg, () -> {
assertTrue(dsg.contains(q1));
});
Txn.executeRead(dsg, () -> {
assertTrue(dsg.contains(q1));
});
}
{
StoreConnection sConn2 = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg2 = sConn.getDatasetGraphTDB();
Txn.executeRead(dsg2, () -> {
assertTrue(dsg2.contains(q1));
});
}
StoreConnection.release(sConn.getLocation());
sConn = null;
{
if (!location.isMem()) {
StoreConnection sConn2 = StoreConnection.connectCreate(location);
DatasetGraphTDB dsg3 = sConn2.getDatasetGraphTDB();
Txn.executeRead(dsg3, () -> {
assertTrue(dsg3.contains(q1));
});
}
}
}
Aggregations