jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r793238 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/observation/ main/java/org/apache/jackrabbit/core/persistence/ main/java/org/apache/jackrabbit/core/persi...
Date Sat, 11 Jul 2009 22:46:09 GMT
Author: jukka
Date: Sat Jul 11 22:46:09 2009
New Revision: 793238

URL: http://svn.apache.org/viewvc?rev=793238&view=rev
Log:
JCR-2087: Upgrade to Java 5 as the base platform

Use Iterables and the foreach loop construct to simplify code that accesses a ChangeLog.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ChangeLogBasedHierarchyMgr.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/AbstractPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/XAItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/ChangeLogTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
Sat Jul 11 22:46:09 2009
@@ -370,27 +370,21 @@
     protected void doWrite() throws JournalException {
         writeTimestampRecord();
         writeUserDataRecord();
-        Iterator deletedStates = changes.deletedStates();
-        while (deletedStates.hasNext()) {
-            ItemState state = (ItemState) deletedStates.next();
+        for (ItemState state : changes.deletedStates()) {
             if (state.isNode()) {
                 writeNodeRecord(DELETED, (NodeState) state);
             } else {
                 writePropertyRecord(DELETED, (PropertyState) state);
             }
         }
-        Iterator modifiedStates = changes.modifiedStates();
-        while (modifiedStates.hasNext()) {
-            ItemState state = (ItemState) modifiedStates.next();
+        for (ItemState state : changes.modifiedStates()) {
             if (state.isNode()) {
                 writeNodeRecord(MODIFIED, (NodeState) state);
             } else {
                 writePropertyRecord(MODIFIED, (PropertyState) state);
             }
         }
-        Iterator addedStates = changes.addedStates();
-        while (addedStates.hasNext()) {
-            ItemState state = (ItemState) addedStates.next();
+        for (ItemState state : changes.addedStates()) {
             if (state.isNode()) {
                 writeNodeRecord(ADDED, (NodeState) state);
             } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ChangeLogBasedHierarchyMgr.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ChangeLogBasedHierarchyMgr.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ChangeLogBasedHierarchyMgr.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ChangeLogBasedHierarchyMgr.java
Sat Jul 11 22:46:09 2009
@@ -34,7 +34,6 @@
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.RepositoryException;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -190,7 +189,8 @@
         /**
          * Map of deleted {@link ItemState}s indexed by {@link ItemId}.
          */
-        private final Map deleted = new HashMap();
+        private final Map<ItemId, ItemState> deleted =
+            new HashMap<ItemId, ItemState>();
 
         /**
          * Creates a new <code>AtticItemStateManager</code> based on
@@ -199,8 +199,7 @@
          *  <code>ChangeLog</code>.
          */
         private AtticItemStateManager(ChangeLog changes) {
-            for (Iterator it = changes.deletedStates(); it.hasNext();) {
-                ItemState state = (ItemState) it.next();
+            for (ItemState state : changes.deletedStates()) {
                 deleted.put(state.getId(), state);
             }
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
Sat Jul 11 22:46:09 2009
@@ -178,11 +178,11 @@
      * @param events       the collection of {@link EventState}s.
      * @param deletedItems Iterator of deleted <code>ItemState</code>s.
      */
-    void prepareDeleted(EventStateCollection events, Iterator<ItemState> deletedItems)
{
+    void prepareDeleted(EventStateCollection events, Iterable<ItemState> deletedItems)
{
         Set<ItemId> denied = null;
         Set<ItemId> deletedIds = new HashSet<ItemId>();
-        while (deletedItems.hasNext()) {
-            deletedIds.add((deletedItems.next()).getId());
+        for (ItemState state : deletedItems) {
+            deletedIds.add(state.getId());
         }
 
         for (Iterator<EventState> it = events.iterator(); it.hasNext();) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Sat Jul 11 22:46:09 2009
@@ -160,9 +160,7 @@
          */
 
         // 1. modified items
-
-        for (Iterator<ItemState> it = changes.modifiedStates(); it.hasNext();) {
-            ItemState state = it.next();
+        for (ItemState state : changes.modifiedStates()) {
             if (state.isNode()) {
                 // node changed
                 // covers the following cases:
@@ -349,9 +347,7 @@
         }
 
         // 2. removed items
-
-        for (Iterator<ItemState> it = changes.deletedStates(); it.hasNext();) {
-            ItemState state = it.next();
+        for (ItemState state : changes.deletedStates()) {
             if (state.isNode()) {
                 // node deleted
                 NodeState n = (NodeState) state;
@@ -391,9 +387,7 @@
         }
 
         // 3. added items
-
-        for (Iterator<ItemState> it = changes.addedStates(); it.hasNext();) {
-            ItemState state = it.next();
+        for (ItemState state : changes.addedStates()) {
             if (state.isNode()) {
                 // node created
                 NodeState n = (NodeState) state;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/AbstractPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/AbstractPersistenceManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/AbstractPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/AbstractPersistenceManager.java
Sat Jul 11 22:46:09 2009
@@ -25,8 +25,6 @@
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
 
-import java.util.Iterator;
-
 /**
  * Implementation <code>PersistenceManager</code> that handles some
  * concepts.
@@ -57,36 +55,28 @@
      * {@inheritDoc}
      */
     public synchronized void store(ChangeLog changeLog) throws ItemStateException {
-        Iterator<ItemState> iter = changeLog.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : changeLog.deletedStates()) {
             if (state.isNode()) {
                 destroy((NodeState) state);
             } else {
                 destroy((PropertyState) state);
             }
         }
-        iter = changeLog.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.addedStates()) {
             if (state.isNode()) {
                 store((NodeState) state);
             } else {
                 store((PropertyState) state);
             }
         }
-        iter = changeLog.modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.modifiedStates()) {
             if (state.isNode()) {
                 store((NodeState) state);
             } else {
                 store((PropertyState) state);
             }
         }
-        Iterator<NodeReferences> refIter = changeLog.modifiedRefs();
-        while (iter.hasNext()) {
-            NodeReferences refs = refIter.next();
+        for (NodeReferences refs : changeLog.modifiedRefs()) {
             if (refs.hasReferences()) {
                 store(refs);
             } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/AbstractBundlePersistenceManager.java
Sat Jul 11 22:46:09 2009
@@ -48,7 +48,6 @@
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Set;
 
 import javax.jcr.PropertyType;
@@ -297,27 +296,21 @@
      * {@inheritDoc}
      */
     public synchronized void onExternalUpdate(ChangeLog changes) {
-        Iterator<ItemState> iter = changes.modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.modifiedStates()) {
             if (state.isNode()) {
                 bundles.remove((NodeId) state.getId());
             } else {
                 bundles.remove(state.getParentId());
             }
         }
-        iter = changes.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.deletedStates()) {
             if (state.isNode()) {
                 bundles.remove((NodeId) state.getId());
             } else {
                 bundles.remove(state.getParentId());
             }
         }
-        iter = changes.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.addedStates()) {
             if (state.isNode()) {
                 missing.remove((NodeId) state.getId());
             } else {
@@ -558,9 +551,7 @@
             throws ItemStateException {
         // delete bundles
         HashSet<ItemId> deleted = new HashSet<ItemId>();
-        Iterator<ItemState> iter = changeLog.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : changeLog.deletedStates()) {
             if (state.isNode()) {
                 NodePropBundle bundle = getBundle((NodeId) state.getId());
                 if (bundle == null) {
@@ -572,18 +563,14 @@
         }
         // gather added node states
         HashMap<ItemId, NodePropBundle> modified = new HashMap<ItemId, NodePropBundle>();
-        iter = changeLog.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.addedStates()) {
             if (state.isNode()) {
                 NodePropBundle bundle = new NodePropBundle(getBinding(), (NodeState) state);
                 modified.put(state.getId(), bundle);
             }
         }
         // gather modified node states
-        iter = changeLog.modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.modifiedStates()) {
             if (state.isNode()) {
                 NodeId nodeId = (NodeId) state.getId();
                 NodePropBundle bundle = (NodePropBundle) modified.get(nodeId);
@@ -616,9 +603,7 @@
             }
         }
         // add removed properties
-        iter = changeLog.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.deletedStates()) {
             if (state.isNode()) {
                 // check consistency
                 NodeId parentId = state.getParentId();
@@ -644,9 +629,7 @@
             }
         }
         // add added properties
-        iter = changeLog.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changeLog.addedStates()) {
             if (!state.isNode()) {
                 PropertyId id = (PropertyId) state.getId();
                 // skip primaryType pr mixinTypes properties
@@ -676,9 +659,7 @@
         }
 
         // store the refs
-        Iterator<NodeReferences> itMod = changeLog.modifiedRefs();
-        while (itMod.hasNext()) {
-            NodeReferences refs = itMod.next();
+        for (NodeReferences refs : changeLog.modifiedRefs()) {
             if (refs.hasReferences()) {
                 store(refs);
             } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ChangeLog.java
Sat Jul 11 22:46:09 2009
@@ -16,12 +16,12 @@
  */
 package org.apache.jackrabbit.core.state;
 
-import java.util.Iterator;
 import java.util.Map;
 
 import org.apache.commons.collections.map.LinkedMap;
 import org.apache.jackrabbit.core.id.ItemId;
 import org.apache.jackrabbit.core.id.NodeReferencesId;
+import org.apache.jackrabbit.core.version.VersionItemStateManager;
 
 /**
  * Registers changes made to states and references and consolidates
@@ -118,6 +118,17 @@
     }
 
     /**
+     * Removes the references entry with the given target node id.
+     * This method is called by {@link VersionItemStateManager} to drop
+     * references to virtual nodes.
+     *
+     * @param targetId target node id
+     */
+    public void removeReferencesEntry(NodeReferencesId targetId) {
+        modifiedRefs.remove(targetId);
+    }
+
+    /**
      * Return an item state given its id. Returns <code>null</code>
      * if the item state is neither in the added nor in the modified
      * section. Throws a <code>NoSuchItemStateException</code> if
@@ -184,39 +195,48 @@
     }
 
     /**
-     * Return an iterator over all added states.
+     * Return the added states in this change log.
      *
-     * @return iterator over all added states.
+     * @return added states
      */
-    public Iterator<ItemState> addedStates() {
-        return addedStates.values().iterator();
+    public Iterable<ItemState> addedStates() {
+        return addedStates.values();
     }
 
     /**
-     * Return an iterator over all modified states.
+     * Return the modified states in this change log.
+     * <p>
+     * Note that this change log must not be modified while iterating
+     * through the returned states.
      *
-     * @return iterator over all modified states.
+     * @return modified states
      */
-    public Iterator<ItemState> modifiedStates() {
-        return modifiedStates.values().iterator();
+    public Iterable<ItemState> modifiedStates() {
+        return modifiedStates.values();
     }
 
     /**
-     * Return an iterator over all deleted states.
+     * Return the deleted states in this change log.
+     * <p>
+     * Note that this change log must not be modified while iterating
+     * through the returned states.
      *
-     * @return iterator over all deleted states.
+     * @return deleted states
      */
-    public Iterator<ItemState> deletedStates() {
-        return deletedStates.values().iterator();
+    public Iterable<ItemState> deletedStates() {
+        return deletedStates.values();
     }
 
     /**
-     * Return an iterator over all modified references.
+     * Return the modified references in this change log.
+     * <p>
+     * Note that this change log must not be modified while iterating
+     * through the returned states.
      *
-     * @return iterator over all modified references.
+     * @return modified references
      */
-    public Iterator<NodeReferences> modifiedRefs() {
-        return modifiedRefs.values().iterator();
+    public Iterable<NodeReferences> modifiedRefs() {
+        return modifiedRefs.values();
     }
 
     /**
@@ -226,9 +246,7 @@
      */
     public void merge(ChangeLog other) {
         // Remove all states from our 'added' set that have now been deleted
-        Iterator<ItemState> iter = other.deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : other.deletedStates()) {
             if (addedStates.remove(state.getId()) == null) {
                 deletedStates.put(state.getId(), state);
             }
@@ -237,9 +255,7 @@
         }
 
         // only add modified states that are not already 'added'
-        iter = other.modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : other.modifiedStates()) {
             if (!addedStates.containsKey(state.getId())) {
                 modifiedStates.put(state.getId(), state);
             } else {
@@ -250,9 +266,7 @@
         }
 
         // add 'added' state, but respect previously deleted
-        iter = other.addedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : other.addedStates()) {
             ItemState deletedState = deletedStates.remove(state.getId());
             if (deletedState != null) {
                 // the newly 'added' state had previously been deleted;
@@ -276,17 +290,14 @@
      * items we have.
      */
     public void push() {
-        Iterator<ItemState> iter = modifiedStates();
-        while (iter.hasNext()) {
-            iter.next().push();
-        }
-        iter = deletedStates();
-        while (iter.hasNext()) {
-            iter.next().push();
-        }
-        iter = addedStates();
-        while (iter.hasNext()) {
-            iter.next().push();
+        for (ItemState state : modifiedStates()) {
+            state.push();
+        }
+        for (ItemState state : deletedStates()) {
+            state.push();
+        }
+        for (ItemState state : addedStates()) {
+            state.push();
         }
     }
 
@@ -295,22 +306,16 @@
      * internal states and notify listeners.
      */
     public void persisted() {
-        Iterator<ItemState> iter = modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : modifiedStates()) {
             state.setStatus(ItemState.STATUS_EXISTING);
             state.notifyStateUpdated();
         }
-        iter = deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : deletedStates()) {
             state.setStatus(ItemState.STATUS_EXISTING_REMOVED);
             state.notifyStateDestroyed();
             state.discard();
         }
-        iter = addedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : addedStates()) {
             state.setStatus(ItemState.STATUS_EXISTING);
             state.notifyStateCreated();
         }
@@ -332,17 +337,14 @@
      * states.
      */
     public void disconnect() {
-        Iterator<ItemState> iter = modifiedStates();
-        while (iter.hasNext()) {
-            iter.next().disconnect();
-        }
-        iter = deletedStates();
-        while (iter.hasNext()) {
-            iter.next().disconnect();
-        }
-        iter = addedStates();
-        while (iter.hasNext()) {
-            iter.next().disconnect();
+        for (ItemState state : modifiedStates()) {
+            state.disconnect();
+        }
+        for (ItemState state : deletedStates()) {
+            state.disconnect();
+        }
+        for (ItemState state : addedStates()) {
+            state.disconnect();
         }
     }
 
@@ -354,9 +356,7 @@
      * @param parent parent manager that will hold current data
      */
     public void undo(ItemStateManager parent) {
-        Iterator<ItemState> iter = modifiedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : modifiedStates()) {
             try {
                 state.connect(parent.getItemState(state.getId()));
                 state.pull();
@@ -364,9 +364,7 @@
                 state.discard();
             }
         }
-        iter = deletedStates();
-        while (iter.hasNext()) {
-            ItemState state = iter.next();
+        for (ItemState state : deletedStates()) {
             try {
                 state.connect(parent.getItemState(state.getId()));
                 state.pull();
@@ -374,9 +372,8 @@
                 state.discard();
             }
         }
-        iter = addedStates();
-        while (iter.hasNext()) {
-            iter.next().discard();
+        for (ItemState state : addedStates()) {
+            state.discard();
         }
         reset();
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Sat Jul 11 22:46:09 2009
@@ -18,7 +18,6 @@
 
 import java.io.PrintStream;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -596,8 +595,7 @@
                  * respective shared item and add the shared items to a
                  * new change log.
                  */
-                for (Iterator<ItemState> iter = local.modifiedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : local.modifiedStates()) {
                     state.connect(getItemState(state.getId()));
                     if (state.isStale()) {
                         boolean merged = false;
@@ -653,8 +651,7 @@
 
                     shared.modified(state.getOverlayedState());
                 }
-                for (Iterator<ItemState> iter = local.deletedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : local.deletedStates()) {
                     state.connect(getItemState(state.getId()));
                     if (state.isStale()) {
                         String msg = state.getId() + " has been modified externally";
@@ -663,16 +660,14 @@
                     }
                     shared.deleted(state.getOverlayedState());
                 }
-                for (Iterator<ItemState> iter = local.addedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : local.addedStates()) {
                     state.connect(createInstance(state));
                     shared.added(state.getOverlayedState());
                 }
 
                 // filter out virtual node references for later processing
                 // (see comment above)
-                for (Iterator<NodeReferences> iter = local.modifiedRefs(); iter.hasNext();)
{
-                    NodeReferences refs = iter.next();
+                for (NodeReferences refs : local.modifiedRefs()) {
                     boolean virtual = false;
                     NodeId id = refs.getId().getTargetId();
                     for (int i = 0; i < virtualProviders.length; i++) {
@@ -792,24 +787,21 @@
 
                 local.disconnect();
 
-                for (Iterator<ItemState> iter = shared.modifiedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : shared.modifiedStates()) {
                     try {
                         state.copy(loadItemState(state.getId()), false);
                     } catch (ItemStateException e) {
                         state.discard();
                     }
                 }
-                for (Iterator<ItemState> iter = shared.deletedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : shared.deletedStates()) {
                     try {
                         state.copy(loadItemState(state.getId()), false);
                     } catch (ItemStateException e) {
                         state.discard();
                     }
                 }
-                for (Iterator<ItemState> iter = shared.addedStates(); iter.hasNext();)
{
-                    ItemState state = iter.next();
+                for (ItemState state : shared.addedStates()) {
                     state.discard();
                 }
             } finally {
@@ -878,8 +870,7 @@
          */
         private void updateReferences() throws ItemStateException {
             // process added REFERENCE properties
-            for (Iterator<ItemState> i = local.addedStates(); i.hasNext();) {
-                ItemState state = i.next();
+            for (ItemState state : local.addedStates()) {
                 if (!state.isNode()) {
                     // remove refs from the target which have been added externally (JCR-2138)
                     if (hasItemState(state.getId())) {
@@ -891,8 +882,7 @@
             }
 
             // process modified REFERENCE properties
-            for (Iterator<ItemState> i = local.modifiedStates(); i.hasNext();) {
-                ItemState state = i.next();
+            for (ItemState state : local.modifiedStates()) {
                 if (!state.isNode()) {
                     // remove old references from the target
                     removeReferences(getItemState(state.getId()));
@@ -902,8 +892,8 @@
             }
 
             // process removed REFERENCE properties
-            for (Iterator<ItemState> i = local.deletedStates(); i.hasNext();) {
-                removeReferences(i.next());
+            for (ItemState state : local.deletedStates()) {
+                removeReferences(state);
             }
         }
 
@@ -989,8 +979,7 @@
                 throws ReferentialIntegrityException, ItemStateException {
 
             // check whether removed referenceable nodes are still being referenced
-            for (Iterator<ItemState> iter = local.deletedStates(); iter.hasNext();)
{
-                ItemState state = iter.next();
+            for (ItemState state : local.deletedStates()) {
                 if (state.isNode()) {
                     NodeState node = (NodeState) state;
                     if (isReferenceable(node)) {
@@ -1018,13 +1007,12 @@
             }
 
             // check whether targets of modified node references exist
-            for (Iterator<NodeReferences> iter = local.modifiedRefs(); iter.hasNext();)
{
-                NodeReferences refs = iter.next();
-                NodeId id = refs.getTargetId();
+            for (NodeReferences refs : local.modifiedRefs()) {
                 // no need to check existence of target if there are no references
                 if (refs.hasReferences()) {
                     // please note:
                     // virtual providers are indirectly checked via 'hasItemState()'
+                    NodeId id = refs.getTargetId();
                     if (!local.has(id) && !hasItemState(id)) {
                         String msg = "Target node " + id
                                 + " of REFERENCE property does not exist";
@@ -1177,9 +1165,7 @@
         // Build a copy of the external change log, consisting of shared
         // states we have in our cache. Inform listeners about this
         // change.
-        Iterator<ItemState> modifiedStates = external.modifiedStates();
-        while (modifiedStates.hasNext()) {
-            ItemState state = modifiedStates.next();
+        for (ItemState state : external.modifiedStates()) {
             state = cache.retrieve(state.getId());
             if (state != null) {
                 try {
@@ -1199,9 +1185,7 @@
                 }
             }
         }
-        Iterator<ItemState> deletedStates = external.deletedStates();
-        while (deletedStates.hasNext()) {
-            ItemState state = deletedStates.next();
+        for (ItemState state : external.deletedStates()) {
             state = cache.retrieve(state.getId());
             if (state != null) {
                 shared.deleted(state);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/XAItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/XAItemStateManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/XAItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/XAItemStateManager.java
Sat Jul 11 22:46:09 2009
@@ -36,7 +36,6 @@
 import org.apache.jackrabbit.core.observation.EventStateCollectionFactory;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.core.virtual.VirtualItemStateProvider;
-import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -380,9 +379,7 @@
         if (changes != null) {
             NodeId target = id.getTargetId();
             // check removed reference properties
-            for (Iterator it = filterReferenceProperties(changes.deletedStates());
-                 it.hasNext(); ) {
-                PropertyState prop = (PropertyState) it.next();
+            for (PropertyState prop : filterReferenceProperties(changes.deletedStates()))
{
                 InternalValue[] values = prop.getValues();
                 for (int i = 0; i < values.length; i++) {
                     if (values[i].getNodeId().equals(target)) {
@@ -392,9 +389,7 @@
                 }
             }
             // check added reference properties
-            for (Iterator it = filterReferenceProperties(changes.addedStates());
-                 it.hasNext(); ) {
-                PropertyState prop = (PropertyState) it.next();
+            for (PropertyState prop : filterReferenceProperties(changes.addedStates())) {
                 InternalValue[] values = prop.getValues();
                 for (int i = 0; i < values.length; i++) {
                     if (values[i].getNodeId().equals(target)) {
@@ -404,8 +399,7 @@
                 }
             }
             // check modified properties
-            for (Iterator it = changes.modifiedStates(); it.hasNext(); ) {
-                ItemState state = (ItemState) it.next();
+            for (ItemState state : changes.modifiedStates()) {
                 if (state.isNode()) {
                     continue;
                 }
@@ -448,17 +442,24 @@
      * @param itemStates item state source iterator.
      * @return iterator over reference property states.
      */
-    private Iterator filterReferenceProperties(Iterator itemStates) {
-        return new FilterIterator(itemStates, new Predicate() {
-            public boolean evaluate(Object object) {
-                ItemState state = (ItemState) object;
-                if (!state.isNode()) {
-                    PropertyState prop = (PropertyState) state;
-                    return prop.getType() == PropertyType.REFERENCE;
-                }
-                return false;
+    private Iterable<PropertyState> filterReferenceProperties(
+            final Iterable<ItemState> itemStates) {
+        return new Iterable<PropertyState>() {
+            @SuppressWarnings("unchecked")
+            public Iterator<PropertyState> iterator() {
+                return (Iterator<PropertyState>) new FilterIterator(
+                        itemStates.iterator(), new Predicate() {
+                    public boolean evaluate(Object object) {
+                        ItemState state = (ItemState) object;
+                        if (!state.isNode()) {
+                            PropertyState prop = (PropertyState) state;
+                            return prop.getType() == PropertyType.REFERENCE;
+                        }
+                        return false;
+                    }
+                });
             }
-        });
+        };
     }
 
     /**
@@ -470,8 +471,7 @@
     private void updateVirtualReferences(ChangeLog changes) throws ItemStateException {
         ChangeLog references = new ChangeLog();
 
-        for (Iterator iter = changes.addedStates(); iter.hasNext();) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.addedStates()) {
             if (!state.isNode()) {
                 PropertyState prop = (PropertyState) state;
                 if (prop.getType() == PropertyType.REFERENCE) {
@@ -484,8 +484,7 @@
                 }
             }
         }
-        for (Iterator iter = changes.modifiedStates(); iter.hasNext();) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.modifiedStates()) {
             if (!state.isNode()) {
                 PropertyState newProp = (PropertyState) state;
                 PropertyState oldProp =
@@ -508,8 +507,7 @@
                 }
             }
         }
-        for (Iterator iter = changes.deletedStates(); iter.hasNext();) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : changes.deletedStates()) {
             if (!state.isNode()) {
                 PropertyState prop = (PropertyState) state;
                 if (prop.getType() == PropertyType.REFERENCE) {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionItemStateManager.java
Sat Jul 11 22:46:09 2009
@@ -16,7 +16,8 @@
  */
 package org.apache.jackrabbit.core.version;
 
-import java.util.Iterator;
+import java.util.HashSet;
+import java.util.Set;
 
 import javax.jcr.ReferentialIntegrityException;
 
@@ -94,14 +95,10 @@
         try {
             ChangeLog log = new ChangeLog();
 
-            Iterator iterator = references.modifiedRefs();
-            while (iterator.hasNext()) {
+            for (NodeReferences source : references.modifiedRefs()) {
                 // filter out version storage intern ones
-                NodeReferences source = (NodeReferences) iterator.next();
                 NodeReferences target = new NodeReferences(source.getId());
-                Iterator iter = source.getReferences().iterator();
-                while (iter.hasNext()) {
-                    PropertyId id = (PropertyId) iter.next();
+                for (PropertyId id : source.getReferences()) {
                     if (!hasNonVirtualItemState(id.getParentId())) {
                         target.addReference(id);
                     }
@@ -124,16 +121,19 @@
         // only store VV-type references and NV-type references
 
         // check whether targets of modified node references exist
-        for (Iterator iter = changes.modifiedRefs(); iter.hasNext();) {
-            NodeReferences refs = (NodeReferences) iter.next();
-            NodeId id = refs.getTargetId();
+        Set<NodeReferencesId> remove = new HashSet<NodeReferencesId>();
+        for (NodeReferences refs : changes.modifiedRefs()) {
             // no need to check existence of target if there are no references
             if (refs.hasReferences()) {
+                NodeId id = refs.getTargetId();
                 if (!changes.has(id) && !hasNonVirtualItemState(id)) {
-                    // remove references
-                    iter.remove();
+                    remove.add(refs.getId());
                 }
             }
         }
+        // remove references
+        for (NodeReferencesId id : remove) {
+            changes.removeReferencesEntry(id);
+        }
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/XAVersionManager.java
Sat Jul 11 22:46:09 2009
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.core.version;
 
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
 import javax.jcr.RepositoryException;
@@ -322,9 +321,8 @@
     public boolean setNodeReferences(ChangeLog references) {
         ChangeLog changeLog = ((XAItemStateManager) stateMgr).getChangeLog();
         if (changeLog != null) {
-            Iterator iterator = references.modifiedRefs();
-            while (iterator.hasNext()) {
-                changeLog.modified((NodeReferences) iterator.next());
+            for (NodeReferences refs : references.modifiedRefs()) {
+                changeLog.modified(refs);
             }
             return true;
         } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
Sat Jul 11 22:46:09 2009
@@ -597,9 +597,9 @@
      *         <code>false</code> otherwise.
      */
     private static boolean equals(ChangeLog changes1, ChangeLog changes2) {
-        return equals(changes1.addedStates(), changes2.addedStates()) &&
-            equals(changes1.deletedStates(), changes2.deletedStates()) &&
-            equals(changes1.modifiedStates(), changes2.modifiedStates());
+        return equals(changes1.addedStates().iterator(), changes2.addedStates().iterator())
&&
+            equals(changes1.deletedStates().iterator(), changes2.deletedStates().iterator())
&&
+            equals(changes1.modifiedStates().iterator(), changes2.modifiedStates().iterator());
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/ChangeLogTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/ChangeLogTest.java?rev=793238&r1=793237&r2=793238&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/ChangeLogTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/state/ChangeLogTest.java
Sat Jul 11 22:46:09 2009
@@ -20,11 +20,8 @@
 import org.apache.jackrabbit.spi.commons.name.NameFactoryImpl;
 import org.apache.jackrabbit.core.id.PropertyId;
 import org.apache.jackrabbit.core.id.NodeId;
-import org.apache.jackrabbit.uuid.UUID;
 import org.apache.jackrabbit.spi.NameFactory;
 
-import java.util.Iterator;
-
 /**
  * <code>ChangeLogTest</code> contains the test cases for the methods
  * inside {@link org.apache.jackrabbit.core.state.ChangeLog}.
@@ -51,10 +48,10 @@
         log.added(state);
         log.deleted(state);
 
-        Iterator iter = log.addedStates();
-        assertFalse("State not in added collection", iter.hasNext());
-        iter = log.deletedStates();
-        assertFalse("State not in deleted collection", iter.hasNext());
+        assertFalse("State not in added collection",
+                log.addedStates().iterator().hasNext());
+        assertFalse("State not in deleted collection",
+                log.deletedStates().iterator().hasNext());
     }
 
     /**
@@ -70,10 +67,10 @@
         log.added(state);
         log.modified(state);
 
-        Iterator iter = log.addedStates();
-        assertTrue("State still in added collection", iter.hasNext());
-        iter = log.modifiedStates();
-        assertFalse("State not in modified collection", iter.hasNext());
+        assertTrue("State still in added collection",
+                log.addedStates().iterator().hasNext());
+        assertFalse("State not in modified collection",
+                log.modifiedStates().iterator().hasNext());
     }
 
     /**
@@ -93,11 +90,8 @@
             log.added(states[i]);
         }
 
-        Iterator iter = log.addedStates();
         int i = 0;
-
-        while (iter.hasNext()) {
-            ItemState state = (ItemState) iter.next();
+        for (ItemState state : log.addedStates()) {
             assertTrue("Added states preserve order.",
                     state.equals(states[i++]));
         }



Mime
View raw message