Search in sources :

Example 71 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestRemoteEndpointConnectionWithAuth method cleanupTest.

/**
     * Clean up after each test by resetting the data
     */
@After
public void cleanupTest() {
    DatasetGraph dsg = FusekiTestAuth.getDataset();
    Txn.executeWrite(dsg, () -> dsg.clear());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) After(org.junit.After)

Example 72 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestUtils method copyDataset.

/**
     * Copies one dataset to another
     * 
     * @param source
     *            Source Dataset
     * @param target
     *            Target Dataset
     * @param copyDefaultAsQuads
     *            Whether the default graph should be copied as quads (required
     *            for TDB datasets)
     * 
     */
public static void copyDataset(Dataset source, Dataset target, boolean copyDefaultAsQuads) {
    // Copy the default graph
    if (copyDefaultAsQuads) {
        DatasetGraph targetDSG = target.asDatasetGraph();
        source.asDatasetGraph().find(defaultGraphIRI, ANY, ANY, ANY).forEachRemaining(targetDSG::add);
    } else {
        target.setDefaultModel(source.getDefaultModel());
    }
    // Copy named graphs
    source.listNames().forEachRemaining(uri -> target.addNamedModel(uri, source.getNamedModel(uri)));
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 73 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class DatasetAssemblerTDB method make.

static Dataset make(Resource root) {
    if (!exactlyOneProperty(root, pLocation))
        throw new AssemblerException(root, "No location given");
    String dir = getStringValue(root, pLocation);
    Location loc = Location.create(dir);
    DatasetGraph dsg = TDBFactory.createDatasetGraph(loc);
    if (root.hasProperty(pUnionDefaultGraph)) {
        Node b = root.getProperty(pUnionDefaultGraph).getObject().asNode();
        NodeValue nv = NodeValue.makeNode(b);
        if (nv.isBoolean())
            dsg.getContext().set(TDB.symUnionDefaultGraph, nv.getBoolean());
        else
            Log.warn(DatasetAssemblerTDB.class, "Failed to recognize value for union graph setting (ignored): " + b);
    }
    /*
        <r> rdf:type tdb:DatasetTDB ;
            tdb:location "dir" ;
            //ja:context [ ja:cxtName "arq:queryTimeout" ;  ja:cxtValue "10000" ] ;
            tdb:unionGraph true ; # or "true"
        */
    AssemblerUtils.setContext(root, dsg.getContext());
    return DatasetFactory.wrap(dsg);
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) AssemblerException(org.apache.jena.assembler.exceptions.AssemblerException) Node(org.apache.jena.graph.Node) VocabTDB.pLocation(org.apache.jena.tdb.assembler.VocabTDB.pLocation) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 74 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class AbstractStoreConnections method store_6.

@Test
public void store_6() {
    // Transaction - release - reattach
    // This tests that the dataset is sync'ed when going into transactional mode.
    StoreConnection sConn = getStoreConnection();
    Location loc = sConn.getLocation();
    DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
    dsgTxn.add(q1);
    assertTrue(dsgTxn.contains(q1));
    dsgTxn.commit();
    dsgTxn.end();
    sConn.forceRecoverFromJournal();
    assertTrue(sConn.getBaseDataset().contains(q1));
    StoreConnection.release(loc);
    sConn = StoreConnection.make(loc);
    DatasetGraph dsg2 = sConn.getBaseDataset();
    assertTrue(dsg2.contains(q1));
    DatasetGraphTxn dsgTxn2 = sConn.begin(ReadWrite.READ);
    assertTrue(dsgTxn2.contains(q1));
    dsgTxn2.end();
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) DatasetGraphTxn(org.apache.jena.tdb.transaction.DatasetGraphTxn) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 75 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class AbstractStoreConnections method store_7.

@Test
public void store_7() {
    // No transaction, plain update, then transaction.
    // This tests that the dataset is sync'ed when going into transactional mode.
    boolean nonTxnData = true;
    StoreConnection sConn = getStoreConnection();
    Location loc = sConn.getLocation();
    DatasetGraph dsg = sConn.getBaseDataset();
    if (nonTxnData) {
        dsg.add(q);
        TDB.sync(dsg);
        assertTrue(dsg.contains(q));
    }
    DatasetGraphTxn dsgTxn = sConn.begin(ReadWrite.WRITE);
    if (nonTxnData)
        assertTrue(dsgTxn.contains(q));
    dsgTxn.add(q1);
    assertTrue(dsgTxn.contains(q1));
    if (nonTxnData)
        assertTrue(dsgTxn.contains(q));
    dsgTxn.commit();
    dsgTxn.end();
    // Should have flushed to disk.
    if (nonTxnData) {
        sConn.forceRecoverFromJournal();
        assertTrue(dsg.contains(q));
    }
    assertTrue(dsg.contains(q1));
    // release via the transactional machinery
    StoreConnection.release(loc);
    sConn = null;
    StoreConnection sConn2 = StoreConnection.make(loc);
    DatasetGraph dsg2 = sConn2.getBaseDataset();
    if (nonTxnData)
        assertTrue(dsg2.contains(q));
    assertTrue(dsg2.contains(q1));
    DatasetGraphTxn dsgTxn2 = sConn2.begin(ReadWrite.READ);
    if (nonTxnData)
        assertTrue(dsgTxn2.contains(q));
    assertTrue(dsgTxn2.contains(q1));
    dsgTxn2.end();
    // Check API methods work.
    Dataset ds = TDBFactory.createDataset(loc);
    ds.begin(ReadWrite.READ);
    Model m = (q.isDefaultGraph() ? ds.getDefaultModel() : ds.getNamedModel("g"));
    assertEquals(nonTxnData ? 2 : 1, m.size());
    ds.end();
}
Also used : StoreConnection(org.apache.jena.tdb.StoreConnection) Dataset(org.apache.jena.query.Dataset) DatasetGraphTxn(org.apache.jena.tdb.transaction.DatasetGraphTxn) Model(org.apache.jena.rdf.model.Model) Location(org.apache.jena.tdb.base.file.Location) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)222 Test (org.junit.Test)132 BaseTest (org.apache.jena.atlas.junit.BaseTest)59 Quad (org.apache.jena.sparql.core.Quad)47 Node (org.apache.jena.graph.Node)29 Graph (org.apache.jena.graph.Graph)18 StoreConnection (org.apache.jena.tdb.StoreConnection)17 DatasetGraphTxn (org.apache.jena.tdb.transaction.DatasetGraphTxn)15 Model (org.apache.jena.rdf.model.Model)10 IOException (java.io.IOException)7 Triple (org.apache.jena.graph.Triple)7 Dataset (org.apache.jena.query.Dataset)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 ResultSet (org.apache.jena.query.ResultSet)5 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)5 Element (org.apache.jena.sparql.syntax.Element)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RiotException (org.apache.jena.riot.RiotException)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4