Index: /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java
===================================================================
--- /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java	(revision 508361)
+++ /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/DatabasePersistenceManager.java	(working copy)
@@ -28,6 +28,7 @@
 import org.apache.jackrabbit.core.state.ChangeLog;
 import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.state.ItemStateException;
+import org.apache.jackrabbit.core.state.ItemStateVisitor;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
 import org.apache.jackrabbit.core.state.NodeReferencesId;
@@ -33,9 +34,11 @@
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.VisitableItemStateCollection;
 import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.util.Text;
+import org.apache.jackrabbit.uuid.UUID;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,7 +71,7 @@
  * See the {@link SimpleDbPersistenceManager} for a detailed description
  * of the available configuration options and database behaviour.
  */
-public abstract class DatabasePersistenceManager extends AbstractPersistenceManager {
+public abstract class DatabasePersistenceManager extends AbstractPersistenceManager implements VisitableItemStateCollection {
 
     /**
      * Logger instance
@@ -92,7 +95,7 @@
     protected Connection con;
 
     // internal flag governing whether an automatic reconnect should be
-    // attempted after a SQLException had been encountered    
+    // attempted after a SQLException had been encountered
     protected boolean autoReconnect = true;
     // time to sleep in ms before a reconnect is attempted
     protected static final int SLEEP_BEFORE_RECONNECT = 10000;
@@ -106,6 +109,7 @@
     protected String nodeStateSelectSQL;
     protected String nodeStateSelectExistSQL;
     protected String nodeStateDeleteSQL;
+    protected String nodeStateSelectAllSQL;
 
     // SQL statements for PropertyState management
     protected String propertyStateInsertSQL;
@@ -113,6 +117,7 @@
     protected String propertyStateSelectSQL;
     protected String propertyStateSelectExistSQL;
     protected String propertyStateDeleteSQL;
+    protected String propertyStateSelectAllSQL;
 
     // SQL statements for NodeReference management
     protected String nodeReferenceInsertSQL;
@@ -714,8 +719,68 @@
         }
     }
 
+    //----------------------------------< VisitableItemStateCollection >
+    /**
+     * {@inheritDoc}
+     */
+    public void accept(ItemStateVisitor visitor) throws ItemStateException {
+        accept(nodeStateSelectAllSQL, visitor);
+        accept(propertyStateSelectAllSQL, visitor);
+        }
+
     //----------------------------------< misc. helper methods & overridables >
+    /**
+     *  Helper method for the Visitor accept method.
+     *  @param sql reference to the SQL string to query.
+     *  @param visitor the Visitor instance.
+     *  @throws ItemStateException if any issue
+     */
+    private void accept(String sql, ItemStateVisitor visitor) throws ItemStateException {
+        if (!initialized) {
+            throw new IllegalStateException("not initialized");
+        }
+
+        synchronized (sql) {
+            ResultSet rs = null;
+            InputStream in = null;
+            try {
+                Statement stmt = executeStmt(sql, new Object[0]);
+                rs = stmt.getResultSet();
+
+                while (rs.next()) {
+                    in = null;
+
+                    //to update when a new kind of resource if needed.
+                    //This is quite unlikely though
+                    if (sql.equals(nodeStateSelectAllSQL)) {
+                        String id = rs.getString("NODE_ID");
+                        NodeState state = createNew(new NodeId(new UUID(id)));
 
+                        //In must be here otherwise some objects are partly reseted to null!
+                        in = rs.getBinaryStream("NODE_DATA");
+                        Serializer.deserialize(state, in);
+                        visitor.visit(state);
+                    }
+                    else if (sql.equals(propertyStateSelectAllSQL)) {
+                        //In must be here otherwise some objects are partly reseted to null!
+                        String id = rs.getString("PROP_ID");
+                        PropertyId propId = PropertyId.valueOf(id);
+                        PropertyState state2 = createNew(propId);
+                        in = rs.getBinaryStream("PROP_DATA");
+                        Serializer.deserialize(state2, in, blobStore);
+                        visitor.visit(state2);
+                    }
+                }
+            } catch (Exception e) {
+                String msg = "failed to read node state ";
+                log.error(msg, e);
+                throw new ItemStateException(msg, e);
+            } finally {
+                closeStream(in);
+                closeResultSet(rs);
+            }
+        }
+    }
     /**
      * Initializes the database connection used by this persistence manager.
      * <p>
@@ -1028,7 +1093,6 @@
     protected void buildSQLStatements() {
         nodeStateInsertSQL = "insert into "
                 + schemaObjectPrefix + "NODE (NODE_DATA, NODE_ID) values (?, ?)";
-
         nodeStateUpdateSQL = "update "
                 + schemaObjectPrefix + "NODE set NODE_DATA = ? where NODE_ID = ?";
         nodeStateSelectSQL = "select NODE_DATA from "
@@ -1033,6 +1097,7 @@
                 + schemaObjectPrefix + "NODE set NODE_DATA = ? where NODE_ID = ?";
         nodeStateSelectSQL = "select NODE_DATA from "
                 + schemaObjectPrefix + "NODE where NODE_ID = ?";
+        nodeStateSelectAllSQL = "select NODE_DATA, NODE_ID from " + schemaObjectPrefix + "NODE ";
         nodeStateSelectExistSQL = "select 1 from "
                 + schemaObjectPrefix + "NODE where NODE_ID = ?";
         nodeStateDeleteSQL = "delete from "
@@ -1044,6 +1109,8 @@
                 + schemaObjectPrefix + "PROP set PROP_DATA = ? where PROP_ID = ?";
         propertyStateSelectSQL = "select PROP_DATA from "
                 + schemaObjectPrefix + "PROP where PROP_ID = ?";
+        propertyStateSelectAllSQL = "select PROP_ID, PROP_DATA from "
+                + schemaObjectPrefix + "PROP";
         propertyStateSelectExistSQL = "select 1 from "
                 + schemaObjectPrefix + "PROP where PROP_ID = ?";
         propertyStateDeleteSQL = "delete from "
@@ -1092,6 +1159,8 @@
                 nodeStateSelectExistSQL, con.prepareStatement(nodeStateSelectExistSQL));
         preparedStatements.put(
                 nodeStateDeleteSQL, con.prepareStatement(nodeStateDeleteSQL));
+        preparedStatements.put(
+                nodeStateSelectAllSQL, con.prepareStatement(nodeStateSelectAllSQL));
 
         preparedStatements.put(
                 propertyStateInsertSQL, con.prepareStatement(propertyStateInsertSQL));
@@ -1103,6 +1172,8 @@
                 propertyStateSelectExistSQL, con.prepareStatement(propertyStateSelectExistSQL));
         preparedStatements.put(
                 propertyStateDeleteSQL, con.prepareStatement(propertyStateDeleteSQL));
+        preparedStatements.put(
+        		propertyStateSelectAllSQL, con.prepareStatement(propertyStateSelectAllSQL));
 
         preparedStatements.put(
                 nodeReferenceInsertSQL, con.prepareStatement(nodeReferenceInsertSQL));
Index: /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateVisitor.java
===================================================================
--- /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateVisitor.java	(revision 0)
+++ /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/ItemStateVisitor.java	(revision 0)
@@ -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.apache.jackrabbit.core.state;
+
+/**
+ * Item state visitor. Used to traverse all the item states within a
+ * persistence manager.
+ */
+public interface ItemStateVisitor {
+
+    /**
+     * Visits a node state.
+     *
+     * @param refs node state
+     */
+    void visit(NodeState refs);
+
+    /**
+     * Visits a property state.
+     *
+     * @param state property state
+     */
+    void visit(PropertyState state);
+    
+
+
+}
\ No newline at end of file
Index: /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/VisitableItemStateCollection.java
===================================================================
--- /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/VisitableItemStateCollection.java	(revision 0)
+++ /home/ntoper/workspace/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/VisitableItemStateCollection.java	(revision 0)
@@ -0,0 +1,38 @@
+/*
+ * 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.apache.jackrabbit.core.state;
+
+/**
+ * Interface used to implement a Visitor's pattern. 
+ */
+public interface VisitableItemStateCollection {
+	
+	/**
+	 * Accepts the given item state visitor to visit <em>all</em> the
+	 *item states
+	 * within this persistence manager. The order in which the item
+	 *states are visited
+	 * is not specified. The visitor should not try to call back to
+	 *this persistence manager
+	 * during the visit.
+	 *
+	 * @param visitor item state visitor
+	 * @throws ItemStateException if the item states could not be traverses
+	 */
+	void accept(ItemStateVisitor visitor) throws ItemStateException;
+	
+}
