use of org.apache.jena.query.QueryExecution in project jena by apache.
the class QueryCommandAssembler method open.
@Override
public Object open(Assembler a, Resource root, Mode mode) {
// Query
Resource queryDesc = getUniqueResource(root, AssemblerVocab.pQuery);
Query query = (Query) a.open(a, queryDesc, mode);
// Dataset
Resource datasetDesc = getUniqueResource(root, AssemblerVocab.pDataset);
Dataset dataset = (Dataset) a.open(a, datasetDesc, mode);
// Output format
String s = GraphUtils.getStringValue(root, AssemblerVocab.pOutputFormat);
if (s == null)
s = "text";
ResultsFormat format = ResultsFormat.lookup(s);
QueryExecution qExec = QueryExecutionFactory.create(query, dataset);
return new QExec(query, qExec, format);
}
use of org.apache.jena.query.QueryExecution in project jena by apache.
the class StoreUtils method containsGraph.
public static boolean containsGraph(Store store, Node graphNode) {
String qs = "SELECT * { GRAPH " + FmtUtils.stringForNode(graphNode) + " { ?s ?p ?o }} LIMIT 1";
Dataset ds = SDBFactory.connectDataset(store);
try (QueryExecution qExec = QueryExecutionFactory.create(qs, ds)) {
ResultSet rs = qExec.execSelect();
return rs.hasNext();
}
}
use of org.apache.jena.query.QueryExecution 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.QueryExecution in project jena by apache.
the class TestDatasetWithLuceneStoredLiterals method doTestSearchWithLiterals.
protected Map<String, Literal> doTestSearchWithLiterals(String turtle, String queryString, Set<String> expectedEntityURIs) {
Model model = dataset.getDefaultModel();
Reader reader = new StringReader(turtle);
dataset.begin(ReadWrite.WRITE);
model.read(reader, "", "TURTLE");
dataset.commit();
Map<String, Literal> literals = new HashMap<>();
Query query = QueryFactory.create(queryString);
dataset.begin(ReadWrite.READ);
try (QueryExecution qexec = QueryExecutionFactory.create(query, dataset)) {
ResultSet results = qexec.execSelect();
assertEquals(expectedEntityURIs.size() > 0, results.hasNext());
int count;
for (count = 0; results.hasNext(); count++) {
QuerySolution soln = results.nextSolution();
String entityUri = soln.getResource("s").getURI();
assertTrue(expectedEntityURIs.contains(entityUri));
Literal literal = soln.getLiteral("literal");
assertNotNull(literal);
literals.put(entityUri, literal);
}
assertEquals(expectedEntityURIs.size(), count);
} finally {
dataset.end();
}
return literals;
}
use of org.apache.jena.query.QueryExecution in project jena by apache.
the class QueryEngineTest method testOpenQueryType.
@Test
public void testOpenQueryType() {
final SecurityEvaluator eval = new MockSecurityEvaluator(true, true, true, true, true, true);
final SecuredModel model = Factory.getInstance(eval, "http://example.com/securedModel", baseModel);
try {
final String query = "prefix fn: <http://www.w3.org/2005/xpath-functions#> " + " SELECT ?foo ?bar WHERE " + " { ?foo a <http://example.com/class> ; " + "?bar [] ." + " } ";
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
final ResultSet results = qexec.execSelect();
int count = 0;
for (; results.hasNext(); ) {
count++;
results.nextSolution();
}
Assert.assertEquals(8, count);
}
} finally {
model.close();
}
}
Aggregations