jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [06/12] jena git commit: Add assemblers for the lesser cases of Zero and Sink datasets.
Date Tue, 06 Mar 2018 16:29:56 GMT
Add assemblers for the lesser cases of Zero and Sink datasets.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/4744cfc8
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/4744cfc8
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/4744cfc8

Branch: refs/heads/master
Commit: 4744cfc82cc355b67152d73192b53ebb12942205
Parents: 41e2eb1
Author: Andy Seaborne <andy@apache.org>
Authored: Sun Mar 4 15:40:11 2018 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Sun Mar 4 15:40:23 2018 +0000

----------------------------------------------------------------------
 .../jena/sparql/core/TxnDataset2Graph.java      | 17 ++--
 .../sparql/core/assembler/AssemblerUtils.java   | 12 ++-
 .../core/assembler/DatasetAssemblerVocab.java   |  5 +-
 .../assembler/DatasetGraphOneAssembler.java     | 82 --------------------
 .../core/assembler/DatasetNullAssembler.java    | 59 ++++++++++++++
 .../core/assembler/DatasetOneAssembler.java     | 82 ++++++++++++++++++++
 .../jena/sparql/resultset/TestResultSet.java    |  9 ++-
 7 files changed, 168 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/TxnDataset2Graph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/TxnDataset2Graph.java b/jena-arq/src/main/java/org/apache/jena/sparql/core/TxnDataset2Graph.java
index d03cc6e..027d1ed 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/TxnDataset2Graph.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/TxnDataset2Graph.java
@@ -55,13 +55,16 @@ import org.apache.jena.sparql.JenaTransactionException;
  * @See {@link DatasetGraphOne}
  */
 public class TxnDataset2Graph extends TransactionalLock {
-    /** Control whether to pass down transactions from the dataset to the graph in the dataset.
-     *  This should be set to "true".
-     *  This is temporary flag during the transition because the change at Jena 3.7.0
-     *  needs to be proven in real deployments as well as testing. 
-     *  "false" restores the Jena 3.6.0 and before behaviour (transactions not passed down).
-     *  See JENA-1492.
-     *  @deprecated This flag will be removed.  
+    /**
+     * Control whether to pass down transactions from the dataset to the graph in the
+     * dataset. This should be set to "true"; setting it "false" causes the onld,
+     * no-transaction passing behaviour.
+     * <p>
+     * This is temporary flag during the transition because the change at Jena 3.7.0 needs
+     * to be proven in real deployments as well as testing. "false" restores the Jena
+     * 3.6.0 and before behaviour (transactions not passed down). See JENA-1492.
+     * 
+     * @deprecated This flag will be removed.
      */
     @Deprecated
     public static boolean TXN_DSG_GRAPH = true;

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
index d80d02c..a9aa7bb 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/AssemblerUtils.java
@@ -37,6 +37,7 @@ import org.apache.jena.sparql.util.TypeNotUniqueException ;
 import org.apache.jena.sparql.util.graph.GraphUtils ;
 import org.apache.jena.system.JenaSystem ;
 import org.apache.jena.vocabulary.RDFS ;
+import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.*;
 
 public class AssemblerUtils
 {
@@ -56,9 +57,12 @@ public class AssemblerUtils
         if ( initialized )
             return ;
         initialized = true ;
-        registerDataset(DatasetAssemblerVocab.tDataset,         new DatasetAssembler()) ;
-        registerDataset(DatasetAssemblerVocab.tMemoryDataset,   new InMemDatasetAssembler())
;
-        registerDataset(DatasetAssemblerVocab.tDatasetTxnMem,   new InMemDatasetAssembler())
;
+        registerDataset(tDataset,         new DatasetAssembler()) ;
+        registerDataset(tDatasetOne,      new DatasetOneAssembler()) ;
+        registerDataset(tDatasetZero,     new DatasetNullAssembler(tDatasetZero)) ;
+        registerDataset(tDatasetSink,     new DatasetNullAssembler(tDatasetSink)) ;
+        registerDataset(tMemoryDataset,   new InMemDatasetAssembler()) ;
+        registerDataset(tDatasetTxnMem,   new InMemDatasetAssembler()) ;
     }
     
     private static Model modelExtras = ModelFactory.createDefaultModel() ;
@@ -118,7 +122,7 @@ public class AssemblerUtils
                 return null ;
             
         } catch (TypeNotUniqueException ex)
-        { throw new ARQException("Multiple types for: "+DatasetAssemblerVocab.tDataset) ;
}
+        { throw new ARQException("Multiple types for: "+tDataset) ; }
         return Assembler.general.open(root) ;
     }
     

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetAssemblerVocab.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetAssemblerVocab.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetAssemblerVocab.java
index 5d26abe..d55d7d1 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetAssemblerVocab.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetAssemblerVocab.java
@@ -35,8 +35,11 @@ public class DatasetAssemblerVocab
 
     // In-memory dataset
     public static final Resource tDatasetTxnMem      = ResourceFactory.createResource(NS+"DatasetTxnMem")
;
+    
+    // Specialised datasets
     public static final Resource tMemoryDataset      = ResourceFactory.createResource(NS+"MemoryDataset")
;
-    public static final Resource tDatasetNull        = ResourceFactory.createResource(NS+"DatasetNull")
;
+    public static final Resource tDatasetZero        = ResourceFactory.createResource(NS+"RDFDatasetZero")
;
+    public static final Resource tDatasetSink        = ResourceFactory.createResource(NS+"RDFDatasetSink")
;
     
     public static final Property pDefaultGraph       = ResourceFactory.createProperty(NS,
"defaultGraph") ;
     public static final Property pNamedGraph         = ResourceFactory.createProperty(NS,
"namedGraph") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetGraphOneAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetGraphOneAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetGraphOneAssembler.java
deleted file mode 100644
index ed33ebf..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetGraphOneAssembler.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.jena.sparql.core.assembler;
-
-import java.util.List;
-
-import org.apache.jena.assembler.Assembler;
-import org.apache.jena.assembler.Mode;
-import org.apache.jena.assembler.assemblers.AssemblerBase;
-import org.apache.jena.assembler.exceptions.AssemblerException;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.query.DatasetFactory;
-import org.apache.jena.rdf.model.Model;
-import org.apache.jena.rdf.model.RDFNode;
-import org.apache.jena.rdf.model.Resource;
-import org.apache.jena.sparql.graph.GraphFactory;
-import org.apache.jena.sparql.util.graph.GraphUtils;
-
-/**
- * An assembler that creates a dataset around a single graph. The dataset created is
- * fixed; graphs can not be added or removed. The wrapped graph is the default graph of
- * the dataset.
- * <p>
- * General datasets and SPARQL Update can create graphs by inserting a quad.
- * The dataset returned by this assembler does not support that.
- * 
- * @see DatasetAssembler {@code DatasetAssembler}, for a general dataset.
- * @see InMemDatasetAssembler {@code InMemDatasetAssembler}, for a fully transactional, in-memory
dataset.
- */
-public class DatasetGraphOneAssembler extends AssemblerBase {
-    public static Resource getType() {
-        return DatasetAssemblerVocab.tDatasetOne;
-    }
-
-    @Override
-    public Object open(Assembler a, Resource root, Mode mode) {
-        Dataset ds = createDataset(a, root, mode);
-        return ds;
-    }
-
-    public Dataset createDataset(Assembler a, Resource root, Mode mode) {
-        // Can use ja:graph or ja:defaultGraph but not both.
-        Resource dftGraphDesc1 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph);
-        Resource dftGraphDesc2 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph);
-        
-        if ( dftGraphDesc1 != null && dftGraphDesc2 != null )
-            throw new AssemblerException(root, "Found both ja:graph and ja:defaultGraph");

-        
-        Resource graphDesc = ( dftGraphDesc1 != null) ? dftGraphDesc1 : dftGraphDesc2 ;
-        Model model;
-        if ( graphDesc != null )
-            model = a.openModel(graphDesc);
-        else
-            // Assembler description did not define one.
-            model = GraphFactory.makeDefaultModel();
-        Dataset ds = DatasetFactory.wrap(model);
-        
-        List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph);
-        if ( ! nodes.isEmpty() ) {
-            String x = DatasetAssemblerVocab.tDatasetOne.getLocalName();
-            throw new AssemblerException(root, "A "+x+" dataset can only hold a default graph,
and no named graphs");
-        }
-        AssemblerUtils.setContext(root, ds.getContext());
-        return ds;
-    }
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetNullAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetNullAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetNullAssembler.java
new file mode 100644
index 0000000..f82d869
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetNullAssembler.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.core.assembler;
+
+import org.apache.jena.assembler.Assembler;
+import org.apache.jena.assembler.Mode;
+import org.apache.jena.assembler.assemblers.AssemblerBase;
+import org.apache.jena.atlas.lib.InternalErrorException;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphSink;
+import org.apache.jena.sparql.core.DatasetGraphZero;
+
+/**
+ * An assembler that creates datasets that do nothing, either a sink or a always empty one.
+
+ * @see DatasetGraphSink
+ * @see DatasetGraphZero
+ */
+
+public class DatasetNullAssembler extends AssemblerBase {
+    private final Resource tDataset;
+
+    public DatasetNullAssembler(Resource tDataset) {
+        this.tDataset = tDataset;
+    }
+
+    @Override
+    public Object open(Assembler a, Resource root, Mode mode) {
+        DatasetGraph dsg;
+        if ( DatasetAssemblerVocab.tDatasetSink.equals(tDataset) )
+            dsg = new DatasetGraphSink();
+        else if ( DatasetAssemblerVocab.tDatasetZero.equals(tDataset) )
+            dsg = new DatasetGraphZero();
+        else
+            throw new InternalErrorException();
+        Dataset ds = DatasetFactory.wrap(dsg);
+        AssemblerUtils.setContext(root, ds.getContext());
+        return ds;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetOneAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetOneAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetOneAssembler.java
new file mode 100644
index 0000000..70002d5
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/DatasetOneAssembler.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.sparql.core.assembler;
+
+import java.util.List;
+
+import org.apache.jena.assembler.Assembler;
+import org.apache.jena.assembler.Mode;
+import org.apache.jena.assembler.assemblers.AssemblerBase;
+import org.apache.jena.assembler.exceptions.AssemblerException;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.sparql.graph.GraphFactory;
+import org.apache.jena.sparql.util.graph.GraphUtils;
+
+/**
+ * An assembler that creates a dataset around a single graph. The dataset created is
+ * fixed; graphs can not be added or removed. The wrapped graph is the default graph of
+ * the dataset.
+ * <p>
+ * General datasets and SPARQL Update can create graphs by inserting a quad.
+ * The dataset returned by this assembler does not support that.
+ * 
+ * @see DatasetAssembler {@code DatasetAssembler}, for a general dataset.
+ * @see InMemDatasetAssembler {@code InMemDatasetAssembler}, for a fully transactional, in-memory
dataset.
+ */
+public class DatasetOneAssembler extends AssemblerBase {
+    public static Resource getType() {
+        return DatasetAssemblerVocab.tDatasetOne;
+    }
+
+    @Override
+    public Object open(Assembler a, Resource root, Mode mode) {
+        Dataset ds = createDataset(a, root, mode);
+        return ds;
+    }
+
+    public Dataset createDataset(Assembler a, Resource root, Mode mode) {
+        // Can use ja:graph or ja:defaultGraph but not both.
+        Resource dftGraphDesc1 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pDefaultGraph);
+        Resource dftGraphDesc2 = GraphUtils.getResourceValue(root, DatasetAssemblerVocab.pGraph);
+        
+        if ( dftGraphDesc1 != null && dftGraphDesc2 != null )
+            throw new AssemblerException(root, "Found both ja:graph and ja:defaultGraph");

+        
+        Resource graphDesc = ( dftGraphDesc1 != null) ? dftGraphDesc1 : dftGraphDesc2 ;
+        Model model;
+        if ( graphDesc != null )
+            model = a.openModel(graphDesc);
+        else
+            // Assembler description did not define one.
+            model = GraphFactory.makeDefaultModel();
+        Dataset ds = DatasetFactory.wrap(model);
+        
+        List<RDFNode> nodes = GraphUtils.multiValue(root, DatasetAssemblerVocab.pNamedGraph);
+        if ( ! nodes.isEmpty() ) {
+            String x = DatasetAssemblerVocab.tDatasetOne.getLocalName();
+            throw new AssemblerException(root, "A "+x+" dataset can only hold a default graph,
and no named graphs");
+        }
+        AssemblerUtils.setContext(root, ds.getContext());
+        return ds;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/4744cfc8/jena-arq/src/test/java/org/apache/jena/sparql/resultset/TestResultSet.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/resultset/TestResultSet.java b/jena-arq/src/test/java/org/apache/jena/sparql/resultset/TestResultSet.java
index cca2235..11c15c3 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/resultset/TestResultSet.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/resultset/TestResultSet.java
@@ -166,28 +166,29 @@ public class TestResultSet extends BaseTest
     }
     
     // Into some format.
+    private static String DIR = "testing/ResultSet/";
     
     @Test public void test_RS_7()
     {
-        ResultSet rs = ResultSetFactory.load("testing/ResultSet/output.srx") ;
+        ResultSet rs = ResultSetFactory.load(DIR+"output.srx") ;
         test_RS_fmt(rs, ResultsFormat.FMT_RS_XML, true) ;
     }
     
     @Test public void test_RS_8()
     {
-        ResultSet rs = ResultSetFactory.load("testing/ResultSet/output.srx") ;
+        ResultSet rs = ResultSetFactory.load(DIR+"output.srx") ;
         test_RS_fmt(rs, ResultsFormat.FMT_RS_JSON, true) ;
     }
     
     @Test public void test_RS_9()
     {
-        ResultSet rs = ResultSetFactory.load("testing/ResultSet/output.srx") ;
+        ResultSet rs = ResultSetFactory.load(DIR+"output.srx") ;
         test_RS_fmt(rs, ResultsFormat.FMT_RDF_XML, false) ;
     }
     
     @Test public void test_RS_10()
     {
-        ResultSet rs = ResultSetFactory.load("testing/ResultSet/output.srx") ;
+        ResultSet rs = ResultSetFactory.load(DIR+"output.srx") ;
         for ( ; rs.hasNext(); rs.next()) { }
         // We should be able to call hasNext() as many times as we want!
         assertFalse(rs.hasNext());


Mime
View raw message