jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject [1/2] jena git commit: Make sure to use datasets transactionally (JENA-1486)
Date Tue, 20 Feb 2018 10:43:36 GMT
Repository: jena
Updated Branches:
  refs/heads/master 89e6a8d16 -> 592ebd4d7


Make sure to use datasets transactionally (JENA-1486)

textindexer did not use datasets transactionally which could fail for
dataset implementations that require transactional usage.  And it is
safer to always use transactions where provided anyway.

This closes #360


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

Branch: refs/heads/master
Commit: 2ced4bdd5eda1b84a8e63d47c7e410f2835946e0
Parents: 22933e3
Author: Rob Vesse <rvesse@apache.org>
Authored: Mon Feb 12 14:19:01 2018 +0000
Committer: Rob Vesse <rvesse@apache.org>
Committed: Tue Feb 20 10:43:10 2018 +0000

----------------------------------------------------------------------
 jena-text/src/main/java/jena/textindexer.java | 75 ++++++++++++++--------
 1 file changed, 47 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/2ced4bdd/jena-text/src/main/java/jena/textindexer.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/jena/textindexer.java b/jena-text/src/main/java/jena/textindexer.java
index 870dfec..bf7a98e 100644
--- a/jena-text/src/main/java/jena/textindexer.java
+++ b/jena-text/src/main/java/jena/textindexer.java
@@ -24,6 +24,7 @@ import java.util.Set ;
 
 import org.apache.jena.graph.Node ;
 import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.text.* ;
 import org.apache.jena.sparql.core.Quad ;
 import org.slf4j.Logger ;
@@ -104,39 +105,57 @@ public class textindexer extends CmdARQ {
 
     @Override
     protected void exec() {
-        Set<Node> properties = getIndexedProperties() ;
-
-        // there are various strategies possible here
-        // what is implemented is a first cut simple approach
-        // currently - for each indexed property
-        // list and index triples with that property
-        // that way only process triples that will be indexed
-        // but each entity may be updated several times
-
-        for ( Node property : properties )
-        {
-            Iterator<Quad> quadIter = dataset.find( Node.ANY, Node.ANY, property, Node.ANY
);
-            for (; quadIter.hasNext(); )
+        try {
+            // JENA-1486 Make sure to use transactions if supported
+            // The supportsTransactions() check should be strictly unecessary as we should
always be using a
+            // DatasetGraphText which is transactional but just for future proofing we check
anyway
+            if (dataset.supportsTransactions()) {
+                dataset.begin(ReadWrite.READ);
+            }
+            
+            Set<Node> properties = getIndexedProperties() ;
+    
+            // there are various strategies possible here
+            // what is implemented is a first cut simple approach
+            // currently - for each indexed property
+            // list and index triples with that property
+            // that way only process triples that will be indexed
+            // but each entity may be updated several times
+    
+            for ( Node property : properties )
             {
-                Quad quad = quadIter.next();
-                if ( Quad.isDefaultGraph(quad.getGraph()) ) {
-                    // Need to use urn:x-arq:DefaultGraphNode for text indexing (JENA-1133)
-                    quad = Quad.create(Quad.defaultGraphNodeGenerated,
-                        quad.getSubject(), quad.getPredicate(), quad.getObject());
-                }
-                Entity entity = TextQueryFuncs.entityFromQuad( entityDefinition, quad );
-                if ( entity != null )
+                Iterator<Quad> quadIter = dataset.find( Node.ANY, Node.ANY, property,
Node.ANY );
+                for (; quadIter.hasNext(); )
                 {
-                    textIndex.addEntity( entity );
-                    progressMonitor.progressByOne();
+                    Quad quad = quadIter.next();
+                    if ( Quad.isDefaultGraph(quad.getGraph()) ) {
+                        // Need to use urn:x-arq:DefaultGraphNode for text indexing (JENA-1133)
+                        quad = Quad.create(Quad.defaultGraphNodeGenerated,
+                            quad.getSubject(), quad.getPredicate(), quad.getObject());
+                    }
+                    Entity entity = TextQueryFuncs.entityFromQuad( entityDefinition, quad
);
+                    if ( entity != null )
+                    {
+                        textIndex.addEntity( entity );
+                        progressMonitor.progressByOne();
+                    }
                 }
             }
+            
+            textIndex.commit();
+            textIndex.close();
+            
+            if (dataset.supportsTransactions()) {
+                dataset.commit();
+            }
+            dataset.close();
+            
+            progressMonitor.close() ;
+        } finally {
+            if (dataset.supportsTransactions()) {
+                dataset.end();
+            }
         }
-        
-        textIndex.commit();
-        textIndex.close();
-        dataset.close();
-        progressMonitor.close() ;
     }
 
     private Set<Node> getIndexedProperties() {


Mime
View raw message