You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by ga...@apache.org on 2020/10/03 12:36:12 UTC
[jena] branch master updated: Fixed TDB transaction error when
checking for empty dataset.
This is an automated email from the ASF dual-hosted git repository.
galbiston pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/master by this push:
new 198e4b3 Fixed TDB transaction error when checking for empty dataset.
new df7ec09 Merge pull request #807 from galbiston/empty_dataset_check
198e4b3 is described below
commit 198e4b33e87d607a946d717e28c7f26895df6489
Author: Greg Albiston <46...@users.noreply.github.com>
AuthorDate: Sat Oct 3 13:29:45 2020 +0100
Fixed TDB transaction error when checking for empty dataset.
---
.../jena/fuseki/geosparql/DatasetOperations.java | 50 +++++---
.../org/apache/jena/fuseki/geosparql/TDBTest.java | 128 +++++++++++++++++++++
2 files changed, 161 insertions(+), 17 deletions(-)
diff --git a/jena-fuseki2/jena-fuseki-geosparql/src/main/java/org/apache/jena/fuseki/geosparql/DatasetOperations.java b/jena-fuseki2/jena-fuseki-geosparql/src/main/java/org/apache/jena/fuseki/geosparql/DatasetOperations.java
index 4b55e9a..87cec24 100644
--- a/jena-fuseki2/jena-fuseki-geosparql/src/main/java/org/apache/jena/fuseki/geosparql/DatasetOperations.java
+++ b/jena-fuseki2/jena-fuseki-geosparql/src/main/java/org/apache/jena/fuseki/geosparql/DatasetOperations.java
@@ -92,19 +92,7 @@ public class DatasetOperations {
}
//Setup Spatial Extension
- if (!dataset.isEmpty()) {
- if (argsConfig.getSpatialIndexFile() != null) {
- File spatialIndexFile = argsConfig.getSpatialIndexFile();
- GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
- } else if (argsConfig.isTDBFileSetup()) {
- File spatialIndexFile = new File(argsConfig.getTdbFile(), SPATIAL_INDEX_FILE);
- GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
- } else {
- GeoSPARQLConfig.setupSpatialIndex(dataset);
- }
- } else {
- LOGGER.warn("Datset empty. Spatial Index not constructed. Server will require restarting after adding data and any updates to build Spatial Index.");
- }
+ prepareSpatialExtension(dataset, argsConfig);
return dataset;
}
@@ -160,10 +148,15 @@ public class DatasetOperations {
}
//Load file and add to target model.
- Model model = RDFDataMgr.loadModel(rdfFile.getAbsolutePath(), rdfFormat.getLang());
- targetModel.add(model);
- dataset.commit();
- LOGGER.info("Reading RDF - Completed - File: {}, Graph Name: {}, RDF Format: {}", rdfFile, graphName, rdfFormat);
+ if (rdfFile.exists()) {
+ Model model = RDFDataMgr.loadModel(rdfFile.getAbsolutePath(), rdfFormat.getLang());
+ targetModel.add(model);
+ dataset.commit();
+ LOGGER.info("Reading RDF - Completed - File: {}, Graph Name: {}, RDF Format: {}", rdfFile, graphName, rdfFormat);
+ } else {
+ dataset.abort();
+ LOGGER.info("Reading RDF - Not Completed - File: {} does not exist", rdfFile, graphName, rdfFormat);
+ }
}
} catch (Exception ex) {
dataset.abort();
@@ -214,4 +207,27 @@ public class DatasetOperations {
}
+ private static void prepareSpatialExtension(Dataset dataset, ArgsConfig argsConfig) throws SpatialIndexException {
+
+ // Transaction now required to check if dataset is empty.
+ dataset.begin(ReadWrite.READ);
+ boolean isEmpty = dataset.isEmpty();
+ dataset.end();
+
+ // Only build spatial index if data provided.
+ if (!isEmpty) {
+ if (argsConfig.getSpatialIndexFile() != null) {
+ File spatialIndexFile = argsConfig.getSpatialIndexFile();
+ GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
+ } else if (argsConfig.isTDBFileSetup()) {
+ File spatialIndexFile = new File(argsConfig.getTdbFile(), SPATIAL_INDEX_FILE);
+ GeoSPARQLConfig.setupSpatialIndex(dataset, spatialIndexFile);
+ } else {
+ GeoSPARQLConfig.setupSpatialIndex(dataset);
+ }
+ } else {
+ LOGGER.warn("Datset empty. Spatial Index not constructed. Server will require restarting after adding data and any updates to build Spatial Index.");
+ }
+ }
+
}
diff --git a/jena-fuseki2/jena-fuseki-geosparql/src/test/java/org/apache/jena/fuseki/geosparql/TDBTest.java b/jena-fuseki2/jena-fuseki-geosparql/src/test/java/org/apache/jena/fuseki/geosparql/TDBTest.java
new file mode 100644
index 0000000..da79ccb
--- /dev/null
+++ b/jena-fuseki2/jena-fuseki-geosparql/src/test/java/org/apache/jena/fuseki/geosparql/TDBTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.fuseki.geosparql;
+
+import com.beust.jcommander.JCommander;
+import com.github.jsonldjava.shaded.com.google.common.io.Files;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.jena.fuseki.geosparql.cli.ArgsConfig;
+import org.apache.jena.geosparql.spatial.SpatialIndexException;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.QueryExecution;
+import org.apache.jena.query.QueryExecutionFactory;
+import org.apache.jena.query.QuerySolution;
+import org.apache.jena.query.ResultSet;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.ResourceFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ *
+ *
+ */
+public class TDBTest {
+
+ private static GeosparqlServer SERVER;
+
+ public TDBTest() {
+ }
+
+ @BeforeClass
+ public static void setUpClass() throws DatasetException, SpatialIndexException {
+
+ File tempTDBDir = Files.createTempDir();
+ String[] args = {"-rf", "geosparql_test.rdf>xml", "-i", "-t", tempTDBDir.getAbsolutePath()};
+
+ ArgsConfig argsConfig = new ArgsConfig();
+ JCommander.newBuilder()
+ .addObject(argsConfig)
+ .build()
+ .parse(args);
+
+ //Setup dataset
+ Dataset dataset = DatasetOperations.setup(argsConfig);
+
+ //Configure server
+ SERVER = new GeosparqlServer(argsConfig.getPort(), argsConfig.getDatsetName(), argsConfig.isLoopbackOnly(), dataset, argsConfig.isUpdateAllowed());
+ SERVER.start();
+
+ System.out.println("Server: " + SERVER.getLocalServiceURL());
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ SERVER.shutdown();
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /**
+ * Test of main method, of class Main.
+ */
+ @Test
+ public void testMain() {
+ System.out.println("main");
+
+ String query = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n"
+ + "\n"
+ + "SELECT ?obj\n"
+ + "WHERE{\n"
+ + " <http://example.org/Geometry#PolygonH> geo:sfContains ?obj .\n"
+ + "}ORDER by ?obj";
+ List<Resource> result = new ArrayList<>();
+ try (QueryExecution qe = QueryExecutionFactory.sparqlService(SERVER.getLocalServiceURL(), query)) {
+ ResultSet rs = qe.execSelect();
+
+ while (rs.hasNext()) {
+ QuerySolution qs = rs.nextSolution();
+ Resource obj = qs.getResource("obj");
+ result.add(obj);
+ }
+
+ //ResultSetFormatter.outputAsTSV(rs);
+ }
+
+ List<Resource> expResult = new ArrayList<>();
+ expResult.add(ResourceFactory.createResource("http://example.org/Feature#A"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Feature#D"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Feature#H"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Feature#K"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Geometry#LineStringD"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PointA"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonH"));
+ expResult.add(ResourceFactory.createResource("http://example.org/Geometry#PolygonK"));
+
+ //System.out.println("Exp: " + expResult);
+ //System.out.println("Res: " + result);
+ assertEquals(expResult, result);
+ }
+
+}