jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1450301 - in /jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store: GraphNamedTDB.java GraphTDBBase.java GraphTriplesTDB.java
Date Tue, 26 Feb 2013 17:40:13 GMT
Author: andy
Date: Tue Feb 26 17:40:13 2013
New Revision: 1450301

URL: http://svn.apache.org/r1450301
Log:
Direct all graph operations through the dataset.
TDB graphs bypassed the dataset API and went straight 
to the database tables which is fragile and confusing.

Modified:
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java?rev=1450301&r1=1450300&r2=1450301&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphNamedTDB.java Tue Feb
26 17:40:13 2013
@@ -18,7 +18,6 @@
 
 package com.hp.hpl.jena.tdb.store;
 
-import static com.hp.hpl.jena.sparql.core.Quad.isDefaultGraph ;
 import static com.hp.hpl.jena.sparql.core.Quad.isUnionGraph ;
 
 import java.util.Iterator ;
@@ -30,19 +29,18 @@ import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.graph.TripleMatch ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.util.Utils ;
 import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
 import com.hp.hpl.jena.tdb.sys.TDBInternal ;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
 
 /** A graph implementation that projects a graph from a quad table */
 public class GraphNamedTDB extends GraphTDBBase
 {
+    // Collapse this into GraphTDBBase and have one class, no interface.
+    
     /*
         Quad.unionGraph
         Quad.defaultGraphIRI
@@ -50,15 +48,12 @@ public class GraphNamedTDB extends Graph
     */
     private static Logger log = LoggerFactory.getLogger(GraphNamedTDB.class) ;
     
-    private final QuadTable quadTable ; 
     private NodeId graphNodeId = null ;
 
     public GraphNamedTDB(DatasetGraphTDB dataset, Node graphName) 
     {
         super(dataset, graphName) ;
 
-        this.quadTable = dataset.getQuadTable() ;
-        
         if ( graphName == null )
             throw new TDBException("GraphNamedTDB: Null graph name") ; 
         if ( ! graphName.isURI() )
@@ -71,53 +66,18 @@ public class GraphNamedTDB extends Graph
         return dataset.getPrefixes().getPrefixMapping(graphNode.getURI()) ;
     }
 
-    @Override
-    protected boolean _performAdd( Triple t ) 
-    { 
-        if ( isUnionGraph(graphNode) )
-            throw new TDBException("Can't add a triple to the RDF merge of all named graphs")
;
-        boolean changed ;
-        if ( isDefaultGraph(graphNode) )
-            changed = dataset.getTripleTable().add(t) ;
-        else 
-            changed = dataset.getQuadTable().add(graphNode, t) ;
-        
-        if ( ! changed )
-            duplicate(t) ;
-        return changed ; 
-    }
-
- 
-    @Override
-    protected boolean _performDelete( Triple t ) 
-    { 
-        if ( isUnionGraph(graphNode) )
-            throw new TDBException("Can't delete triple from the RDF merge of all named graphs")
;
-        
-        if ( isDefaultGraph(graphNode) )
-            return dataset.getTripleTable().delete(t) ;
 
-        return dataset.getQuadTable().delete(graphNode, t) ;
-    }
-    
-    @Override
-    protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m)
-    {
-        // Explicitly named default graph
-        if ( isDefaultGraph(graphNode) )
-            // Default graph.
-            return graphBaseFindDft(getDataset(), m) ;
-        // Includes union graph
-        return graphBaseFindNG(getDataset(), graphNode, m) ;
-    }
-    
     @Override
     protected Iterator<Tuple<NodeId>> countThis()
     {
+        if ( isDefaultGraph(graphNode) ) 
+            return dataset.getTripleTable().getNodeTupleTable().findAll() ;
+        
         NodeId gn = isUnionGraph(graphNode) ? null : getGraphNodeId() ; 
         if ( NodeId.isDoesNotExist(gn) )
             return Iter.nullIterator() ;
         
+        // Eliminate this and push all work into find/4. 
         Iterator<Tuple<NodeId>> iter = dataset.getQuadTable().getNodeTupleTable().find(gn,
null, null, null) ;
         if ( isUnionGraph(graphNode) )
         {
@@ -163,17 +123,5 @@ public class GraphNamedTDB extends Graph
     }
 
     @Override
-    final public void close()
-    { 
-        sync() ;
-    }
-    
-    @Override
-    public void sync()
-    {
-        dataset.sync();
-    }
-    
-    @Override
     public String toString() { return Utils.className(this)+":<"+this.graphNode+">"
; }
 }

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java?rev=1450301&r1=1450300&r2=1450301&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTDBBase.java Tue Feb
26 17:40:13 2013
@@ -37,6 +37,7 @@ import com.hp.hpl.jena.graph.impl.GraphB
 import com.hp.hpl.jena.shared.Lock ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.tdb.TDB ;
+import com.hp.hpl.jena.tdb.TDBException ;
 import com.hp.hpl.jena.tdb.graph.BulkUpdateHandlerTDB ;
 import com.hp.hpl.jena.tdb.graph.TransactionHandlerTDB ;
 import com.hp.hpl.jena.tdb.lib.NodeFmtLib ;
@@ -89,17 +90,48 @@ public abstract class GraphTDBBase exten
         finishUpdate() ;
     }
     
-    protected abstract boolean _performAdd( Triple triple ) ;
+    @Override
+    protected final ExtendedIterator<Triple> graphBaseFind(TripleMatch m)
+    {
+        // Explicitly named default graph
+        if ( isDefaultGraph(graphNode) )
+            // Default graph.
+            return graphBaseFindDft(getDataset(), m) ;
+        // Includes union graph
+        return graphBaseFindNG(getDataset(), graphNode, m) ;
+    }
     
-    protected abstract boolean _performDelete( Triple triple ) ;
+    protected final void _performAdd( Triple t ) 
+    {
+        if ( isUnionGraph(graphNode) )
+            throw new TDBException("Can't add a triple to the RDF merge of all named graphs")
;
+        dataset.add(graphNode(), t.getSubject(), t.getPredicate(), t.getObject()) ;
+    }
+ 
+    protected final void _performDelete( Triple t ) 
+    { 
+        if ( isUnionGraph(graphNode) )
+            throw new TDBException("Can't delete triple from the RDF merge of all named graphs")
;
+        dataset.delete(graphNode(), t.getSubject(), t.getPredicate(), t.getObject()) ;
+    }
     
     @Override
-    public abstract void sync() ;
+    public final void sync()        { dataset.sync(); }
+    
+    @Override
+    final public void close()       { sync() ; }
     
     @Override
     // make submodels think about this.
     public abstract String toString() ;
     
+    private Node graphNode() { return ( graphNode != null ) ? graphNode : Quad.defaultGraphNodeGenerated
; }
+
+    protected static boolean isDefaultGraph(Node g)
+    {
+        return g == null || Quad.isDefaultGraph(g) ; 
+    }
+    
     protected void duplicate(Triple t)
     {
         if ( TDB.getContext().isTrue(SystemTDB.symLogDuplicates) && getLog().isInfoEnabled()
)
@@ -223,7 +255,7 @@ public abstract class GraphTDBBase exten
         removeWorker(this, Node.ANY, Node.ANY, Node.ANY) ;
         getEventManager().notifyEvent(this, GraphEvents.removeAll ) ;   
     }
-
+    
     @Override
     public void remove( Node s, Node p, Node o )
     {

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java?rev=1450301&r1=1450300&r2=1450301&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/GraphTriplesTDB.java Tue Feb
26 17:40:13 2013
@@ -24,20 +24,18 @@ import org.apache.jena.atlas.lib.Tuple ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.graph.TripleMatch ;
 import com.hp.hpl.jena.shared.PrefixMapping ;
 import com.hp.hpl.jena.sparql.core.DatasetPrefixStorage ;
 import com.hp.hpl.jena.sparql.util.Utils ;
 import com.hp.hpl.jena.tdb.nodetable.NodeTupleTable ;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
 
 /** A graph implementation that uses a triple table - concrete default graph of dataset */
 public class GraphTriplesTDB extends GraphTDBBase
 {
+    // Collapse this into GraphTDBBase and have one class, no interface.
+    
     private static Logger log = LoggerFactory.getLogger(GraphTriplesTDB.class) ;
     
-    private final TripleTable tripleTable ;
     private final DatasetPrefixStorage prefixes ;
     
     public GraphTriplesTDB(DatasetGraphTDB dataset,
@@ -45,34 +43,11 @@ public class GraphTriplesTDB extends Gra
                            DatasetPrefixStorage prefixes)
     {
         super(dataset, null) ;
-        this.tripleTable = tripleTable ;
         this.prefixes = prefixes ;
     }
-    
-    @Override
-    protected boolean _performAdd( Triple t ) 
-    { 
-        boolean changed = tripleTable.add(t) ;
-        if ( ! changed )
-            duplicate(t) ;
-        return changed ;
-    }
 
     @Override
-    protected boolean _performDelete( Triple t ) 
-    { 
-        boolean changed = tripleTable.delete(t) ;
-        return changed ;
-    }
-    
-    @Override
-    protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m)
-    {
-        return graphBaseFindDft(dataset, m) ;
-    }
-
-//    @Override
-//    public boolean isEmpty()        { return tripleTable.isEmpty() ; }
+    public boolean isEmpty()        { return dataset.getTripleTable().isEmpty() ; }
     
     @Override
     protected final Logger getLog() { return log ; }
@@ -80,11 +55,11 @@ public class GraphTriplesTDB extends Gra
     @Override
     protected Iterator<Tuple<NodeId>> countThis()
     {
-        return tripleTable.getNodeTupleTable().findAll() ;
+        return getNodeTupleTable().findAll() ;
     }
 
     @Override
-    public NodeTupleTable getNodeTupleTable()           { return tripleTable.getNodeTupleTable()
  ; }
+    public NodeTupleTable getNodeTupleTable()           { return dataset.getTripleTable().getNodeTupleTable()
  ; }
    
     @Override
     protected PrefixMapping createPrefixMapping()
@@ -93,35 +68,5 @@ public class GraphTriplesTDB extends Gra
     }
 
     @Override
-    final public void close()
-    {
-        if ( dataset != null )
-        {
-            // Part of a dataset which may be cached and so "close" is meaningless.
-            // At least sync it to flush data to disk.
-            sync() ;
-        }
-        else            
-        {
-            // Free standing graph.  Clear up.
-            prefixes.close();
-            tripleTable.close();
-            super.close() ;
-        }
-    }
-    
-    @Override
-    public void sync()
-    {
-        if ( dataset != null )
-            dataset.sync() ;
-        else
-        {
-            prefixes.sync() ;
-            tripleTable.sync();
-        }
-    }
-    
-    @Override
     public String toString() { return Utils.className(this) ; }
 }



Mime
View raw message