From 1c7ffd3972120112aa5317ed2649c1a0435a213e Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Thu, 13 Sep 2007 17:22:44 +0000
Subject: [PATCH] Make a couple of changes to speed up schema interaction.

---
 opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java        |   13 +++++++++++--
 opendj-sdk/opends/src/server/org/opends/server/types/ObjectClass.java          |   19 ++++++++++++++++++-
 opendj-sdk/opends/src/server/org/opends/server/types/CommonSchemaElements.java |    7 ++++++-
 3 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
index 5f419d9..fb02b4b 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/AttributeType.java
@@ -101,6 +101,9 @@
   // Indicates whether this attribute type is the objectclass type.
   private final boolean isObjectClassType;
 
+  // Indicates whether this attribute type is operational.
+  private final boolean isOperational;
+
   // Indicates whether this attribute type is declared "single-value".
   private final boolean isSingleValue;
 
@@ -120,6 +123,9 @@
   // The definition string used to create this attribute type.
   private final String definition;
 
+  // The OID for the associated syntax.
+  private final String syntaxOID;
+
   // The substring matching rule for this attribute type.
   private final SubstringMatchingRule substringMatchingRule;
 
@@ -324,6 +330,7 @@
     {
       this.syntax = syntax;
     }
+    syntaxOID = this.syntax.getOID();
 
 
     if (approximateMatchingRule == null)
@@ -386,6 +393,8 @@
     {
       isObjectClassType = hasName(OBJECTCLASS_ATTRIBUTE_TYPE_NAME);
     }
+
+    isOperational = this.attributeUsage.isOperational();
   }
 
 
@@ -504,7 +513,7 @@
    */
   public String getSyntaxOID()
   {
-    return syntax.getOID();
+    return syntaxOID;
   }
 
 
@@ -588,7 +597,7 @@
    */
   public boolean isOperational()
   {
-    return attributeUsage.isOperational();
+    return isOperational;
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/CommonSchemaElements.java b/opendj-sdk/opends/src/server/org/opends/server/types/CommonSchemaElements.java
index 10dcb95..cc40cc5 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/CommonSchemaElements.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/CommonSchemaElements.java
@@ -74,6 +74,9 @@
   // Indicates whether this definition is declared "obsolete".
   private final boolean isObsolete;
 
+  // The hash code for this definition.
+  private final int hashCode;
+
   // The set of additional name-value pairs associated with this
   // definition.
   private final Map<String, List<String>> extraProperties;
@@ -141,6 +144,8 @@
     this.description = description;
     this.isObsolete = isObsolete;
 
+    hashCode = oid.hashCode();
+
     // Make sure we have a primary name if possible.
     if (primaryName == null) {
       if (names != null && !names.isEmpty()) {
@@ -497,7 +502,7 @@
    */
   public final int hashCode() {
 
-    return oid.hashCode();
+    return hashCode;
   }
 
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/types/ObjectClass.java b/opendj-sdk/opends/src/server/org/opends/server/types/ObjectClass.java
index d1ccece..b77b57a 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/types/ObjectClass.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/types/ObjectClass.java
@@ -89,6 +89,10 @@
   // superclasses.
   private final Set<AttributeType> requiredAttributesChain;
 
+  // The set of required and optional attributes for this objectclass
+  // and its superclasses.
+  private final Set<AttributeType> requiredAndOptionalChain;
+
   // The reference to the superior objectclass.
   private final ObjectClass superiorClass;
 
@@ -238,6 +242,16 @@
       this.optionalAttributesChain = Collections.unmodifiableSet(tmp);
     }
 
+    // Construct unmodifiable views of the required and optional
+    // attribute chains.
+    HashSet<AttributeType> reqAndOptSet =
+         new HashSet<AttributeType>(requiredAttributesChain.size() +
+                                    optionalAttributesChain.size());
+    reqAndOptSet.addAll(requiredAttributesChain);
+    reqAndOptSet.addAll(optionalAttributesChain);
+    requiredAndOptionalChain =
+         Collections.<AttributeType>unmodifiableSet(reqAndOptSet);
+
     // Object class type defaults to structural.
     if (objectClassType != null) {
       this.objectClassType = objectClassType;
@@ -447,7 +461,10 @@
    */
   public boolean isRequiredOrOptional(AttributeType attributeType) {
 
-    return (isRequired(attributeType) || isOptional(attributeType));
+    // FIXME -- Do we need to do any other checks here, like whether
+    // the attribute type is actually defined in the schema?
+    return (isExtensibleObject ||
+            requiredAndOptionalChain.contains(attributeType));
   }
 
 

--
Gitblit v1.10.0