Skip to content

Commit

Permalink
#266 #295 Clearing TDB instead of delete its folder: ending transacti…
Browse files Browse the repository at this point in the history
…on before clearing the dataset
  • Loading branch information
luigi-asprino committed Nov 14, 2023
1 parent 6e07a86 commit 41a1b24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,22 +628,6 @@ public void testIssue291() {

}

@Test
@Ignore
public void playWithTDBLoc() throws IOException {
String testFolder = "tmp/testTDB";
Dataset d1 = TDB2Factory.connectDataset(testFolder);
Txn.executeWrite(d1, ()->{
RDFDataMgr.read(d1, "https://www.w3.org/1999/02/22-rdf-syntax-ns#");
});

Txn.executeRead(d1, ()->{
RDFDataMgr.write(System.out, d1, Lang.TRIG);
});
d1.close();
FileUtils.deleteDirectory(new File(testFolder));
}


/**
* See <a href="https://github.com/SPARQL-Anything/sparql.anything/issues/295">...</a>
Expand Down Expand Up @@ -681,7 +665,11 @@ public void testIssue295() throws URISyntaxException, IOException {
}
ds.end();
assertEquals(expectedNames, actualNames);
FileUtils.deleteDirectory(tmpTBDFolder);
try {
FileUtils.deleteDirectory(tmpTBDFolder);
}catch(IOException e){
log.warn("Unable to delete {}, delete it once the program terminates.",tmpTBDFolder.getAbsolutePath());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.system.Txn;
import org.apache.jena.tdb.TDBFactory;
import org.apache.jena.tdb2.DatabaseMgr;
import org.apache.jena.tdb2.TDB2Factory;
Expand Down Expand Up @@ -61,7 +62,9 @@ private void initialiseDatasetGraph(Properties properties) {
FileUtils.deleteDirectory(ondiskFile);
} catch (IOException e) {
if (TDBFactory.inUseLocation(ondiskPath)) {
TDB2Factory.connectDataset(ondiskPath).asDatasetGraph().clear();
DatasetGraph dg = TDB2Factory.connectDataset(ondiskPath).asDatasetGraph();
dg.end();
Txn.executeWrite(dg, dg::clear);
log.warn("Clearing TBD instead of deleting the TDB folder.");
} else {
throw new RuntimeException(e);
Expand Down

0 comments on commit 41a1b24

Please sign in to comment.