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 2013/08/15 14:26:49 UTC

svn commit: r1514244 - in /jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb: solver/SolverLib.java store/DatasetGraphTDB.java store/GraphTDB.java

Author: andy
Date: Thu Aug 15 12:26:49 2013
New Revision: 1514244

URL: http://svn.apache.org/r1514244
Log:
JENA-513 : Move the batch delete code from GraphTDB to DatsetgraphTDB.

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java?rev=1514244&r1=1514243&r2=1514244&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/solver/SolverLib.java Thu Aug 15 12:26:49 2013
@@ -85,7 +85,7 @@ public class SolverLib
                                         QueryIterator input, Filter<Tuple<NodeId>> filter,
                                         ExecutionContext execCxt)
     {
-        NodeTupleTable ntt = GraphTDB.chooseNodeTupleTable(ds, graphNode) ;
+        NodeTupleTable ntt = ds.chooseNodeTupleTable(graphNode) ;
         return execute(ntt, graphNode, pattern, input, filter, execCxt) ;
     }
     

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java?rev=1514244&r1=1514243&r2=1514244&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DatasetGraphTDB.java Thu Aug 15 12:26:49 2013
@@ -38,6 +38,7 @@ import com.hp.hpl.jena.sparql.core.Quad 
 import com.hp.hpl.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.lib.NodeLib ;
+import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
 import com.hp.hpl.jena.tdb.sys.Session ;
 import com.hp.hpl.jena.tdb.transaction.DatasetGraphTransaction ;
 import com.hp.hpl.jena.tdb.transaction.DatasetGraphTxn ;
@@ -117,24 +118,6 @@ public class DatasetGraphTDB extends Dat
         return triples2quads(Quad.defaultGraphIRI, iter) ;
     }
     
-//    @Override
-//    public void add(Quad quad)
-//    {
-//        if ( quad.isDefaultGraph() )
-//            getTripleTable().add(quad.asTriple()) ;
-//        else
-//            getQuadTable().add(quad) ;
-//    } 
-//    
-//    @Override
-//    public void delete(Quad quad)
-//    {
-//        if ( quad.isDefaultGraph() )
-//            getTripleTable().delete(quad.asTriple()) ;
-//        else
-//            getQuadTable().delete(quad) ;
-//    }
-    
     @Override
     protected void addToDftGraph(Node s, Node p, Node o)
     { getTripleTable().add(s,p,o) ; }
@@ -257,6 +240,61 @@ public class DatasetGraphTDB extends Dat
         getQuadTable().clearQuads() ;
     }
     
+    public NodeTupleTable chooseNodeTupleTable(Node graphNode)
+    {
+        if ( graphNode == null || Quad.isDefaultGraph(graphNode) )
+            return getTripleTable().getNodeTupleTable() ;
+        else
+            // Includes Node.ANY and union graph
+            return getQuadTable().getNodeTupleTable() ;
+    }
+    
+    private static final int sliceSize = 1000 ;
+    
+    @Override
+    public void deleteAny(Node g, Node s, Node p, Node o) {
+        // Delete in batches.
+        // That way, there is no active iterator when a delete
+        // from the indexes happens.
+
+        NodeTupleTable t = chooseNodeTupleTable(g) ;
+        startUpdate() ;
+        @SuppressWarnings("unchecked")
+        Tuple<NodeId>[] array = (Tuple<NodeId>[])new Tuple<?>[sliceSize] ;
+
+        while (true) { // Convert/cache s,p,o?
+            // The Node Cache will catch these so don't worry unduely.
+            Iterator<Tuple<NodeId>> iter = null ;
+            if ( g == null )
+                iter = t.findAsNodeIds(s, p, o) ;
+            else
+                iter = t.findAsNodeIds(g, s, p, o) ;
+
+            if ( iter == null )
+                // Finished?
+                return ;
+
+            // Get a slice
+            int len = 0 ;
+            for (; len < sliceSize; len++) {
+                if ( !iter.hasNext() )
+                    break ;
+                array[len] = iter.next() ;
+            }
+
+            // Delete them.
+            for (int i = 0; i < len; i++) {
+                t.getTupleTable().delete(array[i]) ;
+                array[i] = null ;
+            }
+            // Finished?
+            if ( len < sliceSize )
+                break ;
+        }
+
+        finishUpdate() ;
+    }
+    
     public Location getLocation()       { return config.location ; }
 
     @Override

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java?rev=1514244&r1=1514243&r2=1514244&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDB.java Thu Aug 15 12:26:49 2013
@@ -53,25 +53,23 @@ public class GraphTDB extends GraphView 
         this.dataset = dataset ;
     }
     
-    
     /** get the current TDB dataset graph - changes for transactions */  
     public DatasetGraphTDB getDSG()
-    //{ return dataset.get() ; }
     { return dataset ; }
 
     /** The NodeTupleTable for this graph */ 
     public NodeTupleTable getNodeTupleTable()
     {
-        return chooseNodeTupleTable(getDSG(), getGraphName()) ;
+        return getDSG().chooseNodeTupleTable(getGraphName()) ;
     }
-    
+
+    /**
+     * @deprecated Use DatasetGraphTDB.chooseNodeTupleTable
+     */
+    @Deprecated
     public static NodeTupleTable chooseNodeTupleTable(DatasetGraphTDB dsg, Node graphNode)
     {
-        if ( graphNode == null || Quad.isDefaultGraph(graphNode) )
-            return dsg.getTripleTable().getNodeTupleTable() ;
-        else
-            // Includes Node.ANY and union graph
-            return dsg.getQuadTable().getNodeTupleTable() ;
+        return dsg.chooseNodeTupleTable(graphNode) ;
     }
     
     @Override
@@ -242,7 +240,7 @@ public class GraphTDB extends GraphView 
     @Override
     public void clear()
     {
-        removeWorker(this, Node.ANY, Node.ANY, Node.ANY) ;
+        dataset.deleteAny(getGraphName(), Node.ANY, Node.ANY, Node.ANY) ;
         getEventManager().notifyEvent(this, GraphEvents.removeAll ) ;   
     }
     
@@ -256,60 +254,8 @@ public class GraphTDB extends GraphView 
             return ;
         }
         
-        removeWorker(this, s, p, o) ;
+        dataset.deleteAny(getGraphName(), s, p, o);
         // We know no one is listening ...
         //getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ;
     }
-
-    private static final int sliceSize = 1000 ;
-
-    public static void removeWorker(GraphTDB gv, Node s, Node p, Node o)
-    {
-        NodeTupleTable t = gv.getNodeTupleTable() ;
-        DatasetGraphTDB dsg = gv.getDSG() ;
-        dsg.startUpdate() ;
-        Node gn = gv.getGraphName() ;
-
-        // Delete in batches.
-        // That way, there is no active iterator when a delete 
-        // from the indexes happens.
-        
-        @SuppressWarnings("unchecked")
-        Tuple<NodeId>[] array = (Tuple<NodeId>[])new Tuple<?>[sliceSize] ;
-        
-        while (true)
-        {
-            // Convert/cache s,p,o?
-            // The Node Cache will catch these so don't worry unduely. 
-            Iterator<Tuple<NodeId>> iter = null ;
-            if ( gn == null )
-                iter = t.findAsNodeIds(s, p, o) ;
-            else
-                iter = t.findAsNodeIds(gn, s, p, o) ;
-            
-            if ( iter == null )
-                // Finished?
-                return ;
-            
-            // Get a slice
-            int len = 0 ;
-            for ( ; len < sliceSize ; len++ )
-            {
-                if ( !iter.hasNext() ) break ;
-                array[len] = iter.next() ;
-            }
-            
-            // Delete them.
-            for ( int i = 0 ; i < len ; i++ )
-            {
-                t.getTupleTable().delete(array[i]) ;
-                array[i] = null ;
-            }
-            // Finished?
-            if ( len < sliceSize )
-                break ;
-        }
-        
-        dsg.finishUpdate() ;
-    }
 }