From 2e1b22a99eb38c9eced95526ccdefbcec1c482d2 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 13 Jan 2015 15:25:40 +0000
Subject: [PATCH] Code cleanup
---
opendj3-server-dev/src/server/org/opends/server/api/Backend.java | 264 +++++++++++++---------------------------------------
1 files changed, 66 insertions(+), 198 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/Backend.java b/opendj3-server-dev/src/server/org/opends/server/api/Backend.java
index f9d422a..e732e5d 100644
--- a/opendj3-server-dev/src/server/org/opends/server/api/Backend.java
+++ b/opendj3-server-dev/src/server/org/opends/server/api/Backend.java
@@ -22,7 +22,7 @@
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
- * Portions Copyright 2014 ForgeRock AS
+ * Portions Copyright 2014-2015 ForgeRock AS
*/
package org.opends.server.api;
@@ -62,7 +62,6 @@
import org.opends.server.types.RestoreConfig;
import org.opends.server.types.SearchFilter;
import org.opends.server.types.WritabilityMode;
-
/**
* This class defines the set of methods and structures that must be
* implemented for a Directory Server backend.
@@ -93,9 +92,7 @@
/** The backend monitor associated with this backend. */
private BackendMonitor backendMonitor;
- /**
- * Indicates whether this is a private backend or one that holds user data.
- */
+ /** Indicates whether this is a private backend or one that holds user data. */
private boolean isPrivateBackend;
/** The unique identifier for this backend. */
@@ -119,8 +116,6 @@
*/
public abstract void configureBackend(C cfg) throws ConfigException;
-
-
/**
* Indicates whether the provided configuration is acceptable for
* this backend. It should be possible to call this method on an
@@ -150,8 +145,6 @@
return true;
}
-
-
/**
* Initializes this backend based on the information provided
* when the backend was configured.
@@ -170,8 +163,6 @@
public abstract void initializeBackend()
throws ConfigException, InitializationException;
-
-
/**
* Performs any necessary work to finalize this backend, including
* closing any underlying databases or connections and deregistering
@@ -196,8 +187,6 @@
persistentSearches.clear();
}
-
-
/**
* Retrieves the set of base-level DNs that may be used within this
* backend.
@@ -207,8 +196,6 @@
*/
public abstract DN[] getBaseDNs();
-
-
/**
* Attempts to pre-load all the entries stored within this backend
* into the entry cache. Note that the caller must ensure that the
@@ -221,10 +208,7 @@
* @throws UnsupportedOperationException if backend does not
* support this operation.
*/
- public abstract void preloadEntryCache()
- throws UnsupportedOperationException;
-
-
+ public abstract void preloadEntryCache() throws UnsupportedOperationException;
/**
* Indicates whether the data associated with this backend may be
@@ -239,8 +223,6 @@
*/
public abstract boolean isLocal();
-
-
/**
* Indicates whether search operations which target the specified
* attribute in the indicated manner would be considered indexed
@@ -265,10 +247,7 @@
* specified attribute in the indicated manner should be
* considered indexed, or {@code false} if not.
*/
- public abstract boolean isIndexed(AttributeType attributeType,
- IndexType indexType);
-
-
+ public abstract boolean isIndexed(AttributeType attributeType, IndexType indexType);
/**
* Indicates whether extensible match search operations that target
@@ -290,8 +269,6 @@
return false; // FIXME This should be overridden by the JE Backend at least!
}
-
-
/**
* Indicates whether a subtree search using the provided filter
* would be indexed in this backend. This default implementation
@@ -387,8 +364,6 @@
}
}
-
-
/**
* Retrieves the requested entry from this backend. Note that the
* caller must hold a read or write lock on the specified DN.
@@ -401,10 +376,7 @@
* @throws DirectoryException If a problem occurs while trying to
* retrieve the entry.
*/
- public abstract Entry getEntry(DN entryDN)
- throws DirectoryException;
-
-
+ public abstract Entry getEntry(DN entryDN) throws DirectoryException;
/**
* Indicates whether the requested entry has any subordinates.
@@ -419,10 +391,7 @@
* @throws DirectoryException If a problem occurs while trying to
* retrieve the entry.
*/
- public abstract ConditionResult hasSubordinates(DN entryDN)
- throws DirectoryException;
-
-
+ public abstract ConditionResult hasSubordinates(DN entryDN) throws DirectoryException;
/**
* Retrieves the number of subordinates for the requested entry.
@@ -441,10 +410,7 @@
* @throws DirectoryException If a problem occurs while trying to
* retrieve the entry.
*/
- public abstract long numSubordinates(DN entryDN, boolean subtree)
- throws DirectoryException;
-
-
+ public abstract long numSubordinates(DN entryDN, boolean subtree) throws DirectoryException;
/**
* Indicates whether an entry with the specified DN exists in the
@@ -462,14 +428,11 @@
* @throws DirectoryException If a problem occurs while trying to
* make the determination.
*/
- public boolean entryExists(DN entryDN)
- throws DirectoryException
+ public boolean entryExists(DN entryDN) throws DirectoryException
{
return getEntry(entryDN) != null;
}
-
-
/**
* Adds the provided entry to this backend. This method must ensure
* that the entry is appropriate for the backend and that no entry
@@ -489,12 +452,9 @@
* cancel or abandon the add
* operation.
*/
- public abstract void addEntry(Entry entry,
- AddOperation addOperation)
+ public abstract void addEntry(Entry entry, AddOperation addOperation)
throws DirectoryException, CanceledOperationException;
-
-
/**
* Removes the specified entry from this backend. This method must
* ensure that the entry exists and that it does not have any
@@ -518,12 +478,9 @@
* cancel or abandon the
* delete operation.
*/
- public abstract void deleteEntry(DN entryDN,
- DeleteOperation deleteOperation)
+ public abstract void deleteEntry(DN entryDN, DeleteOperation deleteOperation)
throws DirectoryException, CanceledOperationException;
-
-
/**
* Replaces the specified entry with the provided entry in this
* backend. The backend must ensure that an entry already exists
@@ -549,8 +506,6 @@
ModifyOperation modifyOperation) throws DirectoryException,
CanceledOperationException;
-
-
/**
* Moves and/or renames the provided entry in this backend, altering
* any subordinate entries as necessary. This must ensure that an
@@ -573,12 +528,9 @@
* If this backend noticed and reacted to a request to
* cancel or abandon the modify DN operation.
*/
- public abstract void renameEntry(DN currentDN, Entry entry,
- ModifyDNOperation modifyDNOperation)
+ public abstract void renameEntry(DN currentDN, Entry entry, ModifyDNOperation modifyDNOperation)
throws DirectoryException, CanceledOperationException;
-
-
/**
* Processes the specified search in this backend. Matching entries
* should be provided back to the core server using the
@@ -598,8 +550,6 @@
public abstract void search(SearchOperation searchOperation)
throws DirectoryException, CanceledOperationException;
-
-
/**
* Retrieves the OIDs of the controls that may be supported by this
* backend.
@@ -609,8 +559,6 @@
*/
public abstract Set<String> getSupportedControls();
-
-
/**
* Indicates whether this backend supports the specified control.
*
@@ -626,8 +574,6 @@
return supportedControls != null && supportedControls.contains(controlOID);
}
-
-
/**
* Retrieves the OIDs of the features that may be supported by this
* backend.
@@ -637,8 +583,6 @@
*/
public abstract Set<String> getSupportedFeatures();
-
-
/**
* Indicates whether this backend supports the specified feature.
*
@@ -654,8 +598,6 @@
return supportedFeatures != null && supportedFeatures.contains(featureOID);
}
-
-
/**
* Indicates whether this backend provides a mechanism to export the
* data it contains to an LDIF file.
@@ -665,8 +607,6 @@
*/
public abstract boolean supportsLDIFExport();
-
-
/**
* Exports the contents of this backend to LDIF. This method should
* only be called if {@code supportsLDIFExport} returns
@@ -679,10 +619,7 @@
* @throws DirectoryException If a problem occurs while performing
* the LDIF export.
*/
- public abstract void exportLDIF(LDIFExportConfig exportConfig)
- throws DirectoryException;
-
-
+ public abstract void exportLDIF(LDIFExportConfig exportConfig) throws DirectoryException;
/**
* Indicates whether this backend provides a mechanism to import its
@@ -693,8 +630,6 @@
*/
public abstract boolean supportsLDIFImport();
-
-
/**
* Imports information from an LDIF file into this backend. This
* method should only be called if {@code supportsLDIFImport}
@@ -709,12 +644,9 @@
* @throws DirectoryException If a problem occurs while performing
* the LDIF import.
*/
- public abstract LDIFImportResult importLDIF(
- LDIFImportConfig importConfig)
+ public abstract LDIFImportResult importLDIF(LDIFImportConfig importConfig)
throws DirectoryException;
-
-
/**
* Indicates whether this backend provides a backup mechanism of any
* kind. This method is used by the backup process when backing up
@@ -729,8 +661,6 @@
*/
public abstract boolean supportsBackup();
-
-
/**
* Indicates whether this backend provides a mechanism to perform a
* backup of its contents in a form that can be restored later,
@@ -747,10 +677,7 @@
* performing backups with the provided configuration, or
* {@code false} if not.
*/
- public abstract boolean supportsBackup(BackupConfig backupConfig,
- StringBuilder unsupportedReason);
-
-
+ public abstract boolean supportsBackup(BackupConfig backupConfig, StringBuilder unsupportedReason);
/**
* Creates a backup of the contents of this backend in a form that
@@ -768,8 +695,6 @@
public abstract void createBackup(BackupConfig backupConfig)
throws DirectoryException;
-
-
/**
* Removes the specified backup if it is possible to do so.
*
@@ -785,12 +710,9 @@
* there are other backups that are
* dependent upon it).
*/
- public abstract void removeBackup(BackupDirectory backupDirectory,
- String backupID)
+ public abstract void removeBackup(BackupDirectory backupDirectory, String backupID)
throws DirectoryException;
-
-
/**
* Indicates whether this backend provides a mechanism to restore a
* backup.
@@ -800,8 +722,6 @@
*/
public abstract boolean supportsRestore();
-
-
/**
* Restores a backup of the contents of this backend. This method
* should only be called if {@code supportsRestore} returns
@@ -817,8 +737,6 @@
public abstract void restoreBackup(RestoreConfig restoreConfig)
throws DirectoryException;
-
-
/**
* Retrieves the unique identifier for this backend.
*
@@ -829,8 +747,6 @@
return backendID;
}
-
-
/**
* Specifies the unique identifier for this backend.
*
@@ -841,8 +757,6 @@
this.backendID = backendID;
}
-
-
/**
* Indicates whether this backend holds private data or user data.
*
@@ -854,8 +768,6 @@
return isPrivateBackend;
}
-
-
/**
* Specifies whether this backend holds private data or user data.
*
@@ -867,8 +779,6 @@
this.isPrivateBackend = isPrivateBackend;
}
-
-
/**
* Retrieves the writability mode for this backend.
*
@@ -884,15 +794,11 @@
*
* @param writabilityMode The writability mode for this backend.
*/
- public final void setWritabilityMode(
- WritabilityMode writabilityMode)
+ public final void setWritabilityMode(WritabilityMode writabilityMode)
{
- this.writabilityMode =
- writabilityMode != null ? writabilityMode : WritabilityMode.ENABLED;
+ this.writabilityMode = writabilityMode != null ? writabilityMode : WritabilityMode.ENABLED;
}
-
-
/**
* Retrieves the backend monitor that is associated with this
* backend.
@@ -951,8 +857,6 @@
this.backendMonitor = backendMonitor;
}
-
-
/**
* Retrieves the total number of entries contained in this backend,
* if that information is available.
@@ -962,8 +866,6 @@
*/
public abstract long getEntryCount();
-
-
/**
* Retrieves the parent backend for this backend.
*
@@ -975,23 +877,16 @@
return parentBackend;
}
-
-
/**
* Specifies the parent backend for this backend.
*
* @param parentBackend The parent backend for this backend.
*/
- public final void setParentBackend(Backend<?> parentBackend)
+ public final synchronized void setParentBackend(Backend<?> parentBackend)
{
- synchronized (this)
- {
- this.parentBackend = parentBackend;
- }
+ this.parentBackend = parentBackend;
}
-
-
/**
* Retrieves the set of subordinate backends for this backend.
*
@@ -1003,21 +898,15 @@
return subordinateBackends;
}
-
-
/**
* Specifies the set of subordinate backends for this backend.
*
* @param subordinateBackends The set of subordinate backends for
* this backend.
*/
- public final void setSubordinateBackends(
- Backend<?>[] subordinateBackends)
+ public final synchronized void setSubordinateBackends(Backend<?>[] subordinateBackends)
{
- synchronized (this)
- {
- this.subordinateBackends = subordinateBackends;
- }
+ this.subordinateBackends = subordinateBackends;
}
/**
@@ -1028,29 +917,23 @@
* subordinate backends for this
* backend.
*/
- public final void addSubordinateBackend(Backend<?> subordinateBackend)
+ public final synchronized void addSubordinateBackend(Backend<?> subordinateBackend)
{
- synchronized (this)
+ LinkedHashSet<Backend<?>> backendSet = new LinkedHashSet<Backend<?>>();
+
+ for (Backend<?> b : subordinateBackends)
{
- LinkedHashSet<Backend<?>> backendSet = new LinkedHashSet<Backend<?>>();
+ backendSet.add(b);
+ }
- for (Backend<?> b : subordinateBackends)
- {
- backendSet.add(b);
- }
-
- if (backendSet.add(subordinateBackend))
- {
- Backend<?>[] newSubordinateBackends =
- new Backend[backendSet.size()];
- backendSet.toArray(newSubordinateBackends);
- subordinateBackends = newSubordinateBackends;
- }
+ if (backendSet.add(subordinateBackend))
+ {
+ Backend<?>[] newSubordinateBackends = new Backend[backendSet.size()];
+ backendSet.toArray(newSubordinateBackends);
+ subordinateBackends = newSubordinateBackends;
}
}
-
-
/**
* Removes the provided backend from the set of subordinate backends
* for this backend.
@@ -1059,39 +942,31 @@
* subordinate backends for this
* backend.
*/
- public final void removeSubordinateBackend(
- Backend<?> subordinateBackend)
+ public final synchronized void removeSubordinateBackend(Backend<?> subordinateBackend)
{
- synchronized (this)
+ ArrayList<Backend<?>> backendList = new ArrayList<Backend<?>>(subordinateBackends.length);
+
+ boolean found = false;
+ for (Backend<?> b : subordinateBackends)
{
- ArrayList<Backend<?>> backendList =
- new ArrayList<Backend<?>>(subordinateBackends.length);
-
- boolean found = false;
- for (Backend<?> b : subordinateBackends)
+ if (b.equals(subordinateBackend))
{
- if (b.equals(subordinateBackend))
- {
- found = true;
- }
- else
- {
- backendList.add(b);
- }
+ found = true;
}
-
- if (found)
+ else
{
- Backend<?>[] newSubordinateBackends =
- new Backend[backendList.size()];
- backendList.toArray(newSubordinateBackends);
- subordinateBackends = newSubordinateBackends;
+ backendList.add(b);
}
}
+
+ if (found)
+ {
+ Backend<?>[] newSubordinateBackends = new Backend[backendList.size()];
+ backendList.toArray(newSubordinateBackends);
+ subordinateBackends = newSubordinateBackends;
+ }
}
-
-
/**
* Indicates whether this backend should be used to handle
* operations for the provided entry.
@@ -1121,8 +996,6 @@
return false;
}
-
-
/**
* Indicates whether a backend should be used to handle operations
* for the provided entry given the set of base DNs and exclude DNs.
@@ -1136,36 +1009,31 @@
* @return {@code true} if the backend should handle operations for
* the provided entry, or {@code false} if it does not.
*/
- public static final boolean handlesEntry(DN entryDN,
- List<DN> baseDNs,
- List<DN> excludeDNs)
+ public static final boolean handlesEntry(DN entryDN, List<DN> baseDNs, List<DN> excludeDNs)
{
for (DN baseDN : baseDNs)
{
- if (entryDN.isDescendantOf(baseDN))
+ if (entryDN.isDescendantOf(baseDN) && !isExcluded(excludeDNs, entryDN))
{
- if (excludeDNs == null || excludeDNs.isEmpty())
- {
- return true;
- }
-
- boolean isExcluded = false;
- for (DN excludeDN : excludeDNs)
- {
- if (entryDN.isDescendantOf(excludeDN))
- {
- isExcluded = true;
- break;
- }
- }
-
- if (! isExcluded)
- {
- return true;
- }
+ return true;
}
}
+ return false;
+ }
+ private static boolean isExcluded(List<DN> excludeDNs, DN entryDN)
+ {
+ if (excludeDNs == null || excludeDNs.isEmpty())
+ {
+ return false;
+ }
+ for (DN excludeDN : excludeDNs)
+ {
+ if (entryDN.isDescendantOf(excludeDN))
+ {
+ return true;
+ }
+ }
return false;
}
}
--
Gitblit v1.10.0