jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject [24/44] jena git commit: Cleanup in TIM
Date Sat, 06 Jan 2018 15:17:48 GMT
Cleanup in TIM


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

Branch: refs/heads/master
Commit: 0653c2c567e35a471a20247bae75633e347627ce
Parents: 08a559b
Author: ajs6f <ajs6f@apache.org>
Authored: Fri Dec 29 10:53:27 2017 -0500
Committer: ajs6f <ajs6f@apache.org>
Committed: Fri Jan 5 09:32:55 2018 -0500

----------------------------------------------------------------------
 .../jena/query/util/DatasetCollector.java       |  7 ++-
 .../sparql/core/mem/DatasetGraphInMemory.java   | 47 ++++++--------------
 2 files changed, 19 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/0653c2c5/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java
index 492e06f..b70026a 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/util/DatasetCollector.java
@@ -35,7 +35,7 @@ public abstract class DatasetCollector implements UnorderedIdentityFinishCollect
 
     @Override
     public Supplier<Dataset> supplier() {
-        return DatasetFactory::createGeneral;
+        return DatasetFactory::createTxnMem;
     }
 
     public ConcurrentDatasetCollector concurrent() {
@@ -77,7 +77,10 @@ public abstract class DatasetCollector implements UnorderedIdentityFinishCollect
             return (d1, d2) -> {
                 d1.getDefaultModel().add(d2.getDefaultModel());
                 d2.listNames().forEachRemaining(
-                        name -> d1.replaceNamedModel(name, d1.getNamedModel(name).union(d2.getNamedModel(name))));
+                        name -> {
+                            Model union = d1.getNamedModel(name).union(d2.getNamedModel(name));
+                            d1.replaceNamedModel(name, union);
+                        });
             };
         }
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/0653c2c5/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
index 44dd8db..0a48161 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/core/mem/DatasetGraphInMemory.java
@@ -20,10 +20,11 @@ package org.apache.jena.sparql.core.mem;
 
 import static java.lang.ThreadLocal.withInitial;
 import static org.apache.jena.graph.Node.ANY;
-import static org.apache.jena.query.ReadWrite.READ;
 import static org.apache.jena.query.ReadWrite.WRITE;
 import static org.apache.jena.sparql.core.Quad.isUnionGraph;
 import static org.apache.jena.sparql.util.graph.GraphUtils.triples2quadsDftGraph ;
+import static org.apache.jena.system.Txn.calculateRead;
+import static org.apache.jena.system.Txn.executeWrite;
 import static org.slf4j.LoggerFactory.getLogger;
 
 import java.util.Iterator;
@@ -33,9 +34,7 @@ import java.util.function.Consumer;
 import java.util.function.Supplier;
 
 import org.apache.jena.atlas.lib.InternalErrorException ;
-import org.apache.jena.graph.Graph;
-import org.apache.jena.graph.Node;
-import org.apache.jena.graph.Triple;
+import org.apache.jena.graph.*;
 import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
 import org.apache.jena.shared.Lock;
@@ -315,15 +314,7 @@ public class DatasetGraphInMemory extends DatasetGraphTriplesQuads implements
Tr
     }
     
     private <T> Iterator<T> access(final Supplier<Iterator<T>> source)
{
-        if (!isInTransaction()) {
-            begin(READ);
-            try {
-                return source.get();
-            } finally {
-                end();
-            }
-        }
-        return source.get();
+        return isInTransaction() ? source.get() : calculateRead(this, source::get);
     }
 
     @Override
@@ -390,33 +381,23 @@ public class DatasetGraphInMemory extends DatasetGraphTriplesQuads implements
Tr
      * @param payload
      */
     private <T> void mutate(final Consumer<T> mutator, final T payload) {
-        if (!isInTransaction()) {
-            begin(WRITE);
-            try {
-                mutator.accept(payload);
-                commit();
-            } finally {
-                end();
-            }
-            return ;
-        }
-        if ( !transactionMode().equals(WRITE) ) {
-            TxnType mode = transactionType.get();
-            switch(mode) {
-                case WRITE :
+        if (isInTransaction()) {
+            if (!transactionMode().equals(WRITE)) {
+                TxnType mode = transactionType.get();
+                switch (mode) {
+                case WRITE:
                     break;
-                case READ :
+                case READ:
                     throw new JenaTransactionException("Tried to write inside a READ transaction!");
-                case READ_COMMITTED_PROMOTE :
-                case READ_PROMOTE :
-                {
+                case READ_COMMITTED_PROMOTE:
+                case READ_PROMOTE:
                     boolean readCommitted = (mode == TxnType.READ_COMMITTED_PROMOTE);
                     _promote(readCommitted);
                     break;
                 }
             }
-        }
-        mutator.accept(payload);
+            mutator.accept(payload);
+        } else executeWrite(this, () -> mutator.accept(payload));
     }
 
     /**


Mime
View raw message