public void deleteTenantByClusterIdx(long ClusterId) {
   CFSecurityTenantByClusterIdxKey key =
       ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
   key.setRequiredClusterId(ClusterId);
   if (indexByClusterIdx == null) {
     indexByClusterIdx =
         new HashMap<
             CFSecurityTenantByClusterIdxKey, Map<CFSecurityTenantPKey, ICFSecurityTenantObj>>();
   }
   if (indexByClusterIdx.containsKey(key)) {
     Map<CFSecurityTenantPKey, ICFSecurityTenantObj> dict = indexByClusterIdx.get(key);
     ((ICFSecuritySchema) schema.getBackingStore())
         .getTableTenant()
         .deleteTenantByClusterIdx(schema.getAuthorization(), ClusterId);
     Iterator<ICFSecurityTenantObj> iter = dict.values().iterator();
     ICFSecurityTenantObj obj;
     List<ICFSecurityTenantObj> toForget = new LinkedList<ICFSecurityTenantObj>();
     while (iter.hasNext()) {
       obj = iter.next();
       toForget.add(obj);
     }
     iter = toForget.iterator();
     while (iter.hasNext()) {
       obj = iter.next();
       obj.forget(true);
     }
     indexByClusterIdx.remove(key);
   } else {
     ((ICFSecuritySchema) schema.getBackingStore())
         .getTableTenant()
         .deleteTenantByClusterIdx(schema.getAuthorization(), ClusterId);
   }
 }
  public void forgetTenantByClusterIdx(long ClusterId) {
    if (indexByClusterIdx == null) {
      return;
    }
    CFSecurityTenantByClusterIdxKey key =
        ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
    key.setRequiredClusterId(ClusterId);
    if (indexByClusterIdx.containsKey(key)) {
      Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(key);
      if (mapClusterIdx != null) {
        List<ICFSecurityTenantObj> toForget = new LinkedList<ICFSecurityTenantObj>();
        ICFSecurityTenantObj cur = null;
        Iterator<ICFSecurityTenantObj> iter = mapClusterIdx.values().iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          toForget.add(cur);
        }
        iter = toForget.iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          cur.forget(true);
        }
      }

      indexByClusterIdx.remove(key);
    }
  }
  public void forgetTenant(ICFSecurityTenantObj Obj, boolean forgetSubObjects) {
    ICFSecurityTenantObj obj = Obj;
    CFSecurityTenantPKey pkey = obj.getPKey();
    if (members.containsKey(pkey)) {
      ICFSecurityTenantObj keepObj = members.get(pkey);
      // Detach object from alternate, duplicate, all and PKey indexes

      if (indexByClusterIdx != null) {
        CFSecurityTenantByClusterIdxKey keyClusterIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByUNameIdx != null) {
        CFSecurityTenantByUNameIdxKey keyUNameIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey();
        keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName());
        indexByUNameIdx.remove(keyUNameIdx);
      }

      if (allTenant != null) {
        allTenant.remove(keepObj.getPKey());
      }
      members.remove(pkey);
      if (forgetSubObjects) {
        ((ICFSecuritySchemaObj) schema)
            .getTSecGroupTableObj()
            .forgetTSecGroupByTenantIdx(keepObj.getRequiredId());
      }
    }
  }
 public List<ICFSecurityTenantObj> readTenantByClusterIdx(long ClusterId, boolean forceRead) {
   final String S_ProcName = "readTenantByClusterIdx";
   CFSecurityTenantByClusterIdxKey key =
       ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
   key.setRequiredClusterId(ClusterId);
   Map<CFSecurityTenantPKey, ICFSecurityTenantObj> dict;
   if (indexByClusterIdx == null) {
     indexByClusterIdx =
         new HashMap<
             CFSecurityTenantByClusterIdxKey, Map<CFSecurityTenantPKey, ICFSecurityTenantObj>>();
   }
   if ((!forceRead) && indexByClusterIdx.containsKey(key)) {
     dict = indexByClusterIdx.get(key);
   } else {
     dict = new HashMap<CFSecurityTenantPKey, ICFSecurityTenantObj>();
     // Allow other threads to dirty-read while we're loading
     indexByClusterIdx.put(key, dict);
     ICFSecurityTenantObj obj;
     CFSecurityTenantBuff[] buffList =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableTenant()
             .readDerivedByClusterIdx(schema.getAuthorization(), ClusterId);
     CFSecurityTenantBuff buff;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = schema.getTenantTableObj().newInstance();
       obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey());
       obj.setBuff(buff);
       ICFSecurityTenantObj realized = (ICFSecurityTenantObj) obj.realize();
     }
   }
   Comparator<ICFSecurityTenantObj> cmp =
       new Comparator<ICFSecurityTenantObj>() {
         public int compare(ICFSecurityTenantObj lhs, ICFSecurityTenantObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFSecurityTenantPKey lhsPKey = lhs.getPKey();
             CFSecurityTenantPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = dict.size();
   ICFSecurityTenantObj arr[] = new ICFSecurityTenantObj[len];
   Iterator<ICFSecurityTenantObj> valIter = dict.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFSecurityTenantObj> arrayList = new ArrayList<ICFSecurityTenantObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFSecurityTenantObj> sortedList = arrayList;
   return (sortedList);
 }
  public ICFSecurityTenantObj realizeTenant(ICFSecurityTenantObj Obj) {
    ICFSecurityTenantObj obj = Obj;
    CFSecurityTenantPKey pkey = obj.getPKey();
    ICFSecurityTenantObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFSecurityTenantObj existingObj = members.get(pkey);
      keepObj = existingObj;

      /*
       *	We always rebind the data because if we're being called, some index has
       *	been updated and is refreshing it's data, which may or may not have changed
       */

      // Detach object from alternate and duplicate indexes, leave PKey alone

      if (indexByClusterIdx != null) {
        CFSecurityTenantByClusterIdxKey keyClusterIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByUNameIdx != null) {
        CFSecurityTenantByUNameIdxKey keyUNameIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey();
        keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName());
        indexByUNameIdx.remove(keyUNameIdx);
      }

      keepObj.setBuff(Obj.getBuff());
      // Attach new object to alternate and duplicate indexes -- PKey stay stable

      if (indexByClusterIdx != null) {
        CFSecurityTenantByClusterIdxKey keyClusterIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUNameIdx != null) {
        CFSecurityTenantByUNameIdxKey keyUNameIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey();
        keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
      if (allTenant != null) {
        allTenant.put(keepObj.getPKey(), keepObj);
      }
    } else {
      keepObj = obj;
      keepObj.setIsNew(false);
      // Attach new object to PKey, all, alternate, and duplicate indexes
      members.put(keepObj.getPKey(), keepObj);
      if (allTenant != null) {
        allTenant.put(keepObj.getPKey(), keepObj);
      }

      if (indexByClusterIdx != null) {
        CFSecurityTenantByClusterIdxKey keyClusterIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUNameIdx != null) {
        CFSecurityTenantByUNameIdxKey keyUNameIdx =
            ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey();
        keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
    }
    return (keepObj);
  }