use of org.apache.jena.dboe.base.file.Location 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.dboe.base.file.Location in project jena by apache.
the class TestStoreParamsChoose method params_choose_new_persist_2.
@Test
public void params_choose_new_persist_2() {
// new database, location defined.
Location loc = Location.create(DIR);
FileOps.clearAll(loc.getDirectoryPath());
StoreParamsCodec.write(loc, pLoc);
// Clear.
StoreParams p = StoreParamsFactory.decideStoreParams(loc, true, null, pLoc, pDft);
// Check location still has a pLoc.
String fn = loc.getPath(Names.TDB_CONFIG_FILE);
assertTrue(FileOps.exists(fn));
StoreParams pLoc2 = StoreParamsCodec.read(loc);
assertTrue(StoreParams.sameValues(pLoc, p));
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class TestStoreParamsChoose method params_choose_new_persist_3.
@Test
public void params_choose_new_persist_3() {
// new database, location defined, application modified.
Location loc = Location.create(DIR);
FileOps.clearAll(loc.getDirectoryPath());
StoreParamsCodec.write(loc, pLoc);
// Clear.
StoreParams p = StoreParamsFactory.decideStoreParams(loc, true, pApp, pLoc, pDft);
// Check location still has a pLoc.
String fn = loc.getPath(Names.TDB_CONFIG_FILE);
assertTrue(FileOps.exists(fn));
StoreParams pLoc2 = StoreParamsCodec.read(loc);
assertFalse(StoreParams.sameValues(pLoc, p));
// Location
assertEquals(0, p.getBlockSize().intValue());
// Application
assertEquals(12, p.getNodeMissCacheSize().intValue());
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class SpotTDB2 method checkTDB2.
public static void checkTDB2(Location location) {
if (location.isMem())
return;
if (isEmpty(location))
return;
Path db = storageDir(location);
if (db == null)
// Uninitialized
return;
// Storage. Easier to work in "Location".
Location locStorage = Location.create(db);
checkStorageArea(locStorage);
}
use of org.apache.jena.dboe.base.file.Location in project jena by apache.
the class SpotTDB2 method isTDB2.
/**
* Test to see is a location is either empty (and a fresh TDB2 database can be
* created there) or has looks like it is an existing TDB2 database.
* See {@link #checkTDB2(Location)} for a test that the location is a valid, existing
* database.
*/
public static boolean isTDB2(Location location) {
if (location.isMem())
return true;
if (!location.exists())
return false;
if (isEmpty(location))
return true;
// Look for Data-*
Path db = storageDir(location);
if (db == null)
// Or TDB1?
return !SpotTDB1.isTDB1(location.getDirectoryPath());
// Validate storage.
Location storageLocation = IO_DB.asLocation(db);
return isTDB2_Storage(storageLocation);
}
Aggregations