applied patch for STANBOL-1307
git-svn-id: https://svn.apache.org/repos/asf/stanbol/trunk@1587816 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java b/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
index 3558569..e632e5f 100644
--- a/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
+++ b/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
@@ -165,12 +165,12 @@
}
/**
- * To run a SPARQL query
- *
- * @param query {The query string without the declaration of the prefixes.}
- * @return {Return a Jena Result Set Object.}
- */
- public ResultSet runSPARQL(String query){
+ * To create a SPARQL QueryExecution Object
+ *
+ * @param query {The query string without the declaration of the prefixes.}
+ * @return {Return a QueryExecution Object.}
+ */
+ public QueryExecution createSPARQLQueryExecutionFactory(String query){
if(!sparqlprefix.isEmpty()){
@@ -183,10 +183,7 @@
query = prefix+query;
try{
- QueryExecution qexec = QueryExecutionFactory.create(query,jenamodel);
- ResultSet results = qexec.execSelect();
-
- return results;
+ return QueryExecutionFactory.create(query,jenamodel);
}catch (Exception e){
e.printStackTrace();
return null;
diff --git a/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java b/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
index b57c160..c50d258 100644
--- a/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
+++ b/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
@@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Map;
+import com.hp.hpl.jena.query.QueryExecution;
import org.apache.stanbol.commons.owl.RunSingleSPARQL;
import org.junit.After;
import org.junit.AfterClass;
@@ -148,10 +149,10 @@
}
/**
- * Test of runSPARQL method, of class RunSingleSPARQL.
+ * Test of testCreateSPARQLQueryExecutionFactory() method, of class RunSingleSPARQL.
*/
@Test
- public void testRunSPARQL() {
+ public void testCreateSPARQLQueryExecutionFactory() {
Map<String,String> map = new HashMap<String,String>();
map.put("rdfs","<http://www.w3.org/2000/01/rdf-schema#>");
map.put("xsd","<http://www.w3.org/2000/01/rdf-schema#>");
@@ -160,7 +161,11 @@
map.put("ex","<http://www.semanticweb.org/ontologies/2010/6/ProvaParent.owl#>");
String query = "SELECT * WHERE {?p rdf:type ex:Person .}";
RunSingleSPARQL instance = new RunSingleSPARQL(owl,map);
- ResultSet result = instance.runSPARQL(query);
+ QueryExecution queryExecution = instance.createSPARQLQueryExecutionFactory(query);
+ if (queryExecution == null) {
+ fail("Some errors occurred in createSPARQLQueryExecutionFactory of KReSRunSPARQL");
+ }
+ ResultSet result = queryExecution.execSelect();
if(result!=null){
int m = 0;
@@ -168,10 +173,11 @@
result.next();
m++;
}
+ queryExecution.close();
assertEquals(3, m);
// TODO review the generated test code and remove the default call to fail.
}else{
- fail("Some errors occur in runSPARQL of KReSRunSPARQL");
+ fail("Some errors occur in createSPARQLQueryExecutionFactory of KReSRunSPARQL");
}
}