Search in sources :

Example 66 with DatasetGraph

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

the class AbstractDatasetGraphTests method create_1.

@Test
public void create_1() {
    DatasetGraph dsg = emptyDataset();
    assertNotNull(dsg);
    assertNotNull(dsg.getDefaultGraph());
    assertTrue(dsg.getDefaultGraph().isEmpty());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 67 with DatasetGraph

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

the class AbstractDatasetGraphTests method graph_01.

// Graph centric operations
@Test
public void graph_01() {
    DatasetGraph dsg = emptyDataset();
    assertNotNull(dsg);
    Node g = NodeFactory.createURI("g");
    Triple t = SSE.parseTriple("(<s> <p> <o>)");
    dsg.getGraph(g).add(t);
    assertTrue(dsg.getGraph(g).contains(t));
    Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)");
    Iterator<Quad> iter = dsg.find(null, null, null, null);
    assertTrue(iter.hasNext());
    Quad quad2 = iter.next();
    assertFalse(iter.hasNext());
    assertEquals(quad, quad2);
    assertTrue(dsg.getDefaultGraph().isEmpty());
    assertFalse(dsg.getGraph(NodeFactory.createURI("g")).isEmpty());
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 68 with DatasetGraph

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

the class update method execUpdate.

// Subclass for specialised commands making common updates more convenient
@Override
protected void execUpdate(DatasetGraph graphStore) {
    if (requestFiles.size() == 0 && getPositional().size() == 0)
        throw new CmdException("Nothing to do");
    Transactional transactional = (graphStore.supportsTransactionAbort()) ? graphStore : new TransactionalNull();
    for (String filename : requestFiles) {
        try {
            transactional.begin(ReadWrite.WRITE);
            execOneFile(filename, graphStore);
            transactional.commit();
        } catch (Throwable ex) {
            try {
                transactional.abort();
            } catch (Exception ex2) {
            }
            throw ex;
        } finally {
            transactional.end();
        }
    }
    for (String requestString : super.getPositional()) {
        String requestString2 = indirect(requestString);
        Txn.executeWrite(transactional, () -> execOne(requestString2, graphStore));
    }
    if (!(transactional instanceof DatasetGraph))
        SystemARQ.sync(graphStore);
    if (dump)
        RDFDataMgr.write(System.out, graphStore, Lang.NQUADS);
}
Also used : TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) CmdException(jena.cmd.CmdException) CmdException(jena.cmd.CmdException) Transactional(org.apache.jena.sparql.core.Transactional) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 69 with DatasetGraph

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

the class sse_query method exec.

@Override
protected void exec() {
    Op op = modAlgebra.getOp();
    if (op == null) {
        System.err.println("No query expression to execute");
        throw new TerminationException(9);
    }
    Dataset dataset = modDataset.getDataset();
    // Check there is a dataset.
    if (dataset == null)
        dataset = DatasetFactory.createGeneral();
    modTime.startTimer();
    DatasetGraph dsg = dataset.asDatasetGraph();
    if (printOp || printPlan) {
        if (printOp) {
            divider();
            IndentedWriter out = new IndentedWriter(System.out, true);
            op.output(out);
            out.flush();
        }
        if (printPlan) {
            QueryIterator qIter = Algebra.exec(op, dsg);
            Plan plan = new PlanOp(op, null, qIter);
            divider();
            IndentedWriter out = new IndentedWriter(System.out, false);
            plan.output(out);
            out.flush();
        }
    //return ;
    }
    // Do not optimize.  Execute as-is.
    QueryExecUtils.execute(op, dsg, modResults.getResultsFormat());
    long time = modTime.endTimer();
    if (modTime.timingEnabled())
        System.out.println("Time: " + modTime.timeStr(time));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) PlanOp(org.apache.jena.sparql.engine.PlanOp) Op(org.apache.jena.sparql.algebra.Op) TerminationException(jena.cmd.TerminationException) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ModDataset(arq.cmdline.ModDataset) Dataset(org.apache.jena.query.Dataset) PlanOp(org.apache.jena.sparql.engine.PlanOp) Plan(org.apache.jena.sparql.engine.Plan) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 70 with DatasetGraph

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

the class TestDatasetOps method gsp_x_ct.

private void gsp_x_ct(String urlDataset, String acceptheader, String contentTypeResponse) {
    HttpEntity e = datasetToHttpEntity(data);
    HttpOp.execHttpPut(urlDataset(), e);
    // Do manually so the test can validate the expected ContentType
    try (TypedInputStream in = HttpOp.execHttpGet(urlDataset, acceptheader)) {
        assertEqualsIgnoreCase(contentTypeResponse, in.getContentType());
        Lang lang = RDFLanguages.contentTypeToLang(in.getContentType());
        DatasetGraph dsg = DatasetGraphFactory.create();
        StreamRDF dest = StreamRDFLib.dataset(dsg);
        RDFParser.source(in).lang(lang).parse(dest);
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) StreamRDF(org.apache.jena.riot.system.StreamRDF) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

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