public ICFSecurityTenantObj readTenantByUNameIdx(
     long ClusterId, String TenantName, boolean forceRead) {
   if (indexByUNameIdx == null) {
     indexByUNameIdx = new HashMap<CFSecurityTenantByUNameIdxKey, ICFSecurityTenantObj>();
   }
   CFSecurityTenantByUNameIdxKey key =
       ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey();
   key.setRequiredClusterId(ClusterId);
   key.setRequiredTenantName(TenantName);
   ICFSecurityTenantObj obj = null;
   if ((!forceRead) && indexByUNameIdx.containsKey(key)) {
     obj = indexByUNameIdx.get(key);
   } else {
     CFSecurityTenantBuff buff =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableTenant()
             .readDerivedByUNameIdx(schema.getAuthorization(), ClusterId, TenantName);
     if (buff != null) {
       obj = schema.getTenantTableObj().newInstance();
       obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey());
       obj.setBuff(buff);
       obj = (ICFSecurityTenantObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByUNameIdx.put(key, null);
     }
   }
   return (obj);
 }
 public ICFSecurityTenantObj lockTenant(CFSecurityTenantPKey pkey) {
   ICFSecurityTenantObj locked = null;
   CFSecurityTenantBuff lockBuff =
       ((ICFSecuritySchema) schema.getBackingStore())
           .getTableTenant()
           .lockDerived(schema.getAuthorization(), pkey);
   if (lockBuff != null) {
     locked = schema.getTenantTableObj().newInstance();
     locked.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey());
     locked.setBuff(lockBuff);
     locked = (ICFSecurityTenantObj) locked.realize();
   } else {
     throw CFLib.getDefaultExceptionFactory()
         .newCollisionDetectedException(getClass(), "lockTenant", pkey);
   }
   return (locked);
 }
 public ICFSecurityTenantObj readTenant(CFSecurityTenantPKey pkey, boolean forceRead) {
   ICFSecurityTenantObj obj = null;
   if ((!forceRead) && members.containsKey(pkey)) {
     obj = members.get(pkey);
   } else {
     CFSecurityTenantBuff readBuff =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableTenant()
             .readDerivedByIdIdx(schema.getAuthorization(), pkey.getRequiredId());
     if (readBuff != null) {
       obj = schema.getTenantTableObj().newInstance();
       obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey());
       obj.setBuff(readBuff);
       obj = (ICFSecurityTenantObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       members.put(pkey, null);
     }
   }
   return (obj);
 }
 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 List<ICFSecurityTenantObj> readAllTenant(boolean forceRead) {
   final String S_ProcName = "readAllTenant";
   if ((allTenant == null) || forceRead) {
     Map<CFSecurityTenantPKey, ICFSecurityTenantObj> map =
         new HashMap<CFSecurityTenantPKey, ICFSecurityTenantObj>();
     allTenant = map;
     CFSecurityTenantBuff[] buffList =
         ((ICFSecuritySchema) schema.getBackingStore())
             .getTableTenant()
             .readAllDerived(schema.getAuthorization());
     CFSecurityTenantBuff buff;
     ICFSecurityTenantObj obj;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = 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 = allTenant.size();
   ICFSecurityTenantObj arr[] = new ICFSecurityTenantObj[len];
   Iterator<ICFSecurityTenantObj> valIter = allTenant.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);
  }