From e02c878b0c0f152b87656ce7b2a170302ccb1e91 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Mon, 07 Jan 2008 11:51:03 +0000
Subject: [PATCH] Fix issue 2482. Improve client side referential integrity checks in admin framework. Also renamed aggregation tests so that they are more easily differentiated and removed "slow" tags from certain aggregation tests now that they perform much quicker.

---
 opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java |   74 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java b/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
index a4b5f79..8fc27ab 100644
--- a/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
+++ b/opends/src/server/org/opends/server/admin/AbstractManagedObjectDefinition.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2007 Sun Microsystems, Inc.
+ *      Portions Copyright 2007-2008 Sun Microsystems, Inc.
  */
 
 package org.opends.server.admin;
@@ -82,6 +82,10 @@
   // definition.
   private final Map<String, RelationDefinition<?, ?>> relationDefinitions;
 
+  // The set of relation definitions directly referencing this managed
+  // object definition.
+  private final Set<RelationDefinition<C, S>> reverseRelationDefinitions;
+
   // The set of all property definitions associated with this managed
   // object definition including inherited property definitions.
   private final Map<String, PropertyDefinition<?>> allPropertyDefinitions;
@@ -120,6 +124,7 @@
     this.constraints = new LinkedList<Constraint>();
     this.propertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
     this.relationDefinitions = new HashMap<String, RelationDefinition<?,?>>();
+    this.reverseRelationDefinitions = new HashSet<RelationDefinition<C,S>>();
     this.allPropertyDefinitions = new HashMap<String, PropertyDefinition<?>>();
     this.allRelationDefinitions =
       new HashMap<String, RelationDefinition<?, ?>>();
@@ -182,7 +187,7 @@
    */
   public final Collection<Constraint> getAllConstraints() {
     // This method does not used a cached set of constraints because
-    // constraints may be updated after child definitions haved been
+    // constraints may be updated after child definitions have been
     // defined.
     List<Constraint> allConstraints = new LinkedList<Constraint>();
 
@@ -228,6 +233,35 @@
 
 
   /**
+   * Get all the relation definitions which refer to this managed
+   * object definition. The returned collection will contain relation
+   * definitions which refer to parents of this managed object
+   * definition.
+   *
+   * @return Returns a collection containing all the relation
+   *         definitions which refer to this managed object
+   *         definition. The caller is free to modify the collection
+   *         if required.
+   */
+  public final Collection<RelationDefinition<? super C, ? super S>>
+  getAllReverseRelationDefinitions() {
+    // This method does not used a cached set of relations because
+    // relations may be updated after child definitions have been
+    // defined.
+    List<RelationDefinition<? super C, ? super S>> rdlist =
+      new LinkedList<RelationDefinition<? super C, ? super S>>();
+
+    if (parent != null) {
+      rdlist.addAll(parent.getAllReverseRelationDefinitions());
+    }
+    rdlist.addAll(reverseRelationDefinitions);
+
+    return rdlist;
+  }
+
+
+
+  /**
    * Get all the tags associated with this type of managed object. The
    * returned collection will contain inherited tags.
    *
@@ -473,6 +507,23 @@
 
 
   /**
+   * Get the relation definitions which refer directly to this managed
+   * object definition. The returned collection will not contain
+   * relation definitions which refer to parents of this managed
+   * object definition.
+   *
+   * @return Returns an unmodifiable collection containing the
+   *         relation definitions which refer directly to this managed
+   *         object definition.
+   */
+  public final Collection<RelationDefinition<C, S>>
+      getReverseRelationDefinitions() {
+    return Collections.unmodifiableCollection(reverseRelationDefinitions);
+  }
+
+
+
+  /**
    * Gets the synopsis of this managed object definition in the
    * default locale.
    *
@@ -815,10 +866,15 @@
    *          The relation definition to be registered.
    */
   protected final void registerRelationDefinition(RelationDefinition<?, ?> d) {
+    // Register the relation in this managed object definition.
     String name = d.getName();
 
     relationDefinitions.put(name, d);
     allRelationDefinitions.put(name, d);
+
+    // Now register the relation in the referenced managed object
+    // definition for reverse lookups.
+    registerReverseRelationDefinition(d);
   }
 
 
@@ -880,9 +936,14 @@
    */
   final void deregisterRelationDefinition(
       RelationDefinition<?, ?> d) {
+   // Deregister the relation from this managed object definition.
     String name = d.getName();
     relationDefinitions.remove(name);
     allRelationDefinitions.remove(name);
+
+    // Now deregister the relation from the referenced managed object
+    // definition for reverse lookups.
+    d.getChildDefinition().reverseRelationDefinitions.remove(d);
   }
 
 
@@ -901,6 +962,15 @@
 
 
 
+  // Register a relation definition in the referenced managed object
+  // definition's reverse lookup table.
+  private <CC extends ConfigurationClient, SS extends Configuration>
+  void registerReverseRelationDefinition(RelationDefinition<CC, SS> rd) {
+    rd.getChildDefinition().reverseRelationDefinitions.add(rd);
+  }
+
+
+
   // Recursively descend definition hierarchy to find the best match definition.
   private AbstractManagedObjectDefinition<? extends C, ? extends S>
       resolveManagedObjectDefinitionAux(

--
Gitblit v1.10.0