Search in sources :

Example 21 with DatasetGraph

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

the class AbstractTestUpdateGraph method testInsert2.

@Test
public void testInsert2() {
    DatasetGraph gStore = getEmptyDatasetGraph();
    UpdateModify insert = new UpdateModify();
    insert.getInsertAcc().addTriple(triple1);
    UpdateAction.execute(insert, gStore);
    assertTrue(graphContains(gStore.getDefaultGraph(), triple1));
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 22 with DatasetGraph

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

the class REST_Quads method doPostTriplesGSP.

protected void doPostTriplesGSP(HttpAction action, Lang lang) {
    action.beginWrite();
    try {
        DatasetGraph dsg = action.getActiveDSG();
        //log.info(format("[%d] ** Content-length: %d", action.id, action.request.getContentLength())) ;  
        String name = action.request.getRequestURL().toString();
        if (!name.endsWith("/"))
            name = name + "/";
        name = name + (++counter);
        Node gn = NodeFactory.createURI(name);
        Graph g = dsg.getGraph(gn);
        RDFDataMgr.read(g, action.request.getInputStream(), name, lang);
        log.info(format("[%d] Location: %s", action.id, name));
        action.response.setHeader("Location", name);
        action.commit();
        successCreated(action);
    } catch (IOException ex) {
        action.abort();
    } finally {
        action.endWrite();
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) IOException(java.io.IOException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 23 with DatasetGraph

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

the class REST_Quads method doPostQuads.

protected void doPostQuads(HttpAction action, Lang lang) {
    action.beginWrite();
    try {
        String name = action.request.getRequestURL().toString();
        DatasetGraph dsg = action.getActiveDSG();
        RDFDataMgr.read(dsg, action.request.getInputStream(), name, lang);
        action.commit();
        success(action);
    } catch (IOException ex) {
        action.abort();
    } finally {
        action.endWrite();
    }
}
Also used : IOException(java.io.IOException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 24 with DatasetGraph

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

the class QueryExecutionFactory method make.

protected static QueryExecution make(Query query, Dataset dataset, Context context) {
    query.setResultVars();
    if (context == null)
        // .copy done in QueryExecutionBase -> Context.setupContext.
        context = ARQ.getContext();
    DatasetGraph dsg = null;
    if (dataset != null)
        dsg = dataset.asDatasetGraph();
    QueryEngineFactory f = findFactory(query, dsg, context);
    if (f == null) {
        Log.warn(QueryExecutionFactory.class, "Failed to find a QueryEngineFactory");
        return null;
    }
    return new QueryExecutionBase(query, dataset, context, f);
}
Also used : QueryEngineFactory(org.apache.jena.sparql.engine.QueryEngineFactory) QueryExecutionBase(org.apache.jena.sparql.engine.QueryExecutionBase) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 25 with DatasetGraph

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

the class TestAPI method testARQConstructQuad_Prefix.

// Allow duplicated template quads in execConstructQuads()
@Test
public void testARQConstructQuad_Prefix() {
    String queryString = "PREFIX :   <http://example/ns#> CONSTRUCT { GRAPH :g1 { ?s :p ?o} } WHERE { ?s ?p ?o }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Iterator<Quad> quads = qExec.execConstructQuads();
    DatasetGraph result = DatasetGraphFactory.create();
    long count = 0;
    while (quads.hasNext()) {
        count++;
        Quad qd = quads.next();
        result.add(qd);
    }
    DatasetGraph expected = DatasetGraphFactory.create();
    expected.add(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
    assertEquals(1, count);
    assertTrue(IsoMatcher.isomorphic(expected, result));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) 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