jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r577297 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/persistence/bundle/ main/java/org/apache/jackrabbit/core/persistence/bundle/util/ test/java/org/apache/jackrabbit/core/data/
Date Wed, 19 Sep 2007 13:07:51 GMT
Author: thomasm
Date: Wed Sep 19 06:07:50 2007
New Revision: 577297

URL: http://svn.apache.org/viewvc?rev=577297&view=rev
Log:
JCR-1138: Add AbstractBundlePersistenceManager.getAllNodeIds

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java
  (with props)
Modified:
    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/persistence/bundle/BundleDbPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java

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=577297&r1=577296&r2=577297&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
Wed Sep 19 06:07:50 2007
@@ -29,6 +29,7 @@
 import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeIdIterator;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.NamespaceRegistryImpl;
 import org.apache.jackrabbit.core.nodetype.PropDefId;
@@ -78,7 +79,7 @@
  * <li>&lt;param name="{@link #setBundleCacheSize(String) bundleCacheSize}" value="8"/>
  * </ul>
  */
-abstract public class AbstractBundlePersistenceManager implements 
+public abstract class AbstractBundlePersistenceManager implements 
         PersistenceManager, CachingPersistenceManager {
 
     /** the cvs/svn id */
@@ -112,13 +113,13 @@
     private LRUNodeIdCache missing;
 
     /** definition id of the jcr:uuid property */
-    private PropDefId ID_JCR_UUID;
+    private PropDefId idJcrUUID;
 
     /** definition id of the jcr:primaryType property */
-    private PropDefId ID_JCR_PRIMARYTYPE;
+    private PropDefId idJcrPrimaryType;
 
     /** definition id of the jcr:mixinTypes property */
-    private PropDefId ID_JCR_MIXINTYPES;
+    private PropDefId idJcrMixinTypes;
 
     /** the persistence manager context */
     protected PMContext context;
@@ -141,7 +142,7 @@
      * @param bundleCacheSize the bundle cache size in megabytes.
      */
     public void setBundleCacheSize(String bundleCacheSize) {
-        this.bundleCacheSize = Long.parseLong(bundleCacheSize)*1024*1024;
+        this.bundleCacheSize = Long.parseLong(bundleCacheSize) * 1024 * 1024;
     }
 
     /**
@@ -368,7 +369,7 @@
     /**
      * {@inheritDoc}
      */
-    abstract public NodeReferences load(NodeReferencesId targetId)
+    public abstract NodeReferences load(NodeReferencesId targetId)
             throws NoSuchItemStateException, ItemStateException;
 
     /**
@@ -404,11 +405,11 @@
 
         // init prop defs
         if (context.getNodeTypeRegistry() != null) {
-            ID_JCR_UUID = context.getNodeTypeRegistry().getEffectiveNodeType(QName.MIX_REFERENCEABLE).getApplicablePropertyDef(
+            idJcrUUID = context.getNodeTypeRegistry().getEffectiveNodeType(QName.MIX_REFERENCEABLE).getApplicablePropertyDef(
                     QName.JCR_UUID, PropertyType.STRING, false).getId();
-            ID_JCR_PRIMARYTYPE = context.getNodeTypeRegistry().getEffectiveNodeType(QName.NT_BASE).getApplicablePropertyDef(
+            idJcrPrimaryType = context.getNodeTypeRegistry().getEffectiveNodeType(QName.NT_BASE).getApplicablePropertyDef(
                     QName.JCR_PRIMARYTYPE, PropertyType.NAME, false).getId();
-            ID_JCR_MIXINTYPES = context.getNodeTypeRegistry().getEffectiveNodeType(QName.NT_BASE).getApplicablePropertyDef(
+            idJcrMixinTypes = context.getNodeTypeRegistry().getEffectiveNodeType(QName.NT_BASE).getApplicablePropertyDef(
                     QName.JCR_MIXINTYPES, PropertyType.NAME, true).getId();
         }
     }
@@ -444,20 +445,20 @@
             if (id.getName().equals(QName.JCR_UUID)) {
                 state = createNew(id);
                 state.setType(PropertyType.STRING);
-                state.setDefinitionId(ID_JCR_UUID);
+                state.setDefinitionId(idJcrUUID);
                 state.setMultiValued(false);
                 state.setValues(new InternalValue[]{InternalValue.create(id.getParentId().getUUID().toString())});
             } else if (id.getName().equals(QName.JCR_PRIMARYTYPE)) {
                 state = createNew(id);
                 state.setType(PropertyType.NAME);
-                state.setDefinitionId(ID_JCR_PRIMARYTYPE);
+                state.setDefinitionId(idJcrPrimaryType);
                 state.setMultiValued(false);
                 state.setValues(new InternalValue[]{InternalValue.create(bundle.getNodeTypeName())});
             } else if (id.getName().equals(QName.JCR_MIXINTYPES)) {
                 Set mixins = bundle.getMixinTypeNames();
                 state = createNew(id);
                 state.setType(PropertyType.NAME);
-                state.setDefinitionId(ID_JCR_MIXINTYPES);
+                state.setDefinitionId(idJcrMixinTypes);
                 state.setMultiValued(true);
                 state.setValues(InternalValue.create((QName[]) mixins.toArray(new QName[mixins.size()])));
             } else {
@@ -475,7 +476,7 @@
      */
     public synchronized boolean exists(PropertyId id) throws ItemStateException {
         NodePropBundle bundle = getBundle(id.getParentId());
-        return bundle !=null && bundle.hasProperty(id.getName());
+        return bundle != null && bundle.hasProperty(id.getName());
     }
 
     /**
@@ -701,4 +702,20 @@
             bundles.put(bundle);
         }
     }
+
+    /**
+     * Get all node ids. 
+     * A typical application will call this method multiple times, where 'after'
+     * is the last row read. The maxCount parameter defines the maximum number of 
+     * node ids returned, 0 meaning no limit. The order of the node ids is specific for the

+     * given persistent manager. Items that are added concurrently may not be included.
+     * 
+     * @param after the lower limit, or null for no limit.
+     * @param maxCount the maximum number of node ids to return, or 0 for no limit.
+     * @return an iterator of all bundles.
+     * @throws ItemStateException if an error while loading occurs.
+     */
+    public abstract NodeIdIterator getAllNodeIds(NodeId after, int maxCount)
+            throws ItemStateException;
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?rev=577297&r1=577296&r2=577297&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
Wed Sep 19 06:07:50 2007
@@ -38,6 +38,7 @@
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
 import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeIdIterator;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.uuid.UUID;
 
@@ -62,6 +63,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.NoSuchElementException;
 
 import javax.jcr.RepositoryException;
 
@@ -149,6 +151,8 @@
     protected String bundleUpdateSQL;
     protected String bundleSelectSQL;
     protected String bundleDeleteSQL;
+    protected String bundleSelectAllIdsFromSQL;
+    protected String bundleSelectAllIdsSQL;
 
     // SQL statements for NodeReference management
     protected String nodeReferenceInsertSQL;
@@ -891,6 +895,63 @@
     /**
      * {@inheritDoc}
      */
+    public synchronized NodeIdIterator getAllNodeIds(NodeId bigger, int maxCount)
+            throws ItemStateException {
+        ResultSet rs = null;
+        try {
+            UUID lowUuid;
+            Object[] keys;
+            String sql;
+            if (bigger == null) {
+                sql = bundleSelectAllIdsSQL;
+                lowUuid = null;
+                keys = new Object[0];
+            } else {
+                sql = bundleSelectAllIdsFromSQL;
+                lowUuid = bigger.getUUID();
+                keys = getKey(lowUuid);
+            }
+            if (maxCount > 0) {
+                // get some more rows, in case the first row is smaller
+                // only required for SM_LONGLONG_KEYS
+                // probability is very low to get get the wrong first key, < 1 : 2^64
+                // see also bundleSelectAllIdsFrom SQL statement
+                maxCount += 10;
+            }
+            Statement stmt = connectionManager.executeStmt(sql, keys, false, maxCount + 10);
+            rs = stmt.getResultSet();
+            ArrayList result = new ArrayList();
+            while ((maxCount == 0 || result.size() < maxCount) && rs.next()) {
+                UUID current;
+                if (getStorageModel() == SM_BINARY_KEYS) {
+                    current = new UUID(rs.getBytes(1));
+                } else {
+                    long high = rs.getLong(1);
+                    long low = rs.getLong(2);
+                    current = new UUID(high, low);
+                }
+                if (lowUuid != null) {
+                    // skip the keys that are smaller or equal (see above, maxCount += 10)
+                    if (current.compareTo(lowUuid) <= 0) {
+                        continue;
+                    }
+                }
+                result.add(current);
+            }        
+            ListNodeIdIterator it = new ListNodeIdIterator(result);
+            return it;
+        } catch (SQLException e) {
+            String msg = "getAllNodeIds failed.";
+            log.error(msg, e);
+            throw new ItemStateException(msg, e);
+        } finally {
+            closeResultSet(rs);
+        }
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
     protected synchronized NodePropBundle loadBundle(NodeId id)
             throws ItemStateException {
         ResultSet rs = null;
@@ -1198,6 +1259,9 @@
             nodeReferenceUpdateSQL = "update " + schemaObjectPrefix + "REFS set REFS_DATA
= ? where NODE_ID = ?";
             nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS
where NODE_ID = ?";
             nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID
= ?";
+            
+            bundleSelectAllIdsSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE";
+            bundleSelectAllIdsFromSQL = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE
WHERE NODE_ID > ? ORDER BY NODE_ID";
         } else {
             bundleInsertSQL = "insert into " + schemaObjectPrefix + "BUNDLE (BUNDLE_DATA,
NODE_ID_HI, NODE_ID_LO) values (?, ?, ?)";
             bundleUpdateSQL = "update " + schemaObjectPrefix + "BUNDLE set BUNDLE_DATA =
? where NODE_ID_HI = ? and NODE_ID_LO = ?";
@@ -1208,7 +1272,13 @@
             nodeReferenceUpdateSQL = "update " + schemaObjectPrefix + "REFS set REFS_DATA
= ? where NODE_ID_HI = ? and NODE_ID_LO = ?";
             nodeReferenceSelectSQL = "select REFS_DATA from " + schemaObjectPrefix + "REFS
where NODE_ID_HI = ? and NODE_ID_LO = ?";
             nodeReferenceDeleteSQL = "delete from " + schemaObjectPrefix + "REFS where NODE_ID_HI
= ? and NODE_ID_LO = ?";
+            
+            bundleSelectAllIdsSQL = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix
+ "BUNDLE";
+            // need to use HI and LO parameters
+            // this is not the exact statement, but not all databases support WHERE (NODE_ID_HI,
NODE_ID_LOW) >= (?, ?)
+            bundleSelectAllIdsFromSQL = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix
+ "BUNDLE WHERE (NODE_ID_HI >= ?) AND (? IS NOT NULL) ORDER BY NODE_ID_HI, NODE_ID_LO";
         }
+        
     }
 
     /**
@@ -1339,4 +1409,35 @@
             // owning BundleDbPersistenceManager
         }
     }
+
+    private class ListNodeIdIterator implements NodeIdIterator {
+        
+        private final ArrayList list;
+        private int pos;
+        
+        ListNodeIdIterator(ArrayList list) {
+            this.list = list;
+        }
+        
+        public NodeId nextNodeId() throws NoSuchElementException {
+            if (!hasNext()) {
+                throw new NoSuchElementException();
+            }
+            return new NodeId((UUID) list.get(pos++));
+        }        
+
+        public boolean hasNext() {
+            return pos < list.size();
+        }
+
+        public Object next() {
+            return nextNodeId();
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+        
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java?rev=577297&r1=577296&r2=577297&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleFsPersistenceManager.java
Wed Sep 19 06:07:50 2007
@@ -20,6 +20,7 @@
 import org.slf4j.LoggerFactory;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.BasedFileSystem;
+import org.apache.jackrabbit.core.fs.FileSystemException;
 import org.apache.jackrabbit.core.fs.local.LocalFileSystem;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
@@ -30,11 +31,13 @@
 import org.apache.jackrabbit.core.persistence.util.BLOBStore;
 import org.apache.jackrabbit.core.persistence.util.FileSystemBLOBStore;
 import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeIdIterator;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.state.ItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferencesId;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeReferences;
+import org.apache.jackrabbit.uuid.UUID;
 
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
@@ -43,6 +46,9 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
 
 /**
  * This is a generic persistence manager that stores the {@link NodePropBundle}s
@@ -677,4 +683,105 @@
         }
     }
 
-}
\ No newline at end of file
+    /**
+     * {@inheritDoc}
+     */
+    public NodeIdIterator getAllNodeIds(NodeId bigger, int maxCount)
+            throws ItemStateException {
+        ArrayList list = new ArrayList();
+        try {
+            getListRecursive(list, "", bigger == null ? null : bigger.getUUID(), maxCount);
+            return new FileNodeIdIterator(list);
+        } catch (FileSystemException e) {
+            String msg = "failed to read node list: " + bigger + ": " + e;
+            log.error(msg);
+            throw new ItemStateException(msg, e);
+        }
+    }
+    
+    /**
+     * {@inheritDoc}
+     */    
+    protected UUID getUUIDFromFileName(String fileName) {
+        StringBuffer buff = new StringBuffer(35);
+        if (!fileName.endsWith("." + NODEFILENAME)) {
+            return null;
+        }
+        for (int i = 0; i < fileName.length(); i++) {
+            char c = fileName.charAt(i);
+            if (c == '.') {
+                break;
+            }
+            if (c != '/') {
+                buff.append(c);
+                int len = buff.length();
+                if (len == 8 || len == 13 || len == 18 || len == 23) {
+                    buff.append('-');
+                }
+            }
+        }
+        String u = buff.toString();
+        return new UUID(u);
+    }    
+    
+    private void getListRecursive(ArrayList list, String path, UUID bigger,
+            int maxCount) throws FileSystemException {
+        if (maxCount > 0 && list.size() >= maxCount) {
+            return;
+        }
+        String[] files = itemFs.listFiles(path);
+        Arrays.sort(files);
+        for (int i = 0; i < files.length; i++) {
+            String f = files[i];
+            UUID u = getUUIDFromFileName(path + FileSystem.SEPARATOR + f);
+            if (u == null) {
+                continue;
+            }
+            if (bigger != null && bigger.toString().compareTo(u.toString()) <
0) {
+                continue;
+            }
+            NodeId n = new NodeId(u);
+            list.add(n);
+            if (maxCount > 0 && list.size() >= maxCount) {
+                return;
+            }
+        }
+        String[] dirs = itemFs.listFolders(path);
+        Arrays.sort(dirs);
+        for (int i = 0; i < dirs.length; i++) {
+            getListRecursive(list, path + FileSystem.SEPARATOR + dirs[i],
+                    bigger, maxCount);
+        }
+    }
+    
+    private static class FileNodeIdIterator implements NodeIdIterator {
+
+        private final ArrayList list;
+        private int pos;
+
+        FileNodeIdIterator(ArrayList list) {
+            this.list = list;
+        }
+
+        public NodeId nextNodeId() throws NoSuchElementException {
+            if (pos < list.size()) {
+                return (NodeId) list.get(pos++);
+            }
+            throw new NoSuchElementException();
+        }
+
+        public boolean hasNext() {
+            return pos < list.size();
+        }
+
+        public Object next() {
+            return nextNodeId();
+        }
+
+        public void remove() {
+            throw new UnsupportedOperationException();
+        }
+        
+    }
+
+}

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java?rev=577297&r1=577296&r2=577297&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ConnectionRecoveryManager.java
Wed Sep 19 06:07:50 2007
@@ -205,36 +205,35 @@
      * @throws SQLException if an error occurs
      */
     public synchronized Statement executeStmt(String sql, Object[] params) throws SQLException
{
-        try {
-            PreparedStatement stmt = (PreparedStatement) preparedStatements.get(sql);
-            if (stmt == null) {
-                stmt = getConnection().prepareStatement(sql);
-                preparedStatements.put(sql, stmt);
-            }
-            return executeStmtInternal(params, stmt);
-        } catch (SQLException e) {
-            logException("could not execute statement", e);
-            close();
-            throw e;
-        }
-    }
+        return executeStmt(sql, params, false, 0);
+    }    
 
     /**
      * Executes the given SQL statement with the specified parameters.
      *
      * @param sql statement to execute
      * @param params parameters to set
-     * @param autoGeneratedKeys the constant that tells the driver to make auto generated
keys available
+     * @param returnGeneratedKeys if the statement should return auto generated keys
+     * @param maxRows the maximum number of rows to return (0 for all rows)
      * @return the <code>Statement</code> object that had been executed
      * @throws SQLException if an error occurs
      */
-    public synchronized Statement executeStmt(String sql, Object[] params, int autoGeneratedKeys)
throws SQLException {
+    public synchronized Statement executeStmt(String sql, Object[] params, boolean returnGeneratedKeys,
int maxRows) throws SQLException {
         try {
-            PreparedStatement stmt = (PreparedStatement) preparedStatements.get(sql + "_"
+ autoGeneratedKeys);
+            String key = sql;
+            if (returnGeneratedKeys) {
+                key += " RETURN_GENERATED_KEYS";
+            }
+            PreparedStatement stmt = (PreparedStatement) preparedStatements.get(key);
             if (stmt == null) {
-                stmt = getConnection().prepareStatement(sql, autoGeneratedKeys);
-                preparedStatements.put(sql + "_" + autoGeneratedKeys, stmt);
+                if (returnGeneratedKeys) {
+                    stmt = getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
+                } else {
+                    stmt = getConnection().prepareStatement(sql);
+                }
+                preparedStatements.put(key, stmt);
             }
+            stmt.setMaxRows(maxRows);
             return executeStmtInternal(params, stmt);
         } catch (SQLException e) {
             logException("could not execute statement", e);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java?rev=577297&r1=577296&r2=577297&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/DbNameIndex.java
Wed Sep 19 06:07:50 2007
@@ -140,7 +140,7 @@
         // assert index does not exist
         ResultSet rs = null;
         try {
-            Statement stmt = connectionManager.executeStmt(nameInsertSQL, new Object[]{string},
Statement.RETURN_GENERATED_KEYS);
+            Statement stmt = connectionManager.executeStmt(nameInsertSQL, new Object[]{string},
true, 0);
             rs = stmt.getGeneratedKeys();
             if (!rs.next()) {
                 return -1;

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java?rev=577297&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java
Wed Sep 19 06:07:50 2007
@@ -0,0 +1,116 @@
+/*
+ * 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.data;
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.NodeIdIterator;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.persistence.PersistenceManager;
+import org.apache.jackrabbit.core.persistence.bundle.AbstractBundlePersistenceManager;
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.jackrabbit.uuid.UUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.lang.reflect.Method;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.Session;
+
+public class PersistenceManagerIteratorTest extends AbstractJCRTest {
+    /** logger instance */
+    private static final Logger LOG = LoggerFactory.getLogger(PersistenceManagerIteratorTest.class);
+
+    private void log(String s) {
+        // System.out.println(s);
+        LOG.info(s);
+    }
+
+    public void testGetAllNodeIds() throws Exception {
+        Node root = testRootNode;
+        Session session = root.getSession();
+        Repository rep = session.getRepository();
+
+        if (!(rep instanceof RepositoryImpl)) {
+            log("Test skipped. Required repository class: "
+                    + RepositoryImpl.class + " got: " + rep.getClass());
+            return;
+        }
+
+        RepositoryImpl r = (RepositoryImpl) rep;
+        Method m = r.getClass().getDeclaredMethod("getWorkspaceNames",
+                new Class[0]);
+        m.setAccessible(true);
+        String[] names = (String[]) m.invoke(r, new Object[0]);
+        for (int i = 0; i < names.length; i++) {
+            m = r.getClass().getDeclaredMethod("getWorkspaceInfo", new Class[] { String.class
});
+            m.setAccessible(true);
+            Object info = m.invoke(r, new String[] { names[i] });
+            m = info.getClass().getDeclaredMethod("getPersistenceManager", new Class[0]);
+            m.setAccessible(true);
+            PersistenceManager pm = (PersistenceManager) m.invoke(info, new Object[0]);
+            if (!(pm instanceof AbstractBundlePersistenceManager)) {
+                log("PM skipped: " + pm.getClass());
+                continue;
+            }
+            AbstractBundlePersistenceManager apm = (AbstractBundlePersistenceManager) pm;
+            log("PM: " + pm.getClass().getName());
+
+            log("All nodes in one step");
+            NodeIdIterator it = apm.getAllNodeIds(null, 0);
+            NodeId after = null;
+            while (it.hasNext()) {
+                NodeId id = it.nextNodeId();
+                log("  " + id.toString());
+                if (after != null) {
+                    assertEquals(id.getUUID().compareTo(after.getUUID()), 1);
+                }
+                after = id;
+            }
+
+            log("All nodes using batches");
+            while (true) {
+                log(" bigger than: " + after);
+                it = apm.getAllNodeIds(after, 2);
+                if (!it.hasNext()) {
+                    break;
+                }
+                while (it.hasNext()) {
+                    NodeId id = it.nextNodeId();
+                    log("    " + id.toString());
+                    assertEquals(id.getUUID().compareTo(after.getUUID()), 1);
+                    after = id;
+                }
+            }
+
+            log("Random access");
+            for (int j = 0; j < 50; j++) {
+                after = new NodeId(UUID.randomUUID());
+                log(" bigger than: " + after);
+                it = apm.getAllNodeIds(after, 2);
+                while (it.hasNext()) {
+                    NodeId id = it.nextNodeId();
+                    log("    " + id.toString());
+                    assertEquals(id.getUUID().compareTo(after.getUUID()), 1);
+                    after = id;
+                }
+            }
+        }
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/PersistenceManagerIteratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java?rev=577297&r1=577296&r2=577297&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/data/TestAll.java
Wed Sep 19 06:07:50 2007
@@ -35,6 +35,7 @@
         suite.addTestSuite(NodeTypeTest.class);
         suite.addTestSuite(ExportImportTest.class);
         suite.addTestSuite(GarbageCollectorTest.class);
+        suite.addTestSuite(PersistenceManagerIteratorTest.class);
         return suite;
     }
 



Mime
View raw message