From 619d5d46a827a46b26ef2f71673e89d34b2cec05 Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Fri, 09 Oct 2009 01:02:11 +0000
Subject: [PATCH] - get rid of JE DatabaseException ruse and prepare for JE4 drop-in.

---
 opends/src/server/org/opends/server/backends/jeb/RootContainer.java       |   50 +++++++++++++-----------
 opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java  |   26 ++++++++-----
 opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java |    6 ++-
 opends/src/messages/messages/jeb.properties                               |    2 +
 opends/src/server/org/opends/server/backends/jeb/JebException.java        |   12 +++++
 opends/src/server/org/opends/server/backends/jeb/Index.java               |    8 ++--
 6 files changed, 64 insertions(+), 40 deletions(-)

diff --git a/opends/src/messages/messages/jeb.properties b/opends/src/messages/messages/jeb.properties
index 1c4eabe..75266f8 100644
--- a/opends/src/messages/messages/jeb.properties
+++ b/opends/src/messages/messages/jeb.properties
@@ -69,6 +69,8 @@
 SEVERE_ERR_JEB_ENTRY_DATABASE_CORRUPT_12=The entry database does not contain \
  a valid record for ID %s
 SEVERE_ERR_JEB_DATABASE_EXCEPTION_14=Database exception: %s
+SEVERE_ERR_JEB_ENTRY_CONTAINER_ALREADY_REGISTERED_15=An entry container named \
+ '%s' is alreadly registered for base DN '%s'
 SEVERE_ERR_CONFIG_INDEX_TYPE_NEEDS_MATCHING_RULE_26=The attribute '%s' cannot \
  have indexing of type '%s' because it does not have a corresponding matching \
  rule
diff --git a/opends/src/server/org/opends/server/backends/jeb/Index.java b/opends/src/server/org/opends/server/backends/jeb/Index.java
index 17d196c..1e3fad5 100644
--- a/opends/src/server/org/opends/server/backends/jeb/Index.java
+++ b/opends/src/server/org/opends/server/backends/jeb/Index.java
@@ -328,8 +328,8 @@
         put(null, key, data);
       }
     } else {
-      //Should never happen -- the keys should always be there.
-      throw new DatabaseException();
+      // Should never happen -- the keys should always be there.
+      throw new RuntimeException();
     }
   }
 
@@ -353,8 +353,8 @@
       data.setData(importIdSet.toDatabase());
       put(null, key, data);
     } else {
-      //Should never happen during import.
-      throw new DatabaseException();
+      // Should never happen during import.
+      throw new RuntimeException();
     }
   }
 
diff --git a/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java b/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
index af4c396..b02101f 100644
--- a/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
+++ b/opends/src/server/org/opends/server/backends/jeb/JECompressedSchema.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2008 Sun Microsystems, Inc.
+ *      Copyright 2008-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.backends.jeb;
 
@@ -133,12 +133,15 @@
    * @param  environment  A reference to the database environment in which the
    *                      databases will be held.
    *
-   * @throws  DatabaseException  If a problem occurs while loading the
-   *                             compressed schema definitions from the
-   *                             database.
+   * @throws DatabaseException       If a database problem occurs while loading
+   *                                 the compressed schema definitions from the
+   *                                 database.
+   * @throws InitializationException If an error occurs while loading and
+   *                                 processing the compressed schema
+   *                                 definitions.
    */
   public JECompressedSchema(Environment environment)
-         throws DatabaseException
+         throws DatabaseException, InitializationException
   {
     this.environment = environment;
 
@@ -165,11 +168,14 @@
   /**
    * Loads the compressed schema information from the database.
    *
-   * @throws  DatabaseException  If a problem occurs while loading the
-   *                             definitions from the database.
+   * @throws DatabaseException       If a database error occurs while
+   *                                 loading the definitions from the
+   *                                 database.
+   * @throws InitializationException If an error occurs while loading
+   *                                 and processing the definitions.
    */
   private void load()
-          throws DatabaseException
+          throws DatabaseException, InitializationException
   {
     DatabaseConfig dbConfig = new DatabaseConfig();
 
@@ -242,7 +248,7 @@
 
       Message m =
            ERR_JEB_COMPSCHEMA_CANNOT_DECODE_OC_TOKEN.get(ae.getMessage());
-      throw new DatabaseException(m.toString(), ae);
+      throw new InitializationException(m, ae);
     }
     finally
     {
@@ -314,7 +320,7 @@
 
       Message m =
            ERR_JEB_COMPSCHEMA_CANNOT_DECODE_AD_TOKEN.get(ae.getMessage());
-      throw new DatabaseException(m.toString(), ae);
+      throw new InitializationException(m, ae);
     }
     finally
     {
diff --git a/opends/src/server/org/opends/server/backends/jeb/JebException.java b/opends/src/server/org/opends/server/backends/jeb/JebException.java
index a232f92..c52be71 100644
--- a/opends/src/server/org/opends/server/backends/jeb/JebException.java
+++ b/opends/src/server/org/opends/server/backends/jeb/JebException.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2008 Sun Microsystems, Inc.
+ *      Copyright 2006-2009 Sun Microsystems, Inc.
  */
 package org.opends.server.backends.jeb;
 
@@ -51,6 +51,16 @@
 
 
   /**
+   * Creates a new JE backend exception.
+   */
+  public JebException()
+  {
+    super();
+  }
+
+
+
+  /**
    * Creates a new JE backend exception with the provided message.
    *
    * @param  message    The message that explains the problem that occurred.
diff --git a/opends/src/server/org/opends/server/backends/jeb/RootContainer.java b/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
index 2c34783..3d2e316 100644
--- a/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
+++ b/opends/src/server/org/opends/server/backends/jeb/RootContainer.java
@@ -48,11 +48,8 @@
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import org.opends.server.loggers.debug.DebugTracer;
+import org.opends.server.types.InitializationException;
 import static org.opends.messages.JebMessages.*;
-import static org.opends.messages.ConfigMessages.
-    ERR_CONFIG_BACKEND_MODE_INVALID;
-import static org.opends.messages.ConfigMessages.
-    ERR_CONFIG_BACKEND_INSANE_MODE;
 import static org.opends.server.util.StaticUtils.*;
 import static org.opends.messages.ConfigMessages.*;
 
@@ -134,13 +131,16 @@
   /**
    * Opens the root container using the JE configuration object provided.
    *
-   * @param envConfig The JE environment configuration.
-   * @throws DatabaseException If an error occurs when creating the environment.
-   * @throws ConfigException If an configuration error occurs while creating
-   * the enviornment.
+   * @param  envConfig               The JE environment configuration.
+   * @throws DatabaseException       If a database error occurs when creating
+   *                                 the environment.
+   * @throws InitializationException If an initialization error occurs while
+   *                                 creating the enviornment.
+   * @throws ConfigException         If an configuration error occurs while
+   *                                 creating the enviornment.
    */
   public void open(EnvironmentConfig envConfig)
-      throws DatabaseException, ConfigException
+      throws DatabaseException, InitializationException, ConfigException
   {
     // Determine the backend database directory.
     File parentDirectory = getFileForPath(config.getDBDirectory());
@@ -282,21 +282,23 @@
    *
    * @param baseDN The base DN of the entry container to close.
    * @param entryContainer The entry container to register for the baseDN.
-   * @throws DatabaseException If an error occurs while opening the entry
-   *                           container.
+   * @throws InitializationException If an error occurs while opening the
+   *                                 entry container.
    */
   public void registerEntryContainer(DN baseDN,
                                      EntryContainer entryContainer)
-      throws DatabaseException
+      throws InitializationException
   {
-    EntryContainer ec1=this.entryContainers.get(baseDN);
+    EntryContainer ec1 = this.entryContainers.get(baseDN);
 
-    //If an entry container for this baseDN is already open we don't allow
-    //another to be opened.
+    // If an entry container for this baseDN is already open we don't allow
+    // another to be opened.
     if (ec1 != null)
-      throw new DatabaseException("An entry container named " +
-          ec1.getDatabasePrefix() + " is alreadly registered for base DN " +
-          baseDN.toString());
+    {
+      Message m = ERR_JEB_ENTRY_CONTAINER_ALREADY_REGISTERED.get(
+        ec1.getDatabasePrefix(), baseDN.toString());
+      throw new InitializationException(m);
+    }
 
     this.entryContainers.put(baseDN, entryContainer);
   }
@@ -305,13 +307,15 @@
    * Opens the entry containers for multiple base DNs.
    *
    * @param baseDNs The base DNs of the entry containers to open.
-   * @throws DatabaseException If an error occurs while opening the entry
-   *                           container.
-   * @throws ConfigException if a configuration error occurs while opening the
-   *                         container.
+   * @throws DatabaseException       If a database error occurs while opening
+   *                                 the entry container.
+   * @throws InitializationException If an initialization error occurs while
+   *                                 opening the entry container.
+   * @throws ConfigException         If a configuration error occurs while
+   *                                 opening the entry container.
    */
   private void openAndRegisterEntryContainers(Set<DN> baseDNs)
-      throws DatabaseException, ConfigException
+      throws DatabaseException, InitializationException, ConfigException
   {
     EntryID id;
     EntryID highestID = null;
diff --git a/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java b/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
index 3cc9ef4..65408de 100644
--- a/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
+++ b/opends/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -644,7 +644,9 @@
   }
 
 
-  private void switchContainers() throws DatabaseException, JebException {
+  private void switchContainers()
+    throws DatabaseException, JebException, InitializationException
+  {
 
      for(Suffix suffix : dnSuffixMap.values()) {
        DN baseDN = suffix.getBaseDN();
@@ -1693,7 +1695,7 @@
 
 
     private void cleanUP() throws DatabaseException, DirectoryException,
-            IOException
+      IOException
     {
       if(indexMgr.isDN2ID() && skipDNValidation)
       {

--
Gitblit v1.10.0