Search in sources :

Example 21 with DatasetGraphTDB

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

the class OpExecutorTDB2 method execute.

@Override
protected QueryIterator execute(OpQuadPattern quadPattern, QueryIterator input) {
    if (!isForTDB)
        return super.execute(quadPattern, input);
    // DatasetGraph dg = execCxt.getDataset();
    // if ( ! ( dg instanceof DatasetGraphTDB ) )
    // throw new InternalErrorException("Not a TDB backed dataset in quad pattern execution");
    DatasetGraphTDB ds = (DatasetGraphTDB) execCxt.getDataset();
    BasicPattern bgp = quadPattern.getBasicPattern();
    Node gn = quadPattern.getGraphNode();
    return optimizeExecuteQuads(ds, input, gn, bgp, null, execCxt);
}
Also used : Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Example 22 with DatasetGraphTDB

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

the class TestQuadFilter method createFilter.

/**
 * Create a filter to exclude the graph http://example/g2
 */
private static Predicate<Tuple<NodeId>> createFilter(Dataset dataset) {
    return Txn.calculateRead(dataset, () -> {
        DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(dataset);
        final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
        final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide));
        // Check g slot. Exclude graphToHide
        return item -> !(item.len() == 4 && item.get(0).equals(target));
    });
}
Also used : SystemTDB(org.apache.jena.tdb2.sys.SystemTDB) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Predicate(java.util.function.Predicate) TDBInternal(org.apache.jena.tdb2.sys.TDBInternal) TDB2Factory(org.apache.jena.tdb2.TDB2Factory) Test(org.junit.Test) TDB2(org.apache.jena.tdb2.TDB2) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) SSE(org.apache.jena.sparql.sse.SSE) Txn(org.apache.jena.system.Txn) Quad(org.apache.jena.sparql.core.Quad) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 23 with DatasetGraphTDB

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

the class AbstractTestStoreConnectionBasics method store_03.

@Test
public void store_03() {
    StoreConnection sConn = StoreConnection.connectCreate(location);
    DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
    Txn.executeWrite(dsg, () -> {
        dsg.add(q1);
    });
    Txn.executeWrite(dsg, () -> {
        assertTrue(dsg.contains(q1));
    });
    try {
        Txn.executeWrite(dsg, () -> {
            dsg.add(q2);
            throw new RuntimeException();
        });
        fail("Should not get to here!");
    } catch (RuntimeException ex) {
    }
    Txn.executeRead(dsg, () -> {
        assertTrue(dsg.contains(q1));
        assertFalse(dsg.contains(q2));
    });
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 24 with DatasetGraphTDB

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

the class AbstractTestStoreConnectionBasics method store_04.

@Test
public void store_04() {
    StoreConnection sConn = StoreConnection.connectCreate(location);
    DatasetGraphTDB dsg = sConn.getDatasetGraphTDB();
    Txn.executeWrite(dsg, () -> {
        dsg.add(q1);
    });
    Txn.executeWrite(dsg, () -> {
        assertTrue(dsg.contains(q1));
    });
    dsg.begin(ReadWrite.WRITE);
    dsg.add(q2);
    dsg.abort();
    dsg.end();
    Txn.executeRead(dsg, () -> {
        assertTrue(dsg.contains(q1));
        assertFalse(dsg.contains(q2));
    });
}
Also used : StoreConnection(org.apache.jena.tdb2.sys.StoreConnection) Test(org.junit.Test)

Example 25 with DatasetGraphTDB

use of org.apache.jena.tdb2.store.DatasetGraphTDB 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

DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)19 Location (org.apache.jena.dboe.base.file.Location)10 Node (org.apache.jena.graph.Node)8 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)8 DatasetGraphSwitchable (org.apache.jena.tdb2.store.DatasetGraphSwitchable)8 Test (org.junit.Test)8 NodeId (org.apache.jena.tdb2.store.NodeId)7 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)7 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 StoreConnection (org.apache.jena.tdb2.sys.StoreConnection)4 ConfigTest (org.apache.jena.tdb2.ConfigTest)3 TDBException (org.apache.jena.tdb2.TDBException)3 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)2 FileSet (org.apache.jena.dboe.base.file.FileSet)2 Record (org.apache.jena.dboe.base.record.Record)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)2 Graph (org.apache.jena.graph.Graph)2 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)2 ModDataset (arq.cmdline.ModDataset)1