Search in sources :

Example 6 with Location

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")));
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 7 with Location

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));
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) ConfigTest(org.apache.jena.tdb2.ConfigTest) Test(org.junit.Test)

Example 8 with Location

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());
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) Location(org.apache.jena.dboe.base.file.Location) ConfigTest(org.apache.jena.tdb2.ConfigTest) Test(org.junit.Test)

Example 9 with Location

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);
}
Also used : Path(java.nio.file.Path) Location(org.apache.jena.dboe.base.file.Location)

Example 10 with Location

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);
}
Also used : Path(java.nio.file.Path) Location(org.apache.jena.dboe.base.file.Location)

Aggregations

Location (org.apache.jena.dboe.base.file.Location)29 Test (org.junit.Test)12 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)10 ConfigTest (org.apache.jena.tdb2.ConfigTest)7 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)7 StoreParams (org.apache.jena.tdb2.params.StoreParams)4 Dataset (org.apache.jena.query.Dataset)3 TDBException (org.apache.jena.tdb2.TDBException)3 Path (java.nio.file.Path)2 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 ProcessFileLock (org.apache.jena.dboe.base.file.ProcessFileLock)2 Graph (org.apache.jena.graph.Graph)2 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)2 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 Timer (org.apache.jena.atlas.lib.Timer)1 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)1 CmdException (org.apache.jena.cmd.CmdException)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1