Search in sources :

Example 11 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class SPARQLQueryProcessor method createQueryExecution.

/**
 * Create the {@link QueryExecution} for this operation.
 * @param action
 * @param query
 * @param dataset
 * @return QueryExecution
 */
protected QueryExecution createQueryExecution(HttpAction action, Query query, DatasetGraph dataset) {
    QueryExecDatasetBuilder builder = QueryExec.newBuilder().dataset(dataset).query(query).context(action.getContext());
    setTimeouts(builder, action);
    QueryExec qExec = builder.build();
    return QueryExecutionAdapter.adapt(qExec);
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) QueryExecDatasetBuilder(org.apache.jena.sparql.exec.QueryExecDatasetBuilder)

Example 12 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestService method service_query_extra_params_oldstyle_by_context_1.

// Uses a HttpRequestModifier to check the changes.
@Test
public void service_query_extra_params_oldstyle_by_context_1() {
    Map<String, Map<String, List<String>>> testServiceParams = new HashMap<>();
    Map<String, List<String>> settings = new HashMap<>();
    settings.put("apikey", List.of("BristolCalling"));
    testServiceParams.put(SERVICE, settings);
    DatasetGraph clientDGS = localDataset();
    clientDGS.getContext().set(ARQ.serviceParams, testServiceParams);
    AtomicBoolean seen = new AtomicBoolean(false);
    HttpRequestModifier inspector = (params, header) -> {
        seen.set(params.containsParam("apikey"));
    };
    logOnlyErrors(Fuseki.class, () -> {
        runWithModifier(SERVICE, inspector, () -> {
            String queryString = "ASK { SERVICE <" + SERVICE + "> { BIND(now() AS ?now) } }";
            try (QueryExec qExec = QueryExec.dataset(clientDGS).query(queryString).build()) {
                boolean b = qExec.ask();
                assertTrue(b);
            }
        });
    });
    assertTrue(seen.get());
}
Also used : ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) Context(org.apache.jena.sparql.util.Context) Binding(org.apache.jena.sparql.engine.binding.Binding) LogCtl(org.apache.jena.atlas.logging.LogCtl) BeforeClass(org.junit.BeforeClass) NodeFactory(org.apache.jena.graph.NodeFactory) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) RDFLinkFactory(org.apache.jena.rdflink.RDFLinkFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BasicPattern(org.apache.jena.sparql.core.BasicPattern) HashMap(java.util.HashMap) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) StrUtils(org.apache.jena.atlas.lib.StrUtils) Algebra(org.apache.jena.sparql.algebra.Algebra) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) OpService(org.apache.jena.sparql.algebra.op.OpService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Op(org.apache.jena.sparql.algebra.Op) Fuseki(org.apache.jena.fuseki.Fuseki) Iter(org.apache.jena.atlas.iterator.Iter) DatasetGraphZero(org.apache.jena.sparql.core.DatasetGraphZero) EnvTest(org.apache.jena.test.conn.EnvTest) Before(org.junit.Before) Element(org.apache.jena.sparql.syntax.Element) AfterClass(org.junit.AfterClass) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) org.apache.jena.query(org.apache.jena.query) Test(org.junit.Test) QueryIterService(org.apache.jena.sparql.engine.main.iterator.QueryIterService) ElementService(org.apache.jena.sparql.syntax.ElementService) List(java.util.List) SSE(org.apache.jena.sparql.sse.SSE) Node(org.apache.jena.graph.Node) Assert(org.junit.Assert) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) QueryExec(org.apache.jena.sparql.exec.QueryExec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryExec(org.apache.jena.sparql.exec.QueryExec) HashMap(java.util.HashMap) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 13 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestService method service_query_silent_no_service.

@Test
public void service_query_silent_no_service() {
    logOnlyErrors(QueryIterService.class, () -> {
        DatasetGraph dsg = env.dsg();
        String queryString = "SELECT * { SERVICE SILENT <" + SERVICE + "JUNK> { VALUES ?X { 1 2 } }} ";
        try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
            try (QueryExec qExec = link.query(queryString)) {
                RowSet rs = qExec.select();
                assertTrue(rs.hasNext());
                Binding binding = rs.next();
                assertFalse(rs.hasNext());
                assertTrue(binding.isEmpty());
            }
        }
    });
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 14 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestService method service_query_extra_params_oldstyle_by_context_2.

// Uses a HttpRequestModifier to check the changes.
@Test
public void service_query_extra_params_oldstyle_by_context_2() {
    Map<String, Map<String, List<String>>> testServiceParams = new HashMap<>();
    Map<String, List<String>> settings = new HashMap<>();
    settings.put("apikey", List.of("BristolCallingToTheFarawayTowns"));
    testServiceParams.put(SERVICE, settings);
    DatasetGraph clientDGS = localDataset();
    clientDGS.getContext().set(ARQ.serviceParams, testServiceParams);
    AtomicBoolean seen = new AtomicBoolean(false);
    HttpRequestModifier inspector = (params, header) -> {
        seen.set(params.containsParam("apikey"));
    };
    logOnlyErrors(Fuseki.class, () -> {
        runWithModifier(SERVICE, inspector, () -> {
            String queryString = "ASK { SERVICE <" + SERVICE + "> { BIND(now() AS ?now) } }";
            try (QueryExec qExec = QueryExec.dataset(clientDGS).query(queryString).build()) {
                boolean b = qExec.ask();
                assertTrue(b);
            }
        });
    });
    assertTrue(seen.get());
}
Also used : ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) Context(org.apache.jena.sparql.util.Context) Binding(org.apache.jena.sparql.engine.binding.Binding) LogCtl(org.apache.jena.atlas.logging.LogCtl) BeforeClass(org.junit.BeforeClass) NodeFactory(org.apache.jena.graph.NodeFactory) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) RDFLinkFactory(org.apache.jena.rdflink.RDFLinkFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BasicPattern(org.apache.jena.sparql.core.BasicPattern) HashMap(java.util.HashMap) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) StrUtils(org.apache.jena.atlas.lib.StrUtils) Algebra(org.apache.jena.sparql.algebra.Algebra) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) OpService(org.apache.jena.sparql.algebra.op.OpService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Op(org.apache.jena.sparql.algebra.Op) Fuseki(org.apache.jena.fuseki.Fuseki) Iter(org.apache.jena.atlas.iterator.Iter) DatasetGraphZero(org.apache.jena.sparql.core.DatasetGraphZero) EnvTest(org.apache.jena.test.conn.EnvTest) Before(org.junit.Before) Element(org.apache.jena.sparql.syntax.Element) AfterClass(org.junit.AfterClass) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) org.apache.jena.query(org.apache.jena.query) Test(org.junit.Test) QueryIterService(org.apache.jena.sparql.engine.main.iterator.QueryIterService) ElementService(org.apache.jena.sparql.syntax.ElementService) List(java.util.List) SSE(org.apache.jena.sparql.sse.SSE) Node(org.apache.jena.graph.Node) Assert(org.junit.Assert) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) QueryExec(org.apache.jena.sparql.exec.QueryExec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueryExec(org.apache.jena.sparql.exec.QueryExec) HashMap(java.util.HashMap) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 15 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestService method service_query_bad_no_service.

@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_no_service() {
    DatasetGraph dsg = env.dsg();
    dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
    // Not a service of the dataset.
    String queryString = "SELECT * { SERVICE <" + SERVICE + "/JUNK> { ?s ?p ?o }} ";
    // Connect to local, unused, permanently empty dataset
    try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
        try (QueryExec qExec = link.query(queryString)) {
            RowSet rs = qExec.select();
            // Should go on execution.
            rs.hasNext();
            fail("Should not get here");
        }
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Aggregations

QueryExec (org.apache.jena.sparql.exec.QueryExec)21 Test (org.junit.Test)18 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)14 EnvTest (org.apache.jena.test.conn.EnvTest)12 RowSet (org.apache.jena.sparql.exec.RowSet)11 RDFLink (org.apache.jena.rdflink.RDFLink)10 HttpRequestModifier (org.apache.jena.http.sys.HttpRequestModifier)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Graph (org.apache.jena.graph.Graph)4 Node (org.apache.jena.graph.Node)4 Triple (org.apache.jena.graph.Triple)3 RegistryRequestModifier (org.apache.jena.http.sys.RegistryRequestModifier)3 RDFLinkFactory (org.apache.jena.rdflink.RDFLinkFactory)3 SSE (org.apache.jena.sparql.sse.SSE)3 AfterClass (org.junit.AfterClass)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 HashMap (java.util.HashMap)2 List (java.util.List)2