From 79b5e6d4f762912bedeb7d27d744fa7aa007bb91 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 29 Aug 2014 08:07:09 +0000
Subject: [PATCH] Code cleanup

---
 opendj-sdk/opends/src/server/org/opends/server/api/Backend.java |  174 ++++-----------------------------------------------------
 1 files changed, 13 insertions(+), 161 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java b/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
index ebbd4be..fcbb39c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/Backend.java
@@ -38,8 +38,6 @@
 import org.opends.server.monitors.BackendMonitor;
 import org.opends.server.types.*;
 
-import static org.opends.messages.BackendMessages.*;
-
 /**
  * This class defines the set of methods and structures that must be
  * implemented for a Directory Server backend.
@@ -65,7 +63,7 @@
    * The set of backends that hold portions of the DIT that are hierarchically
    * below the information in this backend.
    */
-  private Backend<?>[] subordinateBackends;
+  private Backend<?>[] subordinateBackends = new Backend[0];
 
   /** The backend monitor associated with this backend. */
   private BackendMonitor backendMonitor;
@@ -79,26 +77,7 @@
   private String backendID;
 
   /** The writability mode for this backend. */
-  private WritabilityMode writabilityMode;
-
-
-
-  /**
-   * Creates a new backend with the provided information.  All backend
-   * implementations must implement a default constructor that use
-   * {@code super} to invoke this constructor.
-   */
-  protected Backend()
-  {
-    backendID           = null;
-    parentBackend       = null;
-    subordinateBackends = new Backend[0];
-    isPrivateBackend    = false;
-    writabilityMode     = WritabilityMode.ENABLED;
-    backendMonitor      = null;
-  }
-
-
+  private WritabilityMode writabilityMode = WritabilityMode.ENABLED;
 
   /**
    * Configure this backend based on the information in the provided
@@ -267,10 +246,10 @@
    *          matching rule should be considered indexed, or
    *          {@code false} if not.
    */
-  public boolean isIndexed(AttributeType attributeType,
+  private boolean isIndexed(AttributeType attributeType,
                            MatchingRule matchingRule)
   {
-    return false;
+    return false; // FIXME This should be overridden by the JE Backend at least!
   }
 
 
@@ -321,36 +300,23 @@
         // NOT filters are not considered indexed by default.
         return false;
 
-
       case EQUALITY:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.EQUALITY);
-
+        return isIndexed(filter.getAttributeType(), IndexType.EQUALITY);
 
       case SUBSTRING:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.SUBSTRING);
-
+        return isIndexed(filter.getAttributeType(), IndexType.SUBSTRING);
 
       case GREATER_OR_EQUAL:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.GREATER_OR_EQUAL);
-
+        return isIndexed(filter.getAttributeType(), IndexType.GREATER_OR_EQUAL);
 
       case LESS_OR_EQUAL:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.LESS_OR_EQUAL);
-
+        return isIndexed(filter.getAttributeType(), IndexType.LESS_OR_EQUAL);
 
       case PRESENT:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.PRESENCE);
-
+        return isIndexed(filter.getAttributeType(), IndexType.PRESENCE);
 
       case APPROXIMATE_MATCH:
-        return isIndexed(filter.getAttributeType(),
-                         IndexType.APPROXIMATE);
-
+        return isIndexed(filter.getAttributeType(), IndexType.APPROXIMATE);
 
       case EXTENSIBLE_MATCH:
         // The attribute type must be provided for us to make the
@@ -374,6 +340,7 @@
         {
           matchingRule = attrType.getEqualityMatchingRule();
         }
+        // FIXME isIndexed() always return false down below
         return matchingRule != null && isIndexed(attrType, matchingRule);
 
 
@@ -874,8 +841,6 @@
     return writabilityMode;
   }
 
-
-
   /**
    * Specifies the writability mode for this backend.
    *
@@ -884,14 +849,8 @@
   public final void setWritabilityMode(
                          WritabilityMode writabilityMode)
   {
-    if (writabilityMode == null)
-    {
-      this.writabilityMode = WritabilityMode.ENABLED;
-    }
-    else
-    {
-      this.writabilityMode = writabilityMode;
-    }
+    this.writabilityMode =
+        writabilityMode != null ? writabilityMode : WritabilityMode.ENABLED;
   }
 
 
@@ -989,113 +948,6 @@
     }
   }
 
-
-
-  /**
-   * Indicates whether this backend has a subordinate backend
-   * registered with the provided base DN.  This may check recursively
-   * if a subordinate backend has its own subordinate backends.
-   *
-   * @param  subSuffixDN  The DN of the sub-suffix for which to make
-   *                      the determination.
-   *
-   * @return  {@code true} if this backend has a subordinate backend
-   *          registered with the provided base DN, or {@code false}
-   *          if it does not.
-   */
-  public final boolean hasSubSuffix(DN subSuffixDN)
-  {
-    for (Backend<?> b : subordinateBackends)
-    {
-      for (DN baseDN : b.getBaseDNs())
-      {
-        if (baseDN.equals(subSuffixDN))
-        {
-          return true;
-        }
-      }
-
-      if (b.hasSubSuffix(subSuffixDN))
-      {
-        return true;
-      }
-    }
-
-    return false;
-  }
-
-
-
-  /**
-   * Removes the backend associated with the specified sub-suffix if
-   * it is registered.  This may check recursively if a subordinate
-   * backend has its own subordinate backends.
-   *
-   * @param  subSuffixDN  The DN of the sub-suffix to remove from this
-   *                      backend.
-   * @param  parentDN     The superior DN for the sub-suffix DN that
-   *                      matches one of the subordinate base DNs for
-   *                      this backend.
-   *
-   * @throws  ConfigException  If the sub-suffix exists but it is not
-   *                           possible to remove it for some reason.
-   */
-  public final void removeSubSuffix(DN subSuffixDN, DN parentDN)
-         throws ConfigException
-  {
-    synchronized (this)
-    {
-      boolean matchFound = false;
-      ArrayList<Backend<?>> subBackendList =
-           new ArrayList<Backend<?>>(subordinateBackends.length);
-      for (Backend<?> b : subordinateBackends)
-      {
-        boolean thisMatches = false;
-        DN[] subBaseDNs = b.getBaseDNs();
-        for (DN dn : subBaseDNs)
-        {
-          if (dn.equals(subSuffixDN))
-          {
-            if (subBaseDNs.length > 1)
-            {
-              Message message =
-                      ERR_BACKEND_CANNOT_REMOVE_MULTIBASE_SUB_SUFFIX.
-                              get(String.valueOf(subSuffixDN),
-                                      String.valueOf(parentDN));
-              throw new ConfigException(message);
-            }
-
-            thisMatches = true;
-            matchFound  = true;
-            break;
-          }
-        }
-
-        if (! thisMatches)
-        {
-          if (b.hasSubSuffix(subSuffixDN))
-          {
-            b.removeSubSuffix(subSuffixDN, parentDN);
-          }
-          else
-          {
-            subBackendList.add(b);
-          }
-        }
-      }
-
-      if (matchFound)
-      {
-        Backend<?>[] newSubordinateBackends =
-             new Backend[subBackendList.size()];
-        subBackendList.toArray(newSubordinateBackends);
-        subordinateBackends = newSubordinateBackends;
-      }
-    }
-  }
-
-
-
   /**
    * Adds the provided backend to the set of subordinate backends for
    * this backend.

--
Gitblit v1.10.0