Search in sources :

Example 11 with DatasetGraphSwitchable

use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.

the class TDBInternal method expel.

/**
 * Stop managing a DatasetGraph. Use with great care.
 */
public static synchronized void expel(DatasetGraph dsg, boolean force) {
    Location locContainer = null;
    Location locStorage = null;
    if (dsg instanceof DatasetGraphSwitchable) {
        locContainer = ((DatasetGraphSwitchable) dsg).getLocation();
        dsg = ((DatasetGraphSwitchable) dsg).getWrapped();
    }
    if (dsg instanceof DatasetGraphTDB)
        locStorage = ((DatasetGraphTDB) dsg).getLocation();
    DatabaseConnection.internalExpel(locContainer, force);
    StoreConnection.internalExpel(locStorage, force);
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 12 with DatasetGraphSwitchable

use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.

the class TDBInternal method expel.

/**
 * Stop managing a DatasetGraph. Use with great care.
 */
public static synchronized void expel(DatasetGraph dsg) {
    Location locContainer = null;
    Location locStorage = null;
    if (dsg instanceof DatasetGraphSwitchable) {
        locContainer = ((DatasetGraphSwitchable) dsg).getLocation();
        dsg = ((DatasetGraphSwitchable) dsg).getWrapped();
    }
    if (dsg instanceof DatasetGraphTDB)
        locStorage = ((DatasetGraphTDB) dsg).getLocation();
    if (locContainer != null)
        DatabaseConnection.internalExpel(locContainer, false);
    StoreConnection.internalExpel(locStorage, false);
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) Location(org.apache.jena.dboe.base.file.Location) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 13 with DatasetGraphSwitchable

use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.

the class TestTDBAssembler method createGraphEmbed.

@Test
public void createGraphEmbed() {
    String f = dirAssem + "/tdb-graph-embed.ttl";
    Object thing = null;
    try {
        thing = AssemblerUtils.build(f, JA.Model);
    } catch (AssemblerException e) {
        e.getCause().printStackTrace(System.err);
        throw e;
    }
    assertTrue(thing instanceof Model);
    Graph graph = ((Model) thing).getGraph();
    assertTrue(graph instanceof GraphViewSwitchable);
    DatasetGraphSwitchable ds = ((GraphViewSwitchable) graph).getDataset();
    if (ds != null)
        ds.close();
}
Also used : Graph(org.apache.jena.graph.Graph) GraphViewSwitchable(org.apache.jena.tdb2.store.GraphViewSwitchable) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Model(org.apache.jena.rdf.model.Model) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb2.ConfigTest)

Example 14 with DatasetGraphSwitchable

use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.

the class TestTDBAssembler method createTest.

private void createTest(String filename, Resource type) {
    Object thing = AssemblerUtils.build(filename, type);
    assertTrue(thing instanceof Dataset);
    Dataset ds = (Dataset) thing;
    assertTrue(ds.asDatasetGraph() instanceof DatasetGraphSwitchable);
    assertTrue(ds.supportsTransactions());
    ds.close();
}
Also used : Dataset(org.apache.jena.query.Dataset) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable)

Example 15 with DatasetGraphSwitchable

use of org.apache.jena.tdb2.store.DatasetGraphSwitchable in project jena by apache.

the class TestDatabaseOps method compact_dsg_1.

@Test
public void compact_dsg_1() {
    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, false);
    assertFalse(StoreConnection.isSetup(loc1));
    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));
    });
    // dsg1 was closed and expelled. We must carefully reopen its storage only.
    DatasetGraph dsgOld = StoreConnection.connectCreate(loc1).getDatasetGraph();
    Txn.executeWrite(dsgOld, () -> dsgOld.delete(quad2));
    Txn.executeRead(dsg, () -> assertTrue(dsg.contains(quad2)));
    Txn.executeRead(dsg2, () -> assertTrue(dsg2.contains(quad2)));
}
Also used : 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) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb2.ConfigTest)

Aggregations

DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)14 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)10 Location (org.apache.jena.dboe.base.file.Location)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)6 Graph (org.apache.jena.graph.Graph)4 ConfigTest (org.apache.jena.tdb2.ConfigTest)4 Test (org.junit.Test)4 TDBException (org.apache.jena.tdb2.TDBException)3 AssemblerException (org.apache.jena.assembler.exceptions.AssemblerException)2 Model (org.apache.jena.rdf.model.Model)2 GraphViewSwitchable (org.apache.jena.tdb2.store.GraphViewSwitchable)2 ModDataset (arq.cmdline.ModDataset)1 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)1 CmdException (org.apache.jena.cmd.CmdException)1 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)1 TransactionalSystem (org.apache.jena.dboe.transaction.txn.TransactionalSystem)1 Dataset (org.apache.jena.query.Dataset)1 JenaException (org.apache.jena.shared.JenaException)1