Search in sources :

Example 11 with DatasetGraphTDB

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

the class TestQuadFilter method setup.

/** Example setup - in-memory dataset with two graphs, one triple in each */
private static Dataset setup() {
    Dataset ds = TDBFactory.createDataset();
    DatasetGraphTDB dsg = (DatasetGraphTDB) (ds.asDatasetGraph());
    Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)");
    Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)");
    dsg.add(q1);
    dsg.add(q2);
    return ds;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 12 with DatasetGraphTDB

use of org.apache.jena.tdb.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 ds) {
    DatasetGraphTDB dsg = (DatasetGraphTDB) (ds.asDatasetGraph());
    final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
    final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide));
    return item -> !(item.len() == 4 && item.get(0).equals(target));
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) Predicate(java.util.function.Predicate) Test(org.junit.Test) SystemTDB(org.apache.jena.tdb.sys.SystemTDB) NodeId(org.apache.jena.tdb.store.NodeId) SSE(org.apache.jena.sparql.sse.SSE) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB) BaseTest(org.apache.jena.atlas.junit.BaseTest) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Quad(org.apache.jena.sparql.core.Quad) TDBFactory(org.apache.jena.tdb.TDBFactory) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) TDB(org.apache.jena.tdb.TDB) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 13 with DatasetGraphTDB

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

the class StoreConnection method make.

/**
     * Return a StoreConnection for a particular connection. This is used to
     * create transactions for the database at the location.
     */
public static synchronized StoreConnection make(Location location, StoreParams params) {
    StoreConnection sConn = cache.get(location);
    if (sConn != null)
        return sConn;
    DatasetGraphTDB dsg = DatasetBuilderStd.create(location, params);
    sConn = _makeAndCache(dsg);
    return sConn;
}
Also used : DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 14 with DatasetGraphTDB

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

the class TDB method sync.

/** Sync a TDB-backed DatasetGraph. Do nothing if not TDB-backed. */
public static void sync(DatasetGraph dataset) {
    if (dataset == null)
        return;
    // Should be: SystemARQ.sync(dataset) ;
    if (dataset instanceof DatasetGraphTDB) {
        syncObject(dataset);
        return;
    }
    if (dataset instanceof DatasetGraphTransaction) {
        DatasetGraphTransaction dsgt = (DatasetGraphTransaction) dataset;
        // This only sync if the dataset has not been used transactionally.
        // Can't sync transactional datasets (it's meaningless)
        dsgt.syncIfNotTransactional();
        return;
    }
    // May be a general purpose dataset with TDB objects in it.
    sync(dataset.getDefaultGraph());
    Iterator<Node> iter = dataset.listGraphNodes();
    // Avoid iterator concurrency.
    iter = Iter.toList(iter).iterator();
    for (; iter.hasNext(); ) {
        Node n = iter.next();
        Graph g = dataset.getGraph(n);
        sync(g);
    }
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) DatasetGraphTransaction(org.apache.jena.tdb.transaction.DatasetGraphTransaction) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 15 with DatasetGraphTDB

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

the class TestTransRestart method setupPlain.

private void setupPlain() {
    // Make without transactions.
    DatasetGraphTDB dsg = createPlain(location);
    dsg.add(quad1);
    dsg.close();
    StoreConnection.release(location);
    return;
}
Also used : DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Aggregations

DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)24 Node (org.apache.jena.graph.Node)5 BaseTest (org.apache.jena.atlas.junit.BaseTest)4 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)4 Test (org.junit.Test)4 StoreConnection (org.apache.jena.tdb.StoreConnection)3 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 Quad (org.apache.jena.sparql.core.Quad)2 BlockMgrBuilder (org.apache.jena.tdb.setup.BlockMgrBuilder)2 DatasetBuilderStd (org.apache.jena.tdb.setup.DatasetBuilderStd)2 NodeTableBuilder (org.apache.jena.tdb.setup.NodeTableBuilder)2 NodeId (org.apache.jena.tdb.store.NodeId)2 DatasetGraphTxn (org.apache.jena.tdb.transaction.DatasetGraphTxn)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 HashSet (java.util.HashSet)1 Predicate (java.util.function.Predicate)1 AtlasException (org.apache.jena.atlas.AtlasException)1