Search in sources :

Example 6 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestServerReadOnly method query_readonly.

@Test
public void query_readonly() {
    Query query = QueryFactory.create("ASK{}");
    QueryExecution qexec = QueryExecutionFactory.sparqlService(serviceQuery(), query);
    qexec.execAsk();
}
Also used : Query(org.apache.jena.query.Query) ServerCtl.serviceQuery(org.apache.jena.fuseki.ServerCtl.serviceQuery) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 7 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class AlgebraEx method main.

public static void main(String[] args) {
    String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
    // Parse
    Query query = QueryFactory.create(s);
    System.out.println(query);
    // Generate algebra
    Op op = Algebra.compile(query);
    op = Algebra.optimize(op);
    System.out.println(op);
    // Execute it.
    QueryIterator qIter = Algebra.exec(op, ExQuerySelect1.createModel());
    // Results
    for (; qIter.hasNext(); ) {
        Binding b = qIter.nextBinding();
        System.out.println(b);
    }
    qIter.close();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) Query(org.apache.jena.query.Query) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 8 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestService method query_service_context_application_03.

@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_03() {
    // This test requires us to set some timeouts for the service
    Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap == null) {
        ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
        serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    }
    if (serviceContextMap.get(SERVICE) == null) {
        serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
    }
    Context serviceContext = serviceContextMap.get(SERVICE);
    try {
        serviceContext.put(Service.queryTimeout, "10");
        Query q = QueryFactory.create("ASK { }");
        QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
        Assert.assertNotNull(engine);
        // Check that no settings were changed
        Assert.assertEquals(-1, engine.getTimeout1());
        Assert.assertEquals(10, engine.getTimeout2());
        Assert.assertTrue(engine.getAllowCompression());
        Assert.assertNull(engine.getClient());
    } finally {
        serviceContext.remove(Service.queryTimeout);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestService method query_service_context_application_04.

@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_04() {
    // This test requires us to set some timeouts for the service
    Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap == null) {
        ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
        serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    }
    if (serviceContextMap.get(SERVICE) == null) {
        serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
    }
    Context serviceContext = serviceContextMap.get(SERVICE);
    try {
        serviceContext.put(Service.queryTimeout, "10,20");
        Query q = QueryFactory.create("ASK { }");
        QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
        Assert.assertNotNull(engine);
        // Check that no settings were changed
        Assert.assertEquals(20, engine.getTimeout1());
        Assert.assertEquals(10, engine.getTimeout2());
        Assert.assertTrue(engine.getAllowCompression());
        Assert.assertNull(engine.getClient());
    } finally {
        serviceContext.remove(Service.queryTimeout);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class TestService method query_service_context_application_01.

@Test
public void query_service_context_application_01() {
    // This test requires no service context to be set
    @SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap != null) {
        serviceContextMap.remove(SERVICE);
    }
    Query q = QueryFactory.create("ASK { }");
    QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
    Assert.assertNotNull(engine);
    // Check that no settings were changed
    Assert.assertEquals(-1, engine.getTimeout1());
    Assert.assertEquals(-1, engine.getTimeout2());
    Assert.assertTrue(engine.getAllowCompression());
    Assert.assertNull(engine.getClient());
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Query (org.apache.jena.query.Query)265 Test (org.junit.Test)78 ContractTest (org.xenei.junit.contract.ContractTest)65 QueryExecution (org.apache.jena.query.QueryExecution)63 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)49 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)42 Var (org.apache.jena.sparql.core.Var)42 Triple (org.apache.jena.graph.Triple)38 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)32 ResultSet (org.apache.jena.query.ResultSet)29 Node (org.apache.jena.graph.Node)28 TriplePath (org.apache.jena.sparql.core.TriplePath)28 QuerySolution (org.apache.jena.query.QuerySolution)26 ExprVar (org.apache.jena.sparql.expr.ExprVar)24 Binding (org.apache.jena.sparql.engine.binding.Binding)22 Model (org.apache.jena.rdf.model.Model)20 HashMap (java.util.HashMap)19 Dataset (org.apache.jena.query.Dataset)15 Op (org.apache.jena.sparql.algebra.Op)15 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)14