You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2022/07/17 21:17:59 UTC

[jena] branch main updated: GH-1442: Check if the database is empty in a read transaction.

This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 9cc99d1128 GH-1442: Check if the database is empty in a read transaction.
     new 15774eab85 Merge pull request #1449 from afs/geo-text
9cc99d1128 is described below

commit 9cc99d1128497aee664a26e2dd7f37458537aa7e
Author: Andy Seaborne <an...@apache.org>
AuthorDate: Sun Jul 17 10:08:45 2022 +0100

    GH-1442: Check if the database is empty in a read transaction.
---
 .../jena/geosparql/assembler/GeoAssembler.java     |  2 +-
 .../files/GeoAssembler/fuseki-geo-text-tdb2.ttl    | 68 +++++++++++++++++++++
 .../files/GeoAssembler/fuseki-text-geo-tdb2.ttl    | 69 ++++++++++++++++++++++
 .../apache/jena/geosparql/TestGeoAssembler.java    | 39 ++++++++++--
 4 files changed, 172 insertions(+), 6 deletions(-)

diff --git a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java
index 5eb53c2921..5e54e6ad95 100644
--- a/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java
+++ b/jena-geosparql/src/main/java/org/apache/jena/geosparql/assembler/GeoAssembler.java
@@ -166,7 +166,7 @@ public class GeoAssembler extends DatasetAssembler {
     }
 
     private static void prepareSpatialExtension(Dataset dataset, String spatialIndex){
-        boolean isEmpty = dataset.calculate(()->dataset.isEmpty());
+        boolean isEmpty = dataset.calculateRead(()->dataset.isEmpty());
         if ( isEmpty && spatialIndex != null ) {
             LOG.warn("Dataset empty. Spatial Index not constructed. Server will require restarting after adding data and any updates to build Spatial Index.");
             return;
diff --git a/jena-integration-tests/src/test/files/GeoAssembler/fuseki-geo-text-tdb2.ttl b/jena-integration-tests/src/test/files/GeoAssembler/fuseki-geo-text-tdb2.ttl
new file mode 100644
index 0000000000..b0659064e8
--- /dev/null
+++ b/jena-integration-tests/src/test/files/GeoAssembler/fuseki-geo-text-tdb2.ttl
@@ -0,0 +1,68 @@
+PREFIX : <https://data.coypu.org/>
+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 tdb1:      <http://jena.hpl.hp.com/2008/tdb#>
+PREFIX tdb2:      <http://jena.apache.org/2016/tdb#>
+PREFIX text:  <http://jena.apache.org/text#>
+PREFIX ja:        <http://jena.hpl.hp.com/2005/11/Assembler#>
+PREFIX geosparql: <http://jena.apache.org/geosparql#>
+PREFIX ex:        <http://www.example.org/resources#>
+
+# Text and Geo service 
+<#serviceTest> rdf:type fuseki:Service;
+    fuseki:name "ds";
+    fuseki:endpoint [ fuseki:operation fuseki:query ; ] ;
+    fuseki:dataset <#testGeoDS> .
+
+# Text DS
+<#testTextDS> rdf:type text:TextDataset ;
+    text:dataset   <#testDS> ;
+    text:index     <#testIndexLucene> ;
+    .
+
+# Text index description
+<#testIndexLucene> rdf:type text:TextIndexLucene ;
+    text:directory "mem" ;
+    text:entityMap <#testEntMap> ;
+    text:storeValues true ; 
+    text:analyzer [ a text:StandardAnalyzer ] ;
+    text:queryParser text:AnalyzingQueryParser ;
+    text:multilingualSupport true ; # optional
+    .
+
+<#testEntMap> rdf:type text:EntityMap ;
+    text:defaultField     "label" ;
+    text:entityField      "uri" ;
+    text:uidField         "uid" ;
+    text:langField        "lang" ;
+    text:graphField       "graph" ;
+    text:map (
+        [ text:field "label" ; 
+          text:predicate rdfs:label ]      
+    ) ;
+    .
+
+<#testGeoDS> rdf:type geosparql:geosparqlDataset ;
+    ## If absent build an in-memory index each time.
+    ## geosparql:spatialIndexFile     "";
+
+    ## Default settings. See documentation for meanings.
+    geosparql:inference            false ;
+    geosparql:queryRewrite         true ;
+    geosparql:indexEnabled         true ;
+    geosparql:applyDefaultGeometry false ;
+
+    # 3 item lists: [Geometry Literal, Geometry Transform, Query Rewrite]
+    geosparql:indexSizes           "-1,-1,-1" ;       # Default - unlimited.
+    geosparql:indexExpires         "5000,5000,5000" ; # Default - time in milliseconds.
+
+    ## Required - data over which GeoSPARQL is applied.
+    geosparql:dataset <#testTextDS> ;
+    .
+
+
+# TDB2 dataset
+<#testDS> rdf:type tdb2:DatasetTDB2 ;
+    tdb2:location "--mem--" ;
+    .
diff --git a/jena-integration-tests/src/test/files/GeoAssembler/fuseki-text-geo-tdb2.ttl b/jena-integration-tests/src/test/files/GeoAssembler/fuseki-text-geo-tdb2.ttl
new file mode 100644
index 0000000000..e07e6e53b2
--- /dev/null
+++ b/jena-integration-tests/src/test/files/GeoAssembler/fuseki-text-geo-tdb2.ttl
@@ -0,0 +1,69 @@
+PREFIX : <https://data.coypu.org/>
+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 tdb1:      <http://jena.hpl.hp.com/2008/tdb#>
+PREFIX tdb2:      <http://jena.apache.org/2016/tdb#>
+PREFIX text:  <http://jena.apache.org/text#>
+PREFIX ja:        <http://jena.hpl.hp.com/2005/11/Assembler#>
+PREFIX geosparql: <http://jena.apache.org/geosparql#>
+PREFIX ex:        <http://www.example.org/resources#>
+
+# Text and Geo service 
+<#serviceTest> rdf:type fuseki:Service;
+    fuseki:name "ds";
+    fuseki:endpoint [ fuseki:operation fuseki:query ; ] ;
+    fuseki:dataset <#testTextDS> .
+
+# Text DS
+<#testTextDS> rdf:type text:TextDataset ;
+    text:dataset   <#testGeoDS> ;
+    text:index     <#testIndexLucene> ;
+    .
+
+# Text index description
+<#testIndexLucene> rdf:type text:TextIndexLucene ;
+    text:directory "mem" ;
+    text:entityMap <#testEntMap> ;
+    text:storeValues true ; 
+    text:analyzer [ a text:StandardAnalyzer ] ;
+    text:queryParser text:AnalyzingQueryParser ;
+    text:multilingualSupport true ; # optional
+    .
+
+<#testEntMap> rdf:type text:EntityMap ;
+    text:defaultField     "label" ;
+    text:entityField      "uri" ;
+    text:uidField         "uid" ;
+    text:langField        "lang" ;
+    text:graphField       "graph" ;
+    text:map (
+        [ text:field "label" ; 
+          text:predicate rdfs:label ]      
+    ) ;
+    .
+
+<#testGeoDS> rdf:type geosparql:geosparqlDataset ;
+    ## If absent build an in-memory index each time.
+    ## geosparql:spatialIndexFile     "target/tdb2/test/spatial.index";
+
+    ## Default settings. See documentation for meanings.
+    geosparql:inference            false ;
+    geosparql:queryRewrite         true ;
+    geosparql:indexEnabled         true ;
+    geosparql:applyDefaultGeometry false ;
+
+    # 3 item lists: [Geometry Literal, Geometry Transform, Query Rewrite]
+    geosparql:indexSizes           "-1,-1,-1" ;       # Default - unlimited.
+    geosparql:indexExpires         "5000,5000,5000" ; # Default - time in milliseconds.
+
+    ## Required - data over which GeoSPARQL is applied.
+    geosparql:dataset <#testDS> ;
+    .
+
+
+# TDB2 dataset
+<#testDS> rdf:type tdb2:DatasetTDB2 ;
+    tdb2:location "target/tdb2/test" ;
+    .
+
diff --git a/jena-integration-tests/src/test/java/org/apache/jena/geosparql/TestGeoAssembler.java b/jena-integration-tests/src/test/java/org/apache/jena/geosparql/TestGeoAssembler.java
index 1ef3ea4d12..21921b026d 100644
--- a/jena-integration-tests/src/test/java/org/apache/jena/geosparql/TestGeoAssembler.java
+++ b/jena-integration-tests/src/test/java/org/apache/jena/geosparql/TestGeoAssembler.java
@@ -20,8 +20,11 @@ package org.apache.jena.geosparql;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeFalse;
 
 import org.apache.jena.atlas.lib.FileOps;
+import org.apache.jena.base.Sys;
 import org.apache.jena.fuseki.main.FusekiServer;
 import org.apache.jena.geosparql.assembler.VocabGeoSPARQL;
 import org.apache.jena.query.Dataset;
@@ -57,7 +60,6 @@ public class TestGeoAssembler {
         ds.executeWrite(()->{
             RDFDataMgr.read(ds, DIR+"geosparql_test.rdf");
         });
-
     }
 
     @Test public void geoAssemblerTest() {
@@ -66,18 +68,29 @@ public class TestGeoAssembler {
     }
 
     @Test public void testBasicFusekiGeoAssembler() {
-        test("geo-config.ttl", "ds1");
+        testBuildDataQuery("geo-config.ttl", "ds1");
     }
 
     @Test public void testExampleFusekiGeoAssembler() {
-        test("geo-config-ex.ttl", "ds2");
+        testBuildDataQuery("geo-config-ex.ttl", "ds2");
     }
 
     @Test public void testMemFusekiGeoAssembler() {
-        test("geo-config-mem.ttl", "ds3");
+        testBuildDataQuery("geo-config-mem.ttl", "ds3");
+    }
+
+    @Test public void testFusekiTextGeoTDB2() {
+        assumeFalse(Sys.isWindows);
+        testBuildPing("fuseki-text-geo-tdb2.ttl", "ds");
+    }
+
+    @Test public void testFusekiGeoTextTDB2() {
+        assumeFalse(Sys.isWindows);
+        testBuildPing("fuseki-geo-text-tdb2.ttl", "ds");
     }
 
-    private void test(String filename, String dbName) {
+    // Test for the configurations with data loaded in the assembler
+    private void testBuildDataQuery(String filename, String dbName) {
         FusekiServer server = FusekiServer.create().port(0)
             .parseConfigFile("file:"+DIR+filename)
             .build();
@@ -103,4 +116,20 @@ public class TestGeoAssembler {
             server.stop();
         }
     }
+
+    // Test for valid configurations.
+    private void testBuildPing(String config, String dbName) {
+        FusekiServer server = FusekiServer.create().port(0)
+                .parseConfigFile("file:"+DIR+config)
+                .build();
+        try {
+            server.start();
+            int port = server.getPort();
+            String URL = "http://localhost:"+port+"/"+dbName;
+            boolean ask = QueryExec.service(URL).query("ASK{}").ask();
+            assertTrue(ask);
+        } finally {
+            server.stop();
+        }
+    }
 }