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();
}
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();
}
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);
}
}
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);
}
}
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());
}
Aggregations