Return-Path: X-Original-To: apmail-jackrabbit-commits-archive@www.apache.org Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3CAAE7D68 for ; Mon, 19 Dec 2011 15:34:12 +0000 (UTC) Received: (qmail 62808 invoked by uid 500); 19 Dec 2011 15:34:12 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 62765 invoked by uid 500); 19 Dec 2011 15:34:12 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 62758 invoked by uid 99); 19 Dec 2011 15:34:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Dec 2011 15:34:12 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Dec 2011 15:34:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 798B8238899C; Mon, 19 Dec 2011 15:33:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1220800 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java Date: Mon, 19 Dec 2011 15:33:47 -0000 To: commits@jackrabbit.apache.org From: reschke@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111219153347.798B8238899C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reschke Date: Mon Dec 19 15:33:47 2011 New Revision: 1220800 URL: http://svn.apache.org/viewvc?rev=1220800&view=rev Log: JCR-3185: refactor consistency checks in BundleDBPersistenceManager into a standalone class that could be re-used for other PMs use internal getAllIds() method (work-in-progress) Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java?rev=1220800&r1=1220799&r2=1220800&view=diff ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java (original) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/pool/BundleDbPersistenceManager.java Mon Dec 19 15:33:47 2011 @@ -847,54 +847,27 @@ public class BundleDbPersistenceManager int count = 0; int total = 0; Collection modifications = new ArrayList(); - - if (uuids == null) { - // get all node bundles in the database with a single SQL statement, - // which is (probably) faster than loading each bundle and traversing the tree - ResultSet rs = null; - try { - String sql = "select count(*) from " + schemaObjectPrefix + "BUNDLE"; - rs = conHelper.exec(sql, new Object[0], false, 0); - try { - if (!rs.next()) { - String message = "Could not retrieve total number of bundles. empty result set."; - log.error(message); - throw new RepositoryException(message); - } - total = rs.getInt(1); - } finally { - DbUtility.close(rs); - } - if (getStorageModel() == SM_BINARY_KEYS) { - sql = "select NODE_ID from " + schemaObjectPrefix + "BUNDLE"; - } else { - sql = "select NODE_ID_HI, NODE_ID_LO from " + schemaObjectPrefix + "BUNDLE"; - } - rs = conHelper.exec(sql, new Object[0], false, 0); - // iterate over all node bundles in the db - while (rs.next()) { - NodeId id; - if (getStorageModel() == SM_BINARY_KEYS) { - id = new NodeId(rs.getBytes(1)); - } else { - id = new NodeId(rs.getLong(1), rs.getLong(2)); - } + if (uuids == null) { + total = getNumberOfNodeIds(); + + try { + Iterable allIds = getAllNodeIds(null, 0); - // issuing 2nd statement to circumvent issue JCR-1474 - ResultSet bRs = null; + for (NodeId id : allIds) { + ResultSet rs = null; try { - bRs = conHelper.exec(bundleSelectSQL, getKey(id), false, 0); - if (!bRs.next()) { + rs = conHelper.exec(bundleSelectSQL, getKey(id), false, 0); + if (!rs.next()) { throw new SQLException("bundle cannot be retrieved?"); } // parse and check bundle - NodePropBundle bundle = readBundle(id, bRs, 1); + NodePropBundle bundle = readBundle(id, rs, 1); checkBundleConsistency(id, bundle, fix, modifications, reports); } catch (SQLException e) { log.error("Unable to parse bundle " + id, e); } finally { - DbUtility.close(bRs); + DbUtility.close(rs); } count++; @@ -902,10 +875,9 @@ public class BundleDbPersistenceManager log.info(name + ": checked " + count + "/" + total + " bundles..."); } } - } catch (Exception e) { - log.error("Error loading bundle", e); - } finally { - DbUtility.close(rs); + } catch (ItemStateException ex) { + throw new RepositoryException("getting nodeIds", ex); + } finally { total = count; } } else { @@ -1049,6 +1021,25 @@ public class BundleDbPersistenceManager return params.toArray(); } + private synchronized int getNumberOfNodeIds() throws RepositoryException { + ResultSet rs = null; + try { + String sql = "select count(*) from " + schemaObjectPrefix + "BUNDLE"; + rs = conHelper.exec(sql, new Object[0], false, 0); + + if (!rs.next()) { + String message = "Could not retrieve total number of bundles: empty result set."; + log.error(message); + throw new RepositoryException(message); + } + return rs.getInt(1); + } catch (SQLException ex) { + throw new RepositoryException("Could not retrieve total number of bundles", ex); + } finally { + DbUtility.close(rs); + } + } + /** * {@inheritDoc} */