jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject [2/3] jena git commit: Provide an assembler for WPG dataset
Date Sat, 07 Jan 2017 23:30:04 GMT
Provide an assembler for WPG dataset


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

Branch: refs/heads/ThreadPerGraphDataset
Commit: da6b9103b2f4019a2bf0c5b02e1b0d59e8114796
Parents: f2edbb4
Author: ajs6f <ajs6f@virginia.edu>
Authored: Sat Jan 7 16:42:13 2017 -0500
Committer: ajs6f <ajs6f@virginia.edu>
Committed: Sat Jan 7 16:42:13 2017 -0500

----------------------------------------------------------------------
 .../sparql/core/assembler/AssemblerUtils.java   |  5 +-
 .../core/assembler/DatasetAssemblerVocab.java   |  5 +-
 .../core/assembler/InMemDatasetAssembler.java   | 73 --------------------
 .../TransactionalInMemDatasetAssembler.java     | 66 ++++++++++++++++++
 .../assembler/TxnInMemDatasetAssembler.java     | 41 +++++++++++
 .../WriterPerGraphDatasetAssembler.java         | 41 +++++++++++
 .../assembler/TestInMemDatasetAssembler.java    |  4 +-
 .../core/pergraph/MultithreadingTest.java       |  2 -
 8 files changed, 158 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/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 bb504ab..d124393 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
@@ -58,7 +58,10 @@ public class AssemblerUtils
         initialized = true ;
         // Wire in the extension assemblers (extensions relative to the Jena assembler framework)
         registerDataset(DatasetAssembler.getType(),         new DatasetAssembler()) ;
-        registerDataset(InMemDatasetAssembler.getType(),    new InMemDatasetAssembler())
;
+        TxnInMemDatasetAssembler txnInMemDatasetAssembler = new TxnInMemDatasetAssembler();
+        registerDataset(txnInMemDatasetAssembler.getType(), txnInMemDatasetAssembler);
+        WriterPerGraphDatasetAssembler writerPerGraphDatasetAssembler = new WriterPerGraphDatasetAssembler();
+        registerDataset(writerPerGraphDatasetAssembler.getType(), writerPerGraphDatasetAssembler);
     }
     
     private static Model modelExtras = ModelFactory.createDefaultModel() ;

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/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 f5bbe65..1c234d1 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
@@ -30,8 +30,11 @@ public class DatasetAssemblerVocab
     
     // General dataset
     public static final Resource tDataset            = ResourceFactory.createResource(NS+"RDFDataset")
;
-    // In-memory dataset
+    // Basic txn in-memory dataset
     public static final Resource tDatasetTxnMem      = ResourceFactory.createResource(NS+"DatasetTxnMem")
;
+    // Writer-per-graph txn in-memory dataset
+    public static final Resource tDatasetPGraphWriter = ResourceFactory.createResource(NS+"DatasetMemWriterPerGraph");
+    
     public static final Resource tDatasetNull        = ResourceFactory.createResource(NS+"DatasetNull")
;
     
     public static final Property pDefaultGraph       = ResourceFactory.createProperty(NS,
"defaultGraph") ;

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/InMemDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/InMemDatasetAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/InMemDatasetAssembler.java
deleted file mode 100644
index a79779f..0000000
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/InMemDatasetAssembler.java
+++ /dev/null
@@ -1,73 +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 static org.apache.jena.assembler.JA.data;
-import static org.apache.jena.query.DatasetFactory.createTxnMem;
-import static org.apache.jena.query.ReadWrite.WRITE;
-import static org.apache.jena.riot.RDFDataMgr.read;
-import static org.apache.jena.sparql.core.assembler.AssemblerUtils.setContext;
-import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pGraphName;
-import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pNamedGraph;
-import static org.apache.jena.sparql.util.graph.GraphUtils.getAsStringValue;
-import static org.apache.jena.sparql.util.graph.GraphUtils.multiValueResource;
-
-import org.apache.jena.assembler.Assembler;
-import org.apache.jena.assembler.Mode;
-import org.apache.jena.assembler.assemblers.AssemblerBase;
-import org.apache.jena.query.Dataset;
-import org.apache.jena.rdf.model.Resource;
-
-/**
- * An {@link Assembler} that creates in-memory {@link Dataset}s.
- */
-public class InMemDatasetAssembler extends AssemblerBase implements Assembler {
-
-    public static Resource getType() {
-        return DatasetAssemblerVocab.tDatasetTxnMem ;
-    }
-    
-	@Override
-	public Dataset open(final Assembler assembler, final Resource root, final Mode mode) {
-		checkType(root, DatasetAssemblerVocab.tDatasetTxnMem);
-		final Dataset dataset = createTxnMem();
-		setContext(root, dataset.getContext());
-
-		dataset.begin(WRITE);
-
-		// load data into the default graph
-		if (root.hasProperty(data)) {
-		    multiValueResource(root, data)
-				.forEach(defaultGraphDocument -> read(dataset, defaultGraphDocument.getURI()));
-		}
-
-		// load data into named graphs
-		multiValueResource(root, pNamedGraph).forEach(namedGraphResource -> {
-			final String graphName = getAsStringValue(namedGraphResource, pGraphName);
-			if (namedGraphResource.hasProperty(data)) {
-			    multiValueResource(namedGraphResource, data)
-			        .forEach(namedGraphData -> read(dataset.getNamedModel(graphName), namedGraphData.getURI()));
-			}
-		});
-
-		dataset.commit();
-		dataset.end();
-		return dataset;
-	}
-}

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TransactionalInMemDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TransactionalInMemDatasetAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TransactionalInMemDatasetAssembler.java
new file mode 100644
index 0000000..12fc1fc
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TransactionalInMemDatasetAssembler.java
@@ -0,0 +1,66 @@
+/*
+ * 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 static org.apache.jena.assembler.JA.data;
+import static org.apache.jena.query.ReadWrite.WRITE;
+import static org.apache.jena.riot.RDFDataMgr.read;
+import static org.apache.jena.sparql.core.assembler.AssemblerUtils.setContext;
+import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pGraphName;
+import static org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab.pNamedGraph;
+import static org.apache.jena.sparql.util.graph.GraphUtils.getAsStringValue;
+import static org.apache.jena.sparql.util.graph.GraphUtils.multiValueResource;
+
+import org.apache.jena.assembler.Assembler;
+import org.apache.jena.assembler.Mode;
+import org.apache.jena.assembler.assemblers.AssemblerBase;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.rdf.model.Resource;
+
+/**
+ * An {@link Assembler} that creates transactional in-memory {@link Dataset}s.
+ */
+public abstract class TransactionalInMemDatasetAssembler extends AssemblerBase {
+
+    public abstract Resource getType();
+
+    public abstract Dataset createDataset();
+
+    @Override
+    public Dataset open(final Assembler assembler, final Resource root, final Mode mode)
{
+        checkType(root, getType());
+        final Dataset dataset = createDataset();
+        setContext(root, dataset.getContext());
+
+        dataset.begin(WRITE);
+        try {
+            // load data into the default graph
+            if (root.hasProperty(data))
+                multiValueResource(root, data)
+                    .forEach(defaultGraphDocument -> read(dataset, defaultGraphDocument.getURI()));
+
+            // load data into named graphs
+            multiValueResource(root, pNamedGraph).forEach(namedGraphResource -> {
+                final String graphName = getAsStringValue(namedGraphResource, pGraphName);
+                if (namedGraphResource.hasProperty(data))
+                    multiValueResource(namedGraphResource, data)
+                            .forEach(namedGraphData -> read(dataset.getNamedModel(graphName),
namedGraphData.getURI()));
+            });
+            dataset.commit();
+        } finally {
+            dataset.end();
+        }
+        return dataset;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TxnInMemDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TxnInMemDatasetAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TxnInMemDatasetAssembler.java
new file mode 100644
index 0000000..faa5926
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/TxnInMemDatasetAssembler.java
@@ -0,0 +1,41 @@
+/*
+ * 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 static org.apache.jena.query.DatasetFactory.createTxnMem;
+
+import org.apache.jena.assembler.Assembler;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.rdf.model.Resource;
+
+/**
+ * An {@link Assembler} for basic transactional in-memory {@link Dataset}s.
+ */
+public class TxnInMemDatasetAssembler extends TransactionalInMemDatasetAssembler {
+
+    @Override
+    public Resource getType() {
+        return DatasetAssemblerVocab.tDatasetTxnMem ;
+    }
+    
+    @Override
+    public Dataset createDataset() {
+        return createTxnMem();
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/WriterPerGraphDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/WriterPerGraphDatasetAssembler.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/WriterPerGraphDatasetAssembler.java
new file mode 100644
index 0000000..2ebefd9
--- /dev/null
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/assembler/WriterPerGraphDatasetAssembler.java
@@ -0,0 +1,41 @@
+/*
+ * 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.query.Dataset;
+import org.apache.jena.query.DatasetFactory;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.sparql.core.DatasetGraphPerGraphLocking;
+
+/**
+ * An {@link Assembler} that creates writer-per-graph in-memory {@link Dataset}s.
+ */
+public class WriterPerGraphDatasetAssembler extends TransactionalInMemDatasetAssembler {
+
+    @Override
+    public Resource getType() {
+        return DatasetAssemblerVocab.tDatasetPGraphWriter ;
+    }
+    
+    @Override
+    public Dataset createDataset() {
+        return DatasetFactory.wrap(new DatasetGraphPerGraphLocking()) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/test/java/org/apache/jena/sparql/core/assembler/TestInMemDatasetAssembler.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/core/assembler/TestInMemDatasetAssembler.java
b/jena-arq/src/test/java/org/apache/jena/sparql/core/assembler/TestInMemDatasetAssembler.java
index 29644b6..ad4114c 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/core/assembler/TestInMemDatasetAssembler.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/core/assembler/TestInMemDatasetAssembler.java
@@ -50,7 +50,7 @@ import org.junit.Assert;
 import org.junit.Test;
 
 /**
- * Tests for {@link InMemDatasetAssembler}
+ * Tests for {@link TxnInMemDatasetAssembler}
  *
  */
 public class TestInMemDatasetAssembler extends Assert {
@@ -60,7 +60,7 @@ public class TestInMemDatasetAssembler extends Assert {
 	    model.setNsPrefix("ja", JA.getURI()) ;
 //	    System.out.println("-------------");
 //	    RDFDataMgr.write(System.out, model, Lang.TTL) ;
-	    final InMemDatasetAssembler testAssembler = new InMemDatasetAssembler();
+	    final TxnInMemDatasetAssembler testAssembler = new TxnInMemDatasetAssembler();
 		return testAssembler.open(testAssembler, example, DEFAULT);
 	}
 	

http://git-wip-us.apache.org/repos/asf/jena/blob/da6b9103/jena-arq/src/test/java/org/apache/jena/sparql/core/pergraph/MultithreadingTest.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/core/pergraph/MultithreadingTest.java
b/jena-arq/src/test/java/org/apache/jena/sparql/core/pergraph/MultithreadingTest.java
index d2b8552..99eb8f6 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/core/pergraph/MultithreadingTest.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/core/pergraph/MultithreadingTest.java
@@ -19,7 +19,6 @@ import static org.apache.jena.graph.NodeFactory.createLiteral;
 import static org.apache.jena.graph.NodeFactory.createURI;
 import static org.apache.jena.query.ReadWrite.READ;
 import static org.apache.jena.query.ReadWrite.WRITE;
-import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -27,7 +26,6 @@ import org.apache.jena.atlas.junit.BaseTest;
 import org.apache.jena.graph.Node;
 import org.apache.jena.sparql.core.DatasetGraphPerGraphLocking;
 import org.junit.Test;
-import org.slf4j.Logger;
 
 public class MultithreadingTest extends BaseTest {
 


Mime
View raw message