jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [09/11] jena git commit: Use GraphTxnTDB for API and SPARQL.
Date Sat, 19 May 2018 19:27:18 GMT
Use GraphTxnTDB for API and SPARQL.

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

Branch: refs/heads/master
Commit: 48ab7cbc69a03243ad659ff7638780f6e1094b6d
Parents: 2b62076
Author: Andy Seaborne <andy@apache.org>
Authored: Sat May 19 20:06:53 2018 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Sat May 19 20:06:53 2018 +0100

----------------------------------------------------------------------
 .../apache/jena/tdb/store/GraphNonTxnTDB.java   | 17 +++++++----
 .../org/apache/jena/tdb/store/GraphTDB.java     | 30 +++++++++++++++++++-
 .../org/apache/jena/tdb/store/GraphTxnTDB.java  | 12 ++++++--
 .../transaction/DatasetGraphTransaction.java    | 15 +++-------
 4 files changed, 54 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/48ab7cbc/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java
index 8fa3312..07ecdc4 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphNonTxnTDB.java
@@ -25,10 +25,12 @@ import org.apache.jena.graph.Node;
 import org.apache.jena.graph.TransactionHandler;
 import org.apache.jena.graph.impl.TransactionHandlerBase;
 import org.apache.jena.tdb.TDB;
+import org.apache.jena.tdb.transaction.DatasetGraphTransaction;
 
 /**
- * Non-transactional version of {@link GraphTDB}. Handed out by DatasetGraphTDB when used
- * directly.
+ * Non-transactional version of {@link GraphTDB}.
+ * Handed out by DatasetGraphTDB when used directly (e.g. by the loader)
+ * but not for API or SPARQL usage. 
  * 
  * @see GraphTDB
  * @see GraphTxnTDB
@@ -52,19 +54,24 @@ public class GraphNonTxnTDB extends GraphTDB implements Closeable, Sync
{
     }
     
     @Override
+    public DatasetGraphTransaction getDatasetGraphTransaction() {
+        return null;
+    }
+    
+    @Override
     public TransactionHandler getTransactionHandler() {
-        return new TransactionHandlerTDB(this);
+        return new TransactionHandlerTDBNonTXn(this);
     }
     
     // Transaction handler for non-transactional use.
     // Does not support transactions, but syncs on commit which is the best it
     // can do without being transactional, which is striongly preferrerd.
     // For backwards compatibility only.
-    private static class TransactionHandlerTDB extends TransactionHandlerBase //implements
TransactionHandler 
+    private static class TransactionHandlerTDBNonTXn extends TransactionHandlerBase //implements
TransactionHandler 
     {
         private final Graph graph;
 
-        public TransactionHandlerTDB(GraphTDB graph) {
+        public TransactionHandlerTDBNonTXn(GraphTDB graph) {
             this.graph = graph ;
         }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/48ab7cbc/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
index c62b57d..bf43b1c 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTDB.java
@@ -30,13 +30,16 @@ import org.apache.jena.graph.GraphEvents ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.graph.Triple ;
 import org.apache.jena.riot.other.GLib ;
+import org.apache.jena.riot.system.RiotLib;
 import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.sparql.core.DatasetGraph ;
 import org.apache.jena.sparql.core.DatasetPrefixStorage ;
 import org.apache.jena.sparql.core.GraphView ;
 import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.system.Txn;
 import org.apache.jena.tdb.TDBException ;
 import org.apache.jena.tdb.store.nodetupletable.NodeTupleTable ;
+import org.apache.jena.tdb.transaction.DatasetGraphTransaction;
 import org.apache.jena.util.iterator.ExtendedIterator ;
 import org.apache.jena.util.iterator.WrappedIterator ;
 
@@ -49,15 +52,27 @@ public abstract class GraphTDB extends GraphView implements Closeable,
Sync {
         super(dataset, graphName) ;
     }
 
+    private String graphNameStr() {
+        if ( getGraphName() == null ) return DatasetPrefixesTDB.unnamedGraphURI;
+        if ( getGraphName().isURI() ) return getGraphName().getURI();
+        if ( getGraphName().isBlank() ) return RiotLib.blankNodeToIri(getGraphName()).getURI();
+        throw new TDBException("Bad node for graph name: "+getGraphName());
+    }
+    
     /** Return the associated DatasetGraphTDB.
      * For non-transactional, that's the base storage.
      * For transactional, it is the transactional view.
      * <p>
      * Immediate validity only.
-     * Not valid actoss transacion boundaries, nor non-transactional to transactional. 
+     * Not valid across transatcion boundaries, nor non-transactional to transactional. 
      */
     public abstract DatasetGraphTDB getDatasetGraphTDB() ;
     
+    /** Return the {@link DatasetGraphTransaction}.
+     * If this wrapping a base {@link DatasetGraphTDB}, return null.  
+     */
+    public abstract DatasetGraphTransaction getDatasetGraphTransaction() ;
+
     /** Return the associated base DatasetGraphTDB storage.
      * Use with great care.
      * <p>
@@ -79,6 +94,10 @@ public abstract class GraphTDB extends GraphView implements Closeable,
Sync {
     // This causes it to be passed across transaction boundaries.
     // in the case of fetching, then not using for update in a W transaction,
     // errors occur.
+    //
+    // In TDB1, prefix mapping are limited in usage scope to the transaction.
+    // The issue of the DatasetPrefixStorage.
+    // (Could improve with PrefixMapping that gets the underlying PrefixeMapping each time).
     
     @Override
     public PrefixMapping getPrefixMapping() {
@@ -87,12 +106,21 @@ public abstract class GraphTDB extends GraphView implements Closeable,
Sync {
 
     @Override
     protected PrefixMapping createPrefixMapping() {
+        boolean txnMode = getDatasetGraphTransaction() != null && getDatasetGraphTransaction().getStoreConnection().haveUsedInTransaction()
;
+        if ( ! txnMode )
+            return createPrefixMapping$();
+        return 
+            Txn.calculateRead(getDataset(),()-> createPrefixMapping$()); 
+    }
+    
+    private PrefixMapping createPrefixMapping$() {
         DatasetPrefixStorage dsgPrefixes = getDatasetGraphTDB().getPrefixes() ;
         if ( isDefaultGraph() )
             return dsgPrefixes.getPrefixMapping() ;
         if ( isUnionGraph() )
             return dsgPrefixes.getPrefixMapping() ;
         return dsgPrefixes.getPrefixMapping(getGraphName().getURI()) ;
+        
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/jena/blob/48ab7cbc/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTxnTDB.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTxnTDB.java b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTxnTDB.java
index cde6e1e..8c8814b 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTxnTDB.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/store/GraphTxnTDB.java
@@ -24,11 +24,12 @@ import org.apache.jena.graph.Node ;
 import org.apache.jena.tdb.transaction.DatasetGraphTransaction ;
 
 /**
- * Transaction version of {@link GraphTDB}.
- * Valid across transactions except where noted.
+ * Transaction-capable version of {@link GraphTDB}.
+ * Valid across transactions except where noted (caution: prefix mappings are not).
+ * Valid to use when TDB is not transactional.
  * 
  * @see GraphTDB  
- * @see GraphTxnTDB  
+ * @see GraphNonTxnTDB  
 
  */
 public class GraphTxnTDB extends GraphTDB implements Closeable, Sync {
@@ -41,6 +42,11 @@ public class GraphTxnTDB extends GraphTDB implements Closeable, Sync {
     }
 
     @Override
+    public DatasetGraphTransaction getDatasetGraphTransaction() {
+        return dataset;
+    }
+
+    @Override
     public DatasetGraphTDB getDatasetGraphTDB() {
         return dataset.getDatasetGraphToQuery() ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/48ab7cbc/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
----------------------------------------------------------------------
diff --git a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
index b90d8ec..c02379e 100644
--- a/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
+++ b/jena-tdb/src/main/java/org/apache/jena/tdb/transaction/DatasetGraphTransaction.java
@@ -35,7 +35,6 @@ import org.apache.jena.tdb.TDB ;
 import org.apache.jena.tdb.TDBException;
 import org.apache.jena.tdb.base.file.Location ;
 import org.apache.jena.tdb.store.DatasetGraphTDB ;
-import org.apache.jena.tdb.store.GraphNonTxnTDB ;
 import org.apache.jena.tdb.store.GraphTxnTDB ;
 
 /**
@@ -192,11 +191,8 @@ import org.apache.jena.tdb.store.GraphTxnTDB ;
     }
     
     @Override
-    public Graph getDefaultGraph() { 
-        if ( sConn.haveUsedInTransaction() )
-            return new GraphTxnTDB(this, null) ;
-        else
-            return new GraphNonTxnTDB(getBaseDatasetGraph(), null) ;
+    public Graph getDefaultGraph() {
+        return new GraphTxnTDB(this, null);
     }
 
     @Override
@@ -205,11 +201,8 @@ import org.apache.jena.tdb.store.GraphTxnTDB ;
     }
     
     @Override
-    public Graph getGraph(Node graphNode) {      
-        if ( sConn.haveUsedInTransaction() )
-            return new GraphTxnTDB(this, graphNode) ;
-        else
-            return new GraphNonTxnTDB(getBaseDatasetGraph(), graphNode) ;
+    public Graph getGraph(Node graphNode) {
+        return new GraphTxnTDB(this, graphNode);
     }
 
     @Override


Mime
View raw message