From 71d60c2db03def788c464506afe1e087cf131db8 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 23 Feb 2007 20:16:28 +0000
Subject: [PATCH] Revert the changes in revision #1237 (for issue #740) because they have introduced a large number of test failures.

---
 opendj-sdk/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java |   62 +++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
index 5a9a956..f2439af 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/ID2Entry.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2006 - 2007 Sun Microsystems, Inc.
+ *      Portions Copyright 2006 Sun Microsystems, Inc.
  */
 package org.opends.server.backends.jeb;
 
@@ -296,14 +296,70 @@
   /**
    * Get the count of the number of entries stored.
    *
+   * @param txn A JE database transaction to be used for database access, or
+   * null if none is required.
    * @return The number of entries stored.
    *
    * @throws DatabaseException If an error occurs in the JE database.
    */
-  public long getRecordCount() throws DatabaseException
+  public long getRecordCount(Transaction txn) throws DatabaseException
   {
+    DatabaseEntry key;
+    DatabaseEntry data = new DatabaseEntry();
+
+    // The count is stored in a special record whose key is entry ID zero.
+    EntryID id = new EntryID(0);
+    key = id.getDatabaseEntry();
+
     // Read the current count, if any.
-    return EntryContainer.count(getDatabase());
+    OperationStatus status = EntryContainer.read(getDatabase(), txn,
+                                            key, data, LockMode.DEFAULT);
+
+    // Parse the current count.
+    long count = 0;
+    if (status == OperationStatus.SUCCESS)
+    {
+      count = JebFormat.entryIDFromDatabase(data.getData());
+    }
+
+    return count;
   }
 
+  /**
+   * Adjust the count of the number of entries stored.
+   *
+   * @param txn A database transaction, required to be non-null if multiple
+   *            threads are calling this method concurrently.
+   * @param deltaCount Amount to increment (or decrement if negative).
+   * @throws DatabaseException If an error occurs in the JE database.
+   */
+  public void adjustRecordCount(Transaction txn, long deltaCount)
+       throws DatabaseException
+  {
+    DatabaseEntry key;
+    DatabaseEntry data = new DatabaseEntry();
+
+    // The count is stored in a special record whose key is entry ID zero.
+    EntryID id = new EntryID(0);
+    key = id.getDatabaseEntry();
+
+    // Read the current count, if any.
+    OperationStatus status = EntryContainer.read(getDatabase(), txn,
+                                            key, data, LockMode.RMW);
+
+    // Parse the current count.
+    long count = 0;
+    if (status == OperationStatus.SUCCESS)
+    {
+      count = JebFormat.entryIDFromDatabase(data.getData());
+    }
+
+    // Adjust the count.
+    count += deltaCount;
+
+    // Write it.
+    byte[] bytes = JebFormat.entryIDToDatabase(count);
+    data.setData(bytes);
+    EntryContainer.put(getDatabase(), txn, key, data);
+  }
 }

--
Gitblit v1.10.0