You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2014/04/16 08:42:40 UTC
svn commit: r1587815 - in /stanbol/branches/release-0.12/commons/owl/src:
main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
Author: rwesten
Date: Wed Apr 16 06:42:40 2014
New Revision: 1587815
URL: http://svn.apache.org/r1587815
Log:
applied patch for STANBOL-1307
Modified:
stanbol/branches/release-0.12/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
stanbol/branches/release-0.12/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
Modified: stanbol/branches/release-0.12/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java?rev=1587815&r1=1587814&r2=1587815&view=diff
==============================================================================
--- stanbol/branches/release-0.12/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java (original)
+++ stanbol/branches/release-0.12/commons/owl/src/main/java/org/apache/stanbol/commons/owl/RunSingleSPARQL.java Wed Apr 16 06:42:40 2014
@@ -165,12 +165,12 @@ public class RunSingleSPARQL {
}
/**
- * 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()){
@@ -182,19 +182,16 @@ public class RunSingleSPARQL {
}
query = prefix+query;
- try{
- QueryExecution qexec = QueryExecutionFactory.create(query,jenamodel);
- ResultSet results = qexec.execSelect();
-
- return results;
- }catch (Exception e){
- e.printStackTrace();
- return null;
- }
- }else{
- System.err.println("There is not prefix defined in sparqlprefix.");
+ try{
+ return QueryExecutionFactory.create(query,jenamodel);
+ }catch (Exception e){
+ e.printStackTrace();
return null;
- }
+ }
+ }else{
+ System.err.println("There is not prefix defined in sparqlprefix.");
+ return null;
+ }
}
Modified: stanbol/branches/release-0.12/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java
URL: http://svn.apache.org/viewvc/stanbol/branches/release-0.12/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java?rev=1587815&r1=1587814&r2=1587815&view=diff
==============================================================================
--- stanbol/branches/release-0.12/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java (original)
+++ stanbol/branches/release-0.12/commons/owl/src/test/java/org/apache/stanbol/commons/owl/RunSingleSPARQLTest.java Wed Apr 16 06:42:40 2014
@@ -27,6 +27,7 @@ import java.io.File;
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 @@ public class RunSingleSPARQLTest {
}
/**
- * Test of runSPARQL method, of class RunSingleSPARQL.
+ * Tests 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 @@ public class RunSingleSPARQLTest {
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 @@ public class RunSingleSPARQLTest {
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");
}
}