From dc1aafc09ab7fb6287e9fd866fc05c57df71b737 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Mon, 19 Jan 2015 14:33:22 +0000
Subject: [PATCH] Importer.java: In getRebuildListIndexCount(), code cleanup: - extracted methods - fixed a bug I introduced in r11583, where I collapsed several ifs into one.
---
opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java | 105 ++++++++++++++++++++++++++++------------------------
1 files changed, 56 insertions(+), 49 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
index d569381..300b92f 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/importLDIF/Importer.java
@@ -3377,50 +3377,43 @@
else if ("id2subtree".equals(lowerName)
|| "id2children".equals(lowerName))
{
- LocalizableMessage msg = ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
else
{
- String[] attrIndexParts = lowerName.split("\\.");
+ final String[] attrIndexParts = lowerName.split("\\.");
if (attrIndexParts.length <= 0 || attrIndexParts.length > 3)
{
- LocalizableMessage msg = ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
AttributeType attrType = DirectoryServer.getAttributeType(attrIndexParts[0]);
if (attrType == null)
{
- LocalizableMessage msg = ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
if (attrIndexParts.length != 1)
{
- String indexType = attrIndexParts[1];
+ final String indexType = attrIndexParts[1];
if (attrIndexParts.length == 2)
{
if ("presence".equals(indexType)
|| "equality".equals(indexType)
- || "substring".equals(indexType)
|| "ordering".equals(indexType)
+ || "substring".equals(indexType)
|| "approximate".equals(indexType))
{
indexCount++;
}
else
{
- LocalizableMessage msg =
- ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
}
- else
+ else // attrIndexParts.length == 3
{
if (!findExtensibleMatchingRule(cfg, indexType + "." + attrIndexParts[2]))
{
- LocalizableMessage msg =
- ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
indexCount++;
}
@@ -3430,44 +3423,18 @@
boolean found = false;
for (final String idx : cfg.listLocalDBIndexes())
{
- if (!idx.equalsIgnoreCase(index))
+ if (idx.equalsIgnoreCase(index))
{
- continue;
- }
- found = true;
- LocalDBIndexCfg indexCfg = cfg.getLocalDBIndex(idx);
- SortedSet<IndexType> indexType = indexCfg.getIndexType();
- if (indexType.contains(EQUALITY)
- || indexType.contains(ORDERING)
- || indexType.contains(PRESENCE)
- || indexType.contains(SUBSTRING)
- || indexType.contains(APPROXIMATE))
- {
- indexCount++;
- }
- if (indexType.contains(EXTENSIBLE))
- {
- Set<String> extensibleRules = indexCfg.getIndexExtensibleMatchingRule();
- boolean shared = false;
- for (final String exRule : extensibleRules)
- {
- if (exRule.endsWith(".sub"))
- {
- indexCount++;
- }
- else if (!shared)
- {
- shared = true;
- indexCount++;
- }
- }
+ found = true;
+ final LocalDBIndexCfg indexCfg = cfg.getLocalDBIndex(idx);
+ indexCount += getAttributeIndexCount(indexCfg.getIndexType(),
+ PRESENCE, EQUALITY, ORDERING, SUBSTRING, APPROXIMATE);
+ indexCount += getExtensibleIndexCount(indexCfg);
}
}
if (!found)
{
- LocalizableMessage msg =
- ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index);
- throw new InitializationException(msg);
+ throw attributeIndexNotConfigured(index);
}
}
}
@@ -3475,6 +3442,11 @@
return indexCount;
}
+ private InitializationException attributeIndexNotConfigured(String index)
+ {
+ return new InitializationException(ERR_JEB_ATTRIBUTE_INDEX_NOT_CONFIGURED.get(index));
+ }
+
private boolean findExtensibleMatchingRule(LocalDBBackendCfg cfg, String indexExRuleName) throws ConfigException
{
for (String idx : cfg.listLocalDBIndexes())
@@ -3494,6 +3466,41 @@
return false;
}
+ private int getAttributeIndexCount(SortedSet<IndexType> indexTypes, IndexType... toFinds)
+ {
+ int result = 0;
+ for (IndexType toFind : toFinds)
+ {
+ if (indexTypes.contains(toFind))
+ {
+ result++;
+ }
+ }
+ return result;
+ }
+
+ private int getExtensibleIndexCount(LocalDBIndexCfg indexCfg)
+ {
+ int result = 0;
+ if (indexCfg.getIndexType().contains(EXTENSIBLE))
+ {
+ boolean shared = false;
+ for (final String exRule : indexCfg.getIndexExtensibleMatchingRule())
+ {
+ if (exRule.endsWith(".sub"))
+ {
+ result++;
+ }
+ else if (!shared)
+ {
+ shared = true;
+ result++;
+ }
+ }
+ }
+ return result;
+ }
+
private void processEntry(Entry entry, EntryID entryID)
throws DatabaseException, DirectoryException, JebException,
InterruptedException
--
Gitblit v1.10.0