jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1220928 - in /incubator/jena: Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java
Date Mon, 19 Dec 2011 20:21:11 GMT
Author: andy
Date: Mon Dec 19 20:21:11 2011
New Revision: 1220928

URL: http://svn.apache.org/viewvc?rev=1220928&view=rev
Log: (empty)

Added:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java
Modified:
    incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java

Added: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java?rev=1220928&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java
(added)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorWrapper.java
Mon Dec 19 20:21:11 2011
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.openjena.atlas.iterator;
+
+import java.util.Iterator ;
+
+public class IteratorWrapper<T> implements Iterator<T>
+{
+    protected final Iterator<T> iterator ;
+
+    public IteratorWrapper(Iterator<T> iterator)
+    {
+        this.iterator = iterator ;
+    }
+
+    @Override
+    public boolean hasNext()        { return iterator.hasNext() ; }
+
+    @Override
+    public T next()                 { return iterator.next() ; }
+    
+    @Override
+    public void remove()            { iterator.remove() ; }
+}
+

Modified: incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java?rev=1220928&r1=1220927&r2=1220928&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java (original)
+++ incubator/jena/Scratch/AFS/Jena-Dev/trunk/src/dsg/DSG_Notify.java Mon Dec 19 20:21:11
2011
@@ -18,6 +18,10 @@
 
 package dsg;
 
+import java.util.ArrayList ;
+import java.util.Iterator ;
+import java.util.List ;
+
 import org.openjena.atlas.event.Event ;
 import org.openjena.atlas.event.EventManager ;
 import org.openjena.atlas.event.EventType ;
@@ -45,6 +49,33 @@ public class DSG_Notify extends DatasetG
     static final EventType etRemoveQuad     = new EventType(URI+"removeGraph") ;
     static final EventType etClose          = new EventType(URI+"close") ;
     
+    private final class IteratorNotifyQuad implements Iterator<Quad>
+    {
+        private Quad lastSeenQuad = null ;
+        protected final Iterator<Quad> iterator ;
+        
+        public IteratorNotifyQuad(Iterator<Quad> iter) { iterator = iter ; }
+        
+        @Override
+        public boolean hasNext()        { return iterator.hasNext() ; }
+        
+        @Override
+        public Quad next()                 
+        { 
+            lastSeenQuad = iterator.next() ;
+            return lastSeenQuad ;
+        }
+        
+        @Override
+        public void remove()            
+        { 
+            if ( lastSeenQuad == null ) 
+                throw new IllegalStateException("IteratorNotifyQuad.remove: illegal state:
.next no yet called (quad null)") ;
+            deleteEvent(lastSeenQuad) ;
+            iterator.remove() ;
+        }
+    }
+    
     public DSG_Notify(DatasetGraph dsg)
     {
         super(dsg) ;
@@ -53,20 +84,59 @@ public class DSG_Notify extends DatasetG
     @Override
     public void add(Quad quad)
     {
+        addEvent(quad) ;
+        super.add(quad) ;
+    }
+    
+    public void addEvent(Quad quad)
+    {
         Event ev = new Event(etAddQuad, quad) ;
         EventManager.send(this, ev) ;
-        super.add(quad) ;
     }
 
     @Override
     public void delete(Quad quad)
     {
-        
+        deleteEvent(quad) ;
+    }
+
+    public void deleteEvent(Quad quad)
+    {
+        Event ev = new Event(etDeleteQuad, quad) ;
+        EventManager.send(this, ev) ;
     }
 
+    private final static int ChunkSize = 100 ;
+    
     @Override
     public void deleteAny(Node g, Node s, Node p, Node o)
-    {}
+    {
+        List<Quad> quads = new ArrayList<Quad>(ChunkSize) ;
+        
+        // Need to do this manually.
+        // get a chunk ; repeat.
+
+        while(true)
+        {
+            Iterator<Quad> iter = find(g,s,p,o) ;
+            if ( ! iter.hasNext() )
+                break ;
+            
+            int count = 0 ;
+            
+            for ( ; count < ChunkSize ; count++ )
+            {
+                if ( ! iter.hasNext() )
+                    break ;
+                Quad q = iter.next() ;
+                quads.add(q) ;
+            }
+            
+            for ( int i = 0 ; i < quads.size() ; i++ )
+                // With event.
+                delete(quads.get(i)) ;
+        }
+    }
 
     @Override
     public void setDefaultGraph(Graph g)
@@ -83,4 +153,29 @@ public class DSG_Notify extends DatasetG
     @Override
     public void close()
     {}
+    
+    
+    @Override
+    public Iterator<Quad> find()
+    {
+        return new IteratorNotifyQuad(super.getWrapped().find()) ;
+    }
+
+    @Override
+    public Iterator<Quad> find(Quad quad)
+    {
+        return new IteratorNotifyQuad(super.getWrapped().find(quad)) ;
+    }
+
+    @Override
+    public Iterator<Quad> find(Node g, Node s, Node p, Node o)
+    {
+        return new IteratorNotifyQuad(super.getWrapped().find(g, s, p, o)) ;
+    }
+
+    @Override
+    public Iterator<Quad> findNG(Node g, Node s, Node p, Node o)
+    {
+        return new IteratorNotifyQuad(super.getWrapped().findNG(g, s, p, o)) ;
+    }
 }



Mime
View raw message