@Test public void testQuery() { graph.add(statements); String queryString = "SELECT ?subj ?pred ?obj " + "WHERE {" + " ?subj ?pred ?obj " + " }"; QueryResult res = graph.query(queryString, "sparql", null); assertSame(3, res.getCount()); List<String> variableNames = new ArrayList<>(); variableNames.add("subj"); variableNames.add("pred"); variableNames.add("obj"); assertEquals(variableNames, res.getVariableNames()); queryString = "PREFIX dcterms: <http: + " ?subj dcterms:References ?obj ." + " }"; res = graph.query(queryString, "sparql", null); assertSame(2, res.getCount()); variableNames.remove("pred"); assertEquals(variableNames, res.getVariableNames()); }
@Override public QueryResult query(String queryString, String language, String baseURI) { Model graph = null; GraphConnection graphConnection = null; QueryResult res = null; QueryExecution qe = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); log.debug(String.format("Running query %s", queryString)); if (language != null && !language.equals("sparql")) { log.warn(String.format("Unknown language %s for query, using SPARQL", language)); } Query query = QueryFactory.create(queryString); query.setBaseURI(baseURI); qe = QueryExecutionFactory.create(query, graph); res = new QueryResultImpl(0, new ArrayList<String>(), new ArrayList<Map<String, Node>>()); ResultSet jenaResults = qe.execSelect(); Integer count = 0; List<String> variableNames = jenaResults.getResultVars(); List<Map<String, Node>> nuxResults = new ArrayList<>(); while (jenaResults.hasNext()) { QuerySolution soln = jenaResults.nextSolution(); Map<String, Node> nuxSol = new HashMap<>(); for (String varName : variableNames) { RDFNode x = soln.get(varName); nuxSol.put(varName, getNXRelationsNode(x.asNode())); } nuxResults.add(nuxSol); count++; } res = new QueryResultImpl(count, variableNames, nuxResults); } finally { if (qe != null) { qe.close(); } if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } return res; }
JenaGraph implements Graph { @Override public QueryResult query(String queryString, String language, String baseURI) { Model graph = null; GraphConnection graphConnection = null; QueryResult res = null; QueryExecution qe = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); log.debug(String.format("Running query %s", queryString)); if (language != null && !language.equals("sparql")) { log.warn(String.format("Unknown language %s for query, using SPARQL", language)); } Query query = QueryFactory.create(queryString); query.setBaseURI(baseURI); qe = QueryExecutionFactory.create(query, graph); res = new QueryResultImpl(0, new ArrayList<String>(), new ArrayList<Map<String, Node>>()); ResultSet jenaResults = qe.execSelect(); Integer count = 0; List<String> variableNames = jenaResults.getResultVars(); List<Map<String, Node>> nuxResults = new ArrayList<>(); while (jenaResults.hasNext()) { QuerySolution soln = jenaResults.nextSolution(); Map<String, Node> nuxSol = new HashMap<>(); for (String varName : variableNames) { RDFNode x = soln.get(varName); nuxSol.put(varName, getNXRelationsNode(x.asNode())); } nuxResults.add(nuxSol); count++; } res = new QueryResultImpl(count, variableNames, nuxResults); } finally { if (qe != null) { qe.close(); } if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } return res; } }
JenaGraph implements Graph { @Override public QueryResult query(String queryString, String language, String baseURI) { Model graph = null; GraphConnection graphConnection = null; QueryResult res = null; QueryExecution qe = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); log.debug(String.format("Running query %s", queryString)); if (language != null && !language.equals("sparql")) { log.warn(String.format("Unknown language %s for query, using SPARQL", language)); } Query query = QueryFactory.create(queryString); query.setBaseURI(baseURI); qe = QueryExecutionFactory.create(query, graph); res = new QueryResultImpl(0, new ArrayList<String>(), new ArrayList<Map<String, Node>>()); ResultSet jenaResults = qe.execSelect(); Integer count = 0; List<String> variableNames = jenaResults.getResultVars(); List<Map<String, Node>> nuxResults = new ArrayList<>(); while (jenaResults.hasNext()) { QuerySolution soln = jenaResults.nextSolution(); Map<String, Node> nuxSol = new HashMap<>(); for (String varName : variableNames) { RDFNode x = soln.get(varName); nuxSol.put(varName, getNXRelationsNode(x.asNode())); } nuxResults.add(nuxSol); count++; } res = new QueryResultImpl(count, variableNames, nuxResults); } finally { if (qe != null) { qe.close(); } if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } return res; }  }
JenaGraph implements Graph { @Override public QueryResult query(String queryString, String language, String baseURI) { Model graph = null; GraphConnection graphConnection = null; QueryResult res = null; QueryExecution qe = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); log.debug(String.format("Running query %s", queryString)); if (language != null && !language.equals("sparql")) { log.warn(String.format("Unknown language %s for query, using SPARQL", language)); } Query query = QueryFactory.create(queryString); query.setBaseURI(baseURI); qe = QueryExecutionFactory.create(query, graph); res = new QueryResultImpl(0, new ArrayList<String>(), new ArrayList<Map<String, Node>>()); ResultSet jenaResults = qe.execSelect(); Integer count = 0; List<String> variableNames = jenaResults.getResultVars(); List<Map<String, Node>> nuxResults = new ArrayList<>(); while (jenaResults.hasNext()) { QuerySolution soln = jenaResults.nextSolution(); Map<String, Node> nuxSol = new HashMap<>(); for (String varName : variableNames) { RDFNode x = soln.get(varName); nuxSol.put(varName, getNXRelationsNode(x.asNode())); } nuxResults.add(nuxSol); count++; } res = new QueryResultImpl(count, variableNames, nuxResults); } finally { if (qe != null) { qe.close(); } if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } return res; }  @Override void setDescription(GraphDescription graphDescription); void setNamespaces(Map<String, String> namespaces); @Override Map<String, String> getNamespaces(); @Override void add(Statement statement); @Override void add(List<Statement> statements); @Override void remove(Statement statement); @Override void remove(List<Statement> statements); @Override List<Statement> getStatements(); @Override List<Statement> getStatements(Node subject, Node predicate, Node object); @Override List<Statement> getStatements(Statement statement); @Override List<Node> getSubjects(Node predicate, Node object); @Override List<Node> getPredicates(Node subject, Node object); @Override List<Node> getObjects(Node subject, Node predicate); @Override boolean hasStatement(Statement statement); @Override boolean hasResource(Resource resource); @Override Long size(); @Override void clear(); @Override QueryResult query(String queryString, String language, String baseURI); @Override int queryCount(String queryString, String language, String baseURI); @Override boolean read(InputStream in, String lang, String base); @Override boolean read(String path, String lang, String base); @Override boolean write(OutputStream out, String lang, String base); @Override boolean write(String path, String lang, String base); }
JenaGraph implements Graph { @Override public QueryResult query(String queryString, String language, String baseURI) { Model graph = null; GraphConnection graphConnection = null; QueryResult res = null; QueryExecution qe = null; try { graphConnection = openGraph(); graph = graphConnection.getGraph(); graph.enterCriticalSection(Lock.READ); log.debug(String.format("Running query %s", queryString)); if (language != null && !language.equals("sparql")) { log.warn(String.format("Unknown language %s for query, using SPARQL", language)); } Query query = QueryFactory.create(queryString); query.setBaseURI(baseURI); qe = QueryExecutionFactory.create(query, graph); res = new QueryResultImpl(0, new ArrayList<String>(), new ArrayList<Map<String, Node>>()); ResultSet jenaResults = qe.execSelect(); Integer count = 0; List<String> variableNames = jenaResults.getResultVars(); List<Map<String, Node>> nuxResults = new ArrayList<>(); while (jenaResults.hasNext()) { QuerySolution soln = jenaResults.nextSolution(); Map<String, Node> nuxSol = new HashMap<>(); for (String varName : variableNames) { RDFNode x = soln.get(varName); nuxSol.put(varName, getNXRelationsNode(x.asNode())); } nuxResults.add(nuxSol); count++; } res = new QueryResultImpl(count, variableNames, nuxResults); } finally { if (qe != null) { qe.close(); } if (graph != null) { graph.leaveCriticalSection(); } if (graphConnection != null) { graphConnection.close(); } } return res; }  @Override void setDescription(GraphDescription graphDescription); void setNamespaces(Map<String, String> namespaces); @Override Map<String, String> getNamespaces(); @Override void add(Statement statement); @Override void add(List<Statement> statements); @Override void remove(Statement statement); @Override void remove(List<Statement> statements); @Override List<Statement> getStatements(); @Override List<Statement> getStatements(Node subject, Node predicate, Node object); @Override List<Statement> getStatements(Statement statement); @Override List<Node> getSubjects(Node predicate, Node object); @Override List<Node> getPredicates(Node subject, Node object); @Override List<Node> getObjects(Node subject, Node predicate); @Override boolean hasStatement(Statement statement); @Override boolean hasResource(Resource resource); @Override Long size(); @Override void clear(); @Override QueryResult query(String queryString, String language, String baseURI); @Override int queryCount(String queryString, String language, String baseURI); @Override boolean read(InputStream in, String lang, String base); @Override boolean read(String path, String lang, String base); @Override boolean write(OutputStream out, String lang, String base); @Override boolean write(String path, String lang, String base);  }