Search in sources :

Example 1 with DatasetGraphSwitchable

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);
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable)

Example 2 with DatasetGraphSwitchable

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;
}
Also used : JenaException(org.apache.jena.shared.JenaException) CmdException(org.apache.jena.cmd.CmdException) ModDataset(arq.cmdline.ModDataset) DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable) CmdException(org.apache.jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 3 with DatasetGraphSwitchable

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);
}
Also used : DatasetGraphSwitchable(org.apache.jena.tdb2.store.DatasetGraphSwitchable)

Example 4 with DatasetGraphSwitchable

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)));
}
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)

Example 5 with DatasetGraphSwitchable

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)));
}
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) 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