jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1450343 - in /jena/trunk/jena-fuseki: ./ src-dev/dev/ src/main/java/org/apache/jena/fuseki/ src/main/java/org/apache/jena/fuseki/servlets/
Date Tue, 26 Feb 2013 18:33:39 GMT
Author: andy
Date: Tue Feb 26 18:33:39 2013
New Revision: 1450343

URL: http://svn.apache.org/r1450343
Log:
Centralize adding data into a graph from a dataset.
Make the implementation of that act on the dataset directly.

Modified:
    jena/trunk/jena-fuseki/config-tdb.ttl
    jena/trunk/jena-fuseki/config.ttl
    jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/FusekiLib.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
    jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java

Modified: jena/trunk/jena-fuseki/config-tdb.ttl
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/config-tdb.ttl?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/config-tdb.ttl (original)
+++ jena/trunk/jena-fuseki/config-tdb.ttl Tue Feb 26 18:33:39 2013
@@ -5,7 +5,7 @@
 @prefix :        <#> .
 @prefix fuseki:  <http://jena.apache.org/fuseki#> .
 @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
 @prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
 @prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
 

Modified: jena/trunk/jena-fuseki/config.ttl
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/config.ttl?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
Binary files - no diff available.

Modified: jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java (original)
+++ jena/trunk/jena-fuseki/src-dev/dev/RunFuseki.java Tue Feb 26 18:33:39 2013
@@ -49,7 +49,6 @@ public class RunFuseki
         return sb.toString() ;
     }
     
-    
     private static void main1()
     {
         FusekiCmd.main(

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/FusekiLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/FusekiLib.java?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/FusekiLib.java (original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/FusekiLib.java Tue Feb 26
18:33:39 2013
@@ -19,6 +19,7 @@
 package org.apache.jena.fuseki;
 
 import java.util.HashMap ;
+import java.util.Iterator ;
 import java.util.Map ;
 
 import javax.servlet.http.HttpServletRequest ;
@@ -31,9 +32,14 @@ import org.apache.jena.riot.RDFLanguages
 import org.apache.jena.riot.RiotException ;
 import org.apache.jena.riot.WebContent ;
 
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.rdf.model.Model ;
 import com.hp.hpl.jena.rdf.model.ModelFactory ;
 import com.hp.hpl.jena.rdf.model.RDFWriter ;
+import com.hp.hpl.jena.sparql.core.DatasetGraph ;
+import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.util.Convert ;
 
 public class FusekiLib
@@ -130,5 +136,21 @@ public class FusekiLib
         value = StringUtils.replaceChars(value, "\n", "") ;
         return value ; 
     }
+    
+    // Do the addition directly on the dataset
+    public static void addDataInto(Graph data, DatasetGraph dsg, Node graphName)
+    {
+        if ( graphName == null )
+            graphName = Quad.defaultGraphNodeGenerated ;
+            
+        Iterator<Triple> iter = data.find(Node.ANY, Node.ANY, Node.ANY) ;
+        for ( ; iter.hasNext() ; )
+        {
+            Triple t = iter.next();
+            dsg.add(graphName, t.getSubject(), t.getPredicate(), t.getObject()) ;
+        }
+    }
+
+
 
 }

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_REST.java
Tue Feb 26 18:33:39 2013
@@ -19,15 +19,7 @@
 package org.apache.jena.fuseki.servlets;
 
 import static java.lang.String.format ;
-import static org.apache.jena.fuseki.HttpNames.HEADER_LASTMOD ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_DELETE ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_GET ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_HEAD ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_OPTIONS ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_PATCH ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_POST ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_PUT ;
-import static org.apache.jena.fuseki.HttpNames.METHOD_TRACE ;
+import static org.apache.jena.fuseki.HttpNames.* ;
 
 import java.io.ByteArrayInputStream ;
 import java.io.IOException ;
@@ -39,6 +31,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse ;
 
 import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
 import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.riot.Lang ;
@@ -52,7 +45,6 @@ import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.GraphUtil ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.core.DatasetGraph ;
 import com.hp.hpl.jena.sparql.core.DatasetGraphFactory ;
@@ -105,7 +97,6 @@ public abstract class SPARQL_REST extend
     {
         final boolean isDefault ;
         final DatasetGraph dsg ;
-        // May be null, then  
         private Graph _graph ;
         final String name ;
         final Node graphName ;
@@ -128,9 +119,6 @@ public abstract class SPARQL_REST extend
             this.name  = name ;
             this.graphName = graphName ;
 
-            //            if ( graph == null )
-            //                throw new IllegalArgumentException("Inconsistent: no graph")
;
-
             if ( isDefault )
             {
                 if ( name != null || graphName != null )
@@ -262,17 +250,20 @@ public abstract class SPARQL_REST extend
         try
         {
             Target dest = action.getTarget() ;
-            Graph g = dest.graph() ;
-            if (g == null)
-            {
-                if (dest.isDefault) errorOccurred("Dataset does not have a default graph")
;
-                log.info(format("[%d] Creating in-memory graph for <%s>", action.id,
dest.graphName)) ;
-                // Not default graph.
-                // Not an autocreate dataset - create something.
-                g = GraphFactory.createDefaultGraph() ;
-                dest.dsg.addGraph(dest.graphName, g) ;
-            }
-            GraphUtil.addInto(g, data) ;
+            FusekiLib.addDataInto(data, dest.dsg, dest.graphName) ;
+            
+//            Graph g = dest.graph() ;
+//            
+//            if (g == null)
+//            {
+//                if (dest.isDefault) errorOccurred("Dataset does not have a default graph")
;
+//                log.info(format("[%d] Creating in-memory graph for <%s>", action.id,
dest.graphName)) ;
+//                // Not default graph.
+//                // Not an autocreate dataset - create something.
+//                g = GraphFactory.createDefaultGraph() ;
+//                dest.dsg.addGraph(dest.graphName, g) ;
+//            }
+//            GraphUtil.addInto(g, data) ;
         } catch (RuntimeException ex)
         {
             // If anything went wrong, try to backout.
@@ -281,7 +272,7 @@ public abstract class SPARQL_REST extend
             return ;
         }
     }
-
+    
     protected static DatasetGraph parseBody(HttpActionREST action)
     {
         String contentTypeHeader = action.request.getContentType() ;

Modified: jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java?rev=1450343&r1=1450342&r2=1450343&view=diff
==============================================================================
--- jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
(original)
+++ jena/trunk/jena-fuseki/src/main/java/org/apache/jena/fuseki/servlets/SPARQL_Upload.java
Tue Feb 26 18:33:39 2013
@@ -32,6 +32,7 @@ import org.apache.commons.fileupload.Fil
 import org.apache.commons.fileupload.servlet.ServletFileUpload ;
 import org.apache.commons.fileupload.util.Streams ;
 import org.apache.jena.atlas.web.ContentType ;
+import org.apache.jena.fuseki.FusekiLib ;
 import org.apache.jena.fuseki.HttpNames ;
 import org.apache.jena.fuseki.server.DatasetRef ;
 import org.apache.jena.iri.IRI ;
@@ -41,8 +42,8 @@ import org.apache.jena.riot.system.* ;
 import org.apache.jena.web.HttpSC ;
 
 import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.GraphUtil ;
 import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.graph.GraphFactory ;
 
 public class SPARQL_Upload extends SPARQL_ServletBase 
@@ -97,16 +98,12 @@ public class SPARQL_Upload extends SPARQ
             
             log.info(format("[%d] Upload: Graph: %s (%d triple(s))", 
                             action.id, graphName,  tripleCount)) ;
-
-            Graph target ; 
-            if ( graphName.equals(HttpNames.valueDefault) ) 
-                target = action.getActiveDSG().getDefaultGraph() ;
-            else
-            {
-                Node gn = Node.createURI(graphName) ;
-                target = action.getActiveDSG().getGraph(gn) ;
-            }
-            GraphUtil.addInto(target, graphTmp) ;
+            
+            Node gn = graphName.equals(HttpNames.valueDefault)
+                ? Quad.defaultGraphNodeGenerated 
+                : Node.createURI(graphName) ;
+                
+            FusekiLib.addDataInto(graphTmp, action.getActiveDSG(), gn) ;
             tripleCount = graphTmp.size();
             action.commit() ;
         } catch (RuntimeException ex)
@@ -127,6 +124,8 @@ public class SPARQL_Upload extends SPARQ
     static public Graph upload(long id, DatasetRef desc, HttpServletRequest request, HttpServletResponse
response, String destination)
     {
         HttpActionUpload action = new HttpActionUpload(id, desc, request, response, false)
;
+        // We read into a in-memory graph, then (if successful) update the dataset.
+        // This isolates errors.
         Graph graphTmp = GraphFactory.createDefaultGraph() ;
         String graphName = upload(action, graphTmp, destination) ;
         return graphTmp ;
@@ -198,8 +197,6 @@ public class SPARQL_Upload extends SPARQ
                         // Desperate.
                         lang = RDFLanguages.RDFXML ;
 
-                    // We read into a in-memory graph, then (if successful) update the dataset.
-                    // This isolates errors.
                     StreamRDF dest = StreamRDFLib.graph(graphDst) ;
                     LangRIOT parser = RiotReader.createParser(stream, lang, base, dest) ;
                     parser.getProfile().setHandler(errorHandler) ;



Mime
View raw message