use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.
the class tdbbackup method exec.
@Override
protected void exec() {
DatasetGraphSwitchable dsg = getDatabaseContainer();
String fn = DatabaseOps.backup(dsg);
System.out.println("Backup written to " + fn);
}
use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.
the class ModTDBDataset method createDataset.
@Override
public Dataset createDataset() {
if (inMemFile != null) {
Dataset ds = TDB2Factory.createDataset();
RDFDataMgr.read(ds, inMemFile);
return ds;
}
if (modAssembler.getAssemblerFile() != null) {
Dataset thing = null;
// (which may go wrong later if TDB2 directly is needed).
try {
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB2.tDatasetTDB);
if (thing != null) {
DatasetGraph dsg = thing.asDatasetGraph();
if (!(dsg instanceof DatasetGraphSwitchable) && !(dsg instanceof DatasetGraphTDB))
Log.warn(this, "Unexpected: Not a TDB2 dataset for type DatasetTDB2");
}
if (thing == null)
// Should use assembler inheritance but how do we assert
// the subclass relationship in a program?
thing = (Dataset) AssemblerUtils.build(modAssembler.getAssemblerFile(), DatasetAssemblerVocab.tDataset);
} catch (JenaException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Error creating", ex);
}
return thing;
}
if (modAssembler.getLocation() == null)
throw new CmdException("No assembler file nor location provided");
// No assembler - use location to find a database.
Dataset ds = TDB2Factory.connectDataset(modAssembler.getLocation());
return ds;
}
use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.
the class tdbcompact method exec.
@Override
protected void exec() {
DatasetGraphSwitchable dsg = getDatabaseContainer();
long start = System.currentTimeMillis();
DatabaseOps.compact(dsg, shouldDeleteOld);
long finish = System.currentTimeMillis();
System.out.printf("Compacted in %.3fs\n", (finish - start) / 1000.0);
}
use of org.apache.jena.tdb2.store.DatasetGraphSwitchable 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.DatasetGraphSwitchable 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)));
}
Aggregations