Search in sources :

Example 46 with DatasetGraph

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

the class TestEmbeddedFuseki method embedded_07.

// Context path.
@Test
public void embedded_07() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).setContextPath("/ABC").add("/ds", dsg).build();
    server.start();
    try {
        String x1 = HttpOp.execHttpGetString("http://localhost:" + port + "/ds");
        assertNull(x1);
        String x2 = HttpOp.execHttpGetString("http://localhost:" + port + "/ABC/ds");
        assertNotNull(x2);
    } finally {
        server.stop();
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 47 with DatasetGraph

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

the class CmdUpdate method exec.

@Override
protected final void exec() {
    DatasetGraph dataset = modDataset.getDatasetGraph();
    if (dataset == null)
        dataset = dealWithNoDataset();
    if (dataset.getDefaultGraph() == null)
        dataset.setDefaultGraph(ModelFactory.createDefaultModel().getGraph());
    execUpdate(dataset);
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 48 with DatasetGraph

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

the class TurtleShell method writeGraphTTL.

/** Write graph in Turtle syntax (or part of TriG). graphName is null for default graph. */
protected void writeGraphTTL(DatasetGraph dsg, Node graphName) {
    Graph g = (graphName == null || Quad.isDefaultGraph(graphName)) ? dsg.getDefaultGraph() : dsg.getGraph(graphName);
    ShellGraph x = new ShellGraph(g, graphName, dsg);
    x.writeGraph();
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph)

Example 49 with DatasetGraph

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

the class Eval method evalGraph.

static Table evalGraph(OpGraph opGraph, Evaluator evaluator) {
    ExecutionContext execCxt = evaluator.getExecContext();
    if (!Var.isVar(opGraph.getNode())) {
        DatasetGraph dsg = execCxt.getDataset();
        Node graphNode = opGraph.getNode();
        if (!dsg.containsGraph(graphNode))
            return new TableEmpty();
        Graph graph = execCxt.getDataset().getGraph(opGraph.getNode());
        if (// But contains was true?!!
        graph == null)
            throw new InternalErrorException("Graph was present, now it's not");
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        return eval(e2, opGraph.getSubOp());
    }
    // Graph node is a variable.
    Var gVar = Var.alloc(opGraph.getNode());
    Table current = null;
    for (Iterator<Node> iter = execCxt.getDataset().listGraphNodes(); iter.hasNext(); ) {
        Node gn = iter.next();
        Graph graph = execCxt.getDataset().getGraph(gn);
        ExecutionContext execCxt2 = new ExecutionContext(execCxt, graph);
        Evaluator e2 = EvaluatorFactory.create(execCxt2);
        Table tableVarURI = TableFactory.create(gVar, gn);
        // Evaluate the pattern, join with this graph node possibility.
        // XXX If Var.ANON then no-opt.
        Table patternTable = eval(e2, opGraph.getSubOp());
        Table stepResult = evaluator.join(patternTable, tableVarURI);
        if (current == null)
            current = stepResult;
        else
            current = evaluator.union(current, stepResult);
    }
    if (current == null)
        // Nothing to loop over
        return new TableEmpty();
    return current;
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) OpGraph(org.apache.jena.sparql.algebra.op.OpGraph) Graph(org.apache.jena.graph.Graph) Table(org.apache.jena.sparql.algebra.Table) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TableEmpty(org.apache.jena.sparql.algebra.table.TableEmpty) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 50 with DatasetGraph

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

the class QueryIterGraph method nextStage.

@Override
protected QueryIterator nextStage(Binding outerBinding) {
    DatasetGraph ds = getExecContext().getDataset();
    // Is this closed?
    Iterator<Node> graphNameNodes = makeSources(ds, outerBinding, opGraph.getNode());
    //        List<Node> x = Iter.toList(graphNameNodes) ;
    //        graphNameNodes = x.iterator() ;
    //        System.out.println(x) ;
    QueryIterator current = new QueryIterGraphInner(outerBinding, graphNameNodes, opGraph, getExecContext());
    return current;
}
Also used : QueryIterator(org.apache.jena.sparql.engine.QueryIterator) Node(org.apache.jena.graph.Node) 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