jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sal...@apache.org
Subject svn commit: r1339948 - in /jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena: query/QueryExecution.java sparql/engine/QueryExecutionBase.java sparql/engine/http/QueryEngineHTTP.java
Date Fri, 18 May 2012 01:43:01 GMT
Author: sallen
Date: Fri May 18 01:43:01 2012
New Revision: 1339948

URL: http://svn.apache.org/viewvc?rev=1339948&view=rev
Log:
Added execDescribeTriples() to QueryExecution for streaming DESCRIBE queries.

Modified:
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecution.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/QueryExecutionBase.java
    jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecution.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecution.java?rev=1339948&r1=1339947&r2=1339948&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecution.java (original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/query/QueryExecution.java Fri May 18
01:43:01 2012
@@ -93,9 +93,18 @@ public interface QueryExecution
     public Model execDescribe();
 
     /** Execute a DESCRIBE query, putting the statements into 'model'.
-     *  @return Model The model argument for casaded code.
+     *  @return Model The model argument for cascaded code.
      */
     public Model execDescribe(Model model);
+    
+    /**
+     * Execute a DESCRIBE query, returning the results as an iterator of {@link Triple}.
+     * <b>Caution:</b> This method may return duplicate Triples.  This method
may be useful if you only
+     * need the results for stream processing, as it can avoid having to place the results
in a Model.
+     * 
+     * @return An iterator of Triple objects (possibly containing duplicates) generated as
the output of the DESCRIBE query.
+     */
+    public Iterator<Triple> execDescribeTriples();
 
     /** Execute an ASK query */
     public boolean execAsk();

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/QueryExecutionBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/QueryExecutionBase.java?rev=1339948&r1=1339947&r2=1339948&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/QueryExecutionBase.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/QueryExecutionBase.java
Fri May 18 01:43:01 2012
@@ -24,8 +24,12 @@ import java.util.List ;
 import java.util.Set ;
 import java.util.concurrent.TimeUnit ;
 
+import org.openjena.atlas.iterator.Iter ;
+import org.openjena.atlas.iterator.IteratorResourceClosing ;
+import org.openjena.atlas.iterator.Transform ;
 import org.openjena.atlas.lib.AlarmClock ;
 import org.openjena.atlas.lib.Callback ;
+import org.openjena.atlas.lib.Closeable ;
 import org.openjena.atlas.lib.Pingback ;
 import org.openjena.atlas.logging.Log ;
 
@@ -44,6 +48,7 @@ import com.hp.hpl.jena.rdf.model.ModelFa
 import com.hp.hpl.jena.rdf.model.RDFNode ;
 import com.hp.hpl.jena.rdf.model.Resource ;
 import com.hp.hpl.jena.rdf.model.Statement ;
+import com.hp.hpl.jena.rdf.model.StmtIterator ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.ARQConstants ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
@@ -351,6 +356,32 @@ public class QueryExecutionBase implemen
         this.close() ;
         return model ; 
     }
+    
+    // TODO not memory efficient
+    @Override
+    public Iterator<Triple> execDescribeTriples()
+    {
+        Model model = execDescribe() ;
+        
+        // TODO Is this the best way to get an Iterator<Triple> out of a model?
+        final StmtIterator it = model.listStatements() ;
+        return new IteratorResourceClosing<Triple>(Iter.map(it, new Transform<Statement,
Triple>()
+        {
+            @Override
+            public Triple convert(Statement item)
+            {
+                return item.asTriple() ;
+            }
+        }),
+        new Closeable()
+        {
+            @Override
+            public void close()
+            {
+                it.close() ;
+            }
+        });
+    }
 
     @Override
     public boolean execAsk()

Modified: jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java?rev=1339948&r1=1339947&r2=1339948&view=diff
==============================================================================
--- jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
(original)
+++ jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.java
Fri May 18 01:43:01 2012
@@ -243,16 +243,22 @@ public class QueryEngineHTTP implements 
     }
 
     @Override
-    public Model execConstruct()             { return execConstruct(GraphFactory.makeJenaDefaultModel())
; }
+    public Model execConstruct()                   { return execConstruct(GraphFactory.makeJenaDefaultModel())
; }
     
     @Override
-    public Model execConstruct(Model model)  { return execModel(model) ; }
+    public Model execConstruct(Model model)        { return execModel(model) ; }
+    
+    @Override
+    public Iterator<Triple> execConstructTriples() { return execTriples() ; }
 
     @Override
-    public Model execDescribe()              { return execDescribe(GraphFactory.makeJenaDefaultModel())
; }
+    public Model execDescribe()                    { return execDescribe(GraphFactory.makeJenaDefaultModel())
; }
     
     @Override
-    public Model execDescribe(Model model)   { return execModel(model) ; }
+    public Model execDescribe(Model model)         { return execModel(model) ; }
+    
+    @Override
+    public Iterator<Triple> execDescribeTriples()  { return execTriples() ; }
 
     private Model execModel(Model model)
     {
@@ -278,8 +284,7 @@ public class QueryEngineHTTP implements 
         return model ;
     }
     
-    @Override
-    public Iterator<Triple> execConstructTriples()
+    private Iterator<Triple> execTriples()
     {
         HttpQuery httpQuery = makeHttpQuery() ;
         httpQuery.setAccept(modelContentType) ;



Mime
View raw message