public ICFAccTaxObj readTaxByUNameIdx(long TenantId, String Name, boolean forceRead) {
   if (indexByUNameIdx == null) {
     indexByUNameIdx = new HashMap<CFAccTaxByUNameIdxKey, ICFAccTaxObj>();
   }
   CFAccTaxByUNameIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
   key.setRequiredTenantId(TenantId);
   key.setRequiredName(Name);
   ICFAccTaxObj obj = null;
   if ((!forceRead) && indexByUNameIdx.containsKey(key)) {
     obj = indexByUNameIdx.get(key);
   } else {
     CFAccTaxBuff buff =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readDerivedByUNameIdx(schema.getAuthorization(), TenantId, Name);
     if (buff != null) {
       obj = schema.getTaxTableObj().newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       obj = (ICFAccTaxObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByUNameIdx.put(key, null);
     }
   }
   return (obj);
 }
  public void forgetServiceType(ICFSecurityServiceTypeObj Obj, boolean forgetSubObjects) {
    ICFSecurityServiceTypeObj obj = Obj;
    CFSecurityServiceTypePKey pkey = obj.getPKey();
    if (members.containsKey(pkey)) {
      ICFSecurityServiceTypeObj keepObj = members.get(pkey);
      // Detach object from alternate, duplicate, all and PKey indexes

      if (indexByUDescrIdx != null) {
        CFSecurityServiceTypeByUDescrIdxKey keyUDescrIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription());
        indexByUDescrIdx.remove(keyUDescrIdx);
      }

      if (allServiceType != null) {
        allServiceType.remove(keepObj.getPKey());
      }
      members.remove(pkey);
      if (forgetSubObjects) {
        ((ICFSecuritySchemaObj) schema)
            .getServiceTableObj()
            .forgetServiceByTypeIdx(keepObj.getRequiredServiceTypeId());
      }
    }
  }
 public List<ICFAccTaxObj> readAllTax(boolean forceRead) {
   final String S_ProcName = "readAllTax";
   if ((allTax == null) || forceRead) {
     Map<CFAccTaxPKey, ICFAccTaxObj> map = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     allTax = map;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readAllDerived(schema.getAuthorization());
     CFAccTaxBuff buff;
     ICFAccTaxObj obj;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = allTax.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> valIter = allTax.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<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }
 public void deleteTaxByTenantIdx(long TenantId) {
   CFAccTaxByTenantIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
   key.setRequiredTenantId(TenantId);
   if (indexByTenantIdx == null) {
     indexByTenantIdx = new HashMap<CFAccTaxByTenantIdxKey, Map<CFAccTaxPKey, ICFAccTaxObj>>();
   }
   if (indexByTenantIdx.containsKey(key)) {
     Map<CFAccTaxPKey, ICFAccTaxObj> dict = indexByTenantIdx.get(key);
     ((ICFAccSchema) schema.getBackingStore())
         .getTableTax()
         .deleteTaxByTenantIdx(schema.getAuthorization(), TenantId);
     Iterator<ICFAccTaxObj> iter = dict.values().iterator();
     ICFAccTaxObj obj;
     List<ICFAccTaxObj> toForget = new LinkedList<ICFAccTaxObj>();
     while (iter.hasNext()) {
       obj = iter.next();
       toForget.add(obj);
     }
     iter = toForget.iterator();
     while (iter.hasNext()) {
       obj = iter.next();
       obj.forget(true);
     }
     indexByTenantIdx.remove(key);
   } else {
     ((ICFAccSchema) schema.getBackingStore())
         .getTableTax()
         .deleteTaxByTenantIdx(schema.getAuthorization(), TenantId);
   }
 }
 public ICFSecurityServiceTypeObj readServiceTypeByUDescrIdx(
     String Description, boolean forceRead) {
   if (indexByUDescrIdx == null) {
     indexByUDescrIdx =
         new HashMap<CFSecurityServiceTypeByUDescrIdxKey, ICFSecurityServiceTypeObj>();
   }
   CFSecurityServiceTypeByUDescrIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
   key.setRequiredDescription(Description);
   ICFSecurityServiceTypeObj obj = null;
   if ((!forceRead) && indexByUDescrIdx.containsKey(key)) {
     obj = indexByUDescrIdx.get(key);
   } else {
     CFSecurityServiceTypeBuff buff =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableServiceType()
             .readDerivedByUDescrIdx(schema.getAuthorization(), Description);
     if (buff != null) {
       obj = schema.getServiceTypeTableObj().newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newPKey());
       obj.setBuff(buff);
       obj = (ICFSecurityServiceTypeObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByUDescrIdx.put(key, null);
     }
   }
   return (obj);
 }
  public void forgetTaxByTenantIdx(long TenantId) {
    if (indexByTenantIdx == null) {
      return;
    }
    CFAccTaxByTenantIdxKey key =
        ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
    key.setRequiredTenantId(TenantId);
    if (indexByTenantIdx.containsKey(key)) {
      Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(key);
      if (mapTenantIdx != null) {
        List<ICFAccTaxObj> toForget = new LinkedList<ICFAccTaxObj>();
        ICFAccTaxObj cur = null;
        Iterator<ICFAccTaxObj> iter = mapTenantIdx.values().iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          toForget.add(cur);
        }
        iter = toForget.iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          cur.forget(true);
        }
      }

      indexByTenantIdx.remove(key);
    }
  }
 public CFAccFeeBuff[] readAllDerived(CFSecurityAuthorization Authorization) {
   final String S_ProcName = "CFAccRamFee.readAllDerived";
   CFAccFeeBuff[] retList = new CFAccFeeBuff[dictByPKey.values().size()];
   Iterator<CFAccFeeBuff> iter = dictByPKey.values().iterator();
   int idx = 0;
   while (iter.hasNext()) {
     retList[idx++] = iter.next();
   }
   return (retList);
 }
 public void forgetTaxByIdIdx(long TaxId) {
   if (members == null) {
     return;
   }
   CFAccTaxPKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey();
   key.setRequiredTaxId(TaxId);
   if (members.containsKey(key)) {
     ICFAccTaxObj probed = members.get(key);
     if (probed != null) {
       probed.forget(true);
     }
   }
 }
 public CFAccFeeBuff lockDerived(CFSecurityAuthorization Authorization, CFAccFeePKey PKey) {
   final String S_ProcName = "CFAccRamFee.readDerived";
   CFAccFeePKey key = schema.getFactoryFee().newPKey();
   key.setRequiredTenantId(PKey.getRequiredTenantId());
   key.setRequiredFeeId(PKey.getRequiredFeeId());
   CFAccFeeBuff buff;
   if (dictByPKey.containsKey(key)) {
     buff = dictByPKey.get(key);
   } else {
     buff = null;
   }
   return (buff);
 }
 public void forgetServiceTypeByIdIdx(int ServiceTypeId) {
   if (members == null) {
     return;
   }
   CFSecurityServiceTypePKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newPKey();
   key.setRequiredServiceTypeId(ServiceTypeId);
   if (members.containsKey(key)) {
     ICFSecurityServiceTypeObj probed = members.get(key);
     if (probed != null) {
       probed.forget(true);
     }
   }
 }
  public CFSecurityCursor openFeeCursorByTenantIdx(
      CFSecurityAuthorization Authorization, long TenantId) {
    CFSecurityCursor cursor;
    CFAccFeeByTenantIdxKey key = schema.getFactoryFee().newTenantIdxKey();
    key.setRequiredTenantId(TenantId);

    if (dictByTenantIdx.containsKey(key)) {
      Map<CFAccFeePKey, CFAccFeeBuff> subdictTenantIdx = dictByTenantIdx.get(key);
      cursor = new CFAccRamFeeCursor(Authorization, schema, subdictTenantIdx.values());
    } else {
      cursor = new CFAccRamFeeCursor(Authorization, schema, new ArrayList<CFAccFeeBuff>());
    }
    return (cursor);
  }
  public void forgetServiceTypeByUDescrIdx(String Description) {
    if (indexByUDescrIdx == null) {
      return;
    }
    CFSecurityServiceTypeByUDescrIdxKey key =
        ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
    key.setRequiredDescription(Description);
    if (indexByUDescrIdx.containsKey(key)) {
      ICFSecurityServiceTypeObj probed = indexByUDescrIdx.get(key);
      if (probed != null) {
        probed.forget(true);
      }

      indexByUDescrIdx.remove(key);
    }
  }
  public void forgetTaxByUNameIdx(long TenantId, String Name) {
    if (indexByUNameIdx == null) {
      return;
    }
    CFAccTaxByUNameIdxKey key =
        ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
    key.setRequiredTenantId(TenantId);
    key.setRequiredName(Name);
    if (indexByUNameIdx.containsKey(key)) {
      ICFAccTaxObj probed = indexByUNameIdx.get(key);
      if (probed != null) {
        probed.forget(true);
      }

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

      if (indexByTenantIdx != null) {
        CFAccTaxByTenantIdxKey keyTenantIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx);
        if (mapTenantIdx != null) {
          mapTenantIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByUNameIdx != null) {
        CFAccTaxByUNameIdxKey keyUNameIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.remove(keyUNameIdx);
      }

      if (allTax != null) {
        allTax.remove(keepObj.getPKey());
      }
      members.remove(pkey);
      if (forgetSubObjects) {}
    }
  }
  public ICFSecurityServiceTypeObj realizeServiceType(ICFSecurityServiceTypeObj Obj) {
    ICFSecurityServiceTypeObj obj = Obj;
    CFSecurityServiceTypePKey pkey = obj.getPKey();
    ICFSecurityServiceTypeObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFSecurityServiceTypeObj 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 (indexByUDescrIdx != null) {
        CFSecurityServiceTypeByUDescrIdxKey keyUDescrIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription());
        indexByUDescrIdx.remove(keyUDescrIdx);
      }

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

      if (indexByUDescrIdx != null) {
        CFSecurityServiceTypeByUDescrIdxKey keyUDescrIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription());
        indexByUDescrIdx.put(keyUDescrIdx, keepObj);
      }
      if (allServiceType != null) {
        allServiceType.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 (allServiceType != null) {
        allServiceType.put(keepObj.getPKey(), keepObj);
      }

      if (indexByUDescrIdx != null) {
        CFSecurityServiceTypeByUDescrIdxKey keyUDescrIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
        keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription());
        indexByUDescrIdx.put(keyUDescrIdx, keepObj);
      }
    }
    return (keepObj);
  }
 public ICFAccTaxObj readTax(CFAccTaxPKey pkey, boolean forceRead) {
   ICFAccTaxObj obj = null;
   if ((!forceRead) && members.containsKey(pkey)) {
     obj = members.get(pkey);
   } else {
     CFAccTaxBuff readBuff =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readDerivedByIdIdx(schema.getAuthorization(), pkey.getRequiredTaxId());
     if (readBuff != null) {
       obj = schema.getTaxTableObj().newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(readBuff);
       obj = (ICFAccTaxObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       members.put(pkey, null);
     }
   }
   return (obj);
 }
 public void deleteServiceTypeByUDescrIdx(String Description) {
   if (indexByUDescrIdx == null) {
     indexByUDescrIdx =
         new HashMap<CFSecurityServiceTypeByUDescrIdxKey, ICFSecurityServiceTypeObj>();
   }
   CFSecurityServiceTypeByUDescrIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryServiceType().newUDescrIdxKey();
   key.setRequiredDescription(Description);
   ICFSecurityServiceTypeObj obj = null;
   if (indexByUDescrIdx.containsKey(key)) {
     obj = indexByUDescrIdx.get(key);
     ((ICFAccSchema) schema.getBackingStore())
         .getTableServiceType()
         .deleteServiceTypeByUDescrIdx(schema.getAuthorization(), Description);
     obj.forget(true);
   } else {
     ((ICFAccSchema) schema.getBackingStore())
         .getTableServiceType()
         .deleteServiceTypeByUDescrIdx(schema.getAuthorization(), Description);
   }
 }
 public void deleteTaxByUNameIdx(long TenantId, String Name) {
   if (indexByUNameIdx == null) {
     indexByUNameIdx = new HashMap<CFAccTaxByUNameIdxKey, ICFAccTaxObj>();
   }
   CFAccTaxByUNameIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
   key.setRequiredTenantId(TenantId);
   key.setRequiredName(Name);
   ICFAccTaxObj obj = null;
   if (indexByUNameIdx.containsKey(key)) {
     obj = indexByUNameIdx.get(key);
     ((ICFAccSchema) schema.getBackingStore())
         .getTableTax()
         .deleteTaxByUNameIdx(schema.getAuthorization(), TenantId, Name);
     obj.forget(true);
   } else {
     ((ICFAccSchema) schema.getBackingStore())
         .getTableTax()
         .deleteTaxByUNameIdx(schema.getAuthorization(), TenantId, Name);
   }
 }
  public CFAccFeeBuff[] readDerivedByTenantIdx(
      CFSecurityAuthorization Authorization, long TenantId) {
    final String S_ProcName = "CFAccRamFee.readDerivedByTenantIdx";
    CFAccFeeByTenantIdxKey key = schema.getFactoryFee().newTenantIdxKey();
    key.setRequiredTenantId(TenantId);

    CFAccFeeBuff[] recArray;
    if (dictByTenantIdx.containsKey(key)) {
      Map<CFAccFeePKey, CFAccFeeBuff> subdictTenantIdx = dictByTenantIdx.get(key);
      recArray = new CFAccFeeBuff[subdictTenantIdx.size()];
      Iterator<CFAccFeeBuff> iter = subdictTenantIdx.values().iterator();
      int idx = 0;
      while (iter.hasNext()) {
        recArray[idx++] = iter.next();
      }
    } else {
      Map<CFAccFeePKey, CFAccFeeBuff> subdictTenantIdx = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByTenantIdx.put(key, subdictTenantIdx);
      recArray = new CFAccFeeBuff[0];
    }
    return (recArray);
  }
  public void deleteFee(CFSecurityAuthorization Authorization, CFAccFeeBuff Buff) {
    final String S_ProcName = "CFAccRamFeeTable.deleteFee() ";
    CFAccFeePKey pkey = schema.getFactoryFee().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredFeeId(Buff.getRequiredFeeId());
    CFAccFeeBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteFee", pkey);
    }
    CFAccFeeByDateIdxKey keyDateIdx = schema.getFactoryFee().newDateIdxKey();
    keyDateIdx.setRequiredTenantId(existing.getRequiredTenantId());
    keyDateIdx.setRequiredAccountId(existing.getRequiredAccountId());
    keyDateIdx.setRequiredFeeDate(existing.getRequiredFeeDate());

    CFAccFeeByTenantIdxKey keyTenantIdx = schema.getFactoryFee().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

    CFAccFeeByAcctIdxKey keyAcctIdx = schema.getFactoryFee().newAcctIdxKey();
    keyAcctIdx.setRequiredTenantId(existing.getRequiredTenantId());
    keyAcctIdx.setRequiredAccountId(existing.getRequiredAccountId());

    CFAccFeeByLedgerIdxKey keyLedgerIdx = schema.getFactoryFee().newLedgerIdxKey();
    keyLedgerIdx.setOptionalLedgerTenantId(existing.getOptionalLedgerTenantId());
    keyLedgerIdx.setOptionalLedgerId(existing.getOptionalLedgerId());

    // Validate reverse foreign keys

    // Delete is valid

    schema
        .getTableFeeDetail()
        .deleteFeeDetailByFeeIdx(
            Authorization, Buff.getRequiredTenantId(), Buff.getRequiredFeeId());
    Map<CFAccFeePKey, CFAccFeeBuff> subdict;

    dictByPKey.remove(pkey);

    subdict = dictByDateIdx.get(keyDateIdx);
    subdict.remove(pkey);

    subdict = dictByTenantIdx.get(keyTenantIdx);
    subdict.remove(pkey);

    subdict = dictByAcctIdx.get(keyAcctIdx);
    subdict.remove(pkey);

    subdict = dictByLedgerIdx.get(keyLedgerIdx);
    subdict.remove(pkey);
  }
 public void minimizeMemory() {
   allServiceType = null;
   indexByUDescrIdx = null;
   List<ICFSecurityServiceTypeObj> toForget = new LinkedList<ICFSecurityServiceTypeObj>();
   ICFSecurityServiceTypeObj cur = null;
   Iterator<ICFSecurityServiceTypeObj> iter = members.values().iterator();
   while (iter.hasNext()) {
     cur = iter.next();
     toForget.add(cur);
   }
   iter = toForget.iterator();
   while (iter.hasNext()) {
     cur = iter.next();
     cur.forget();
   }
 }
 public void deleteFeeByIdIdx(CFSecurityAuthorization Authorization, CFAccFeePKey argKey) {
   CFAccFeeBuff cur;
   LinkedList<CFAccFeeBuff> matchSet = new LinkedList<CFAccFeeBuff>();
   Iterator<CFAccFeeBuff> values = dictByPKey.values().iterator();
   while (values.hasNext()) {
     cur = values.next();
     if (argKey.equals(cur)) {
       matchSet.add(cur);
     }
   }
   Iterator<CFAccFeeBuff> iterMatch = matchSet.iterator();
   while (iterMatch.hasNext()) {
     cur = iterMatch.next();
     deleteFee(Authorization, cur);
   }
 }
 public void minimizeMemory() {
   allTax = null;
   indexByTenantIdx = null;
   indexByUNameIdx = null;
   List<ICFAccTaxObj> toForget = new LinkedList<ICFAccTaxObj>();
   ICFAccTaxObj cur = null;
   Iterator<ICFAccTaxObj> iter = members.values().iterator();
   while (iter.hasNext()) {
     cur = iter.next();
     toForget.add(cur);
   }
   iter = toForget.iterator();
   while (iter.hasNext()) {
     cur = iter.next();
     cur.forget();
   }
 }
 public CFSecurityCursor openFeeCursorAll(CFSecurityAuthorization Authorization) {
   CFSecurityCursor cursor = new CFAccRamFeeCursor(Authorization, schema, dictByPKey.values());
   return (cursor);
 }
  public void updateFee(CFSecurityAuthorization Authorization, CFAccFeeBuff Buff) {
    CFAccFeePKey pkey = schema.getFactoryFee().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredFeeId(Buff.getRequiredFeeId());
    CFAccFeeBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateFee", "Existing record not found", "Fee", pkey);
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "updateFee", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFAccFeeByDateIdxKey existingKeyDateIdx = schema.getFactoryFee().newDateIdxKey();
    existingKeyDateIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyDateIdx.setRequiredAccountId(existing.getRequiredAccountId());
    existingKeyDateIdx.setRequiredFeeDate(existing.getRequiredFeeDate());

    CFAccFeeByDateIdxKey newKeyDateIdx = schema.getFactoryFee().newDateIdxKey();
    newKeyDateIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyDateIdx.setRequiredAccountId(Buff.getRequiredAccountId());
    newKeyDateIdx.setRequiredFeeDate(Buff.getRequiredFeeDate());

    CFAccFeeByTenantIdxKey existingKeyTenantIdx = schema.getFactoryFee().newTenantIdxKey();
    existingKeyTenantIdx.setRequiredTenantId(existing.getRequiredTenantId());

    CFAccFeeByTenantIdxKey newKeyTenantIdx = schema.getFactoryFee().newTenantIdxKey();
    newKeyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    CFAccFeeByAcctIdxKey existingKeyAcctIdx = schema.getFactoryFee().newAcctIdxKey();
    existingKeyAcctIdx.setRequiredTenantId(existing.getRequiredTenantId());
    existingKeyAcctIdx.setRequiredAccountId(existing.getRequiredAccountId());

    CFAccFeeByAcctIdxKey newKeyAcctIdx = schema.getFactoryFee().newAcctIdxKey();
    newKeyAcctIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    newKeyAcctIdx.setRequiredAccountId(Buff.getRequiredAccountId());

    CFAccFeeByLedgerIdxKey existingKeyLedgerIdx = schema.getFactoryFee().newLedgerIdxKey();
    existingKeyLedgerIdx.setOptionalLedgerTenantId(existing.getOptionalLedgerTenantId());
    existingKeyLedgerIdx.setOptionalLedgerId(existing.getOptionalLedgerId());

    CFAccFeeByLedgerIdxKey newKeyLedgerIdx = schema.getFactoryFee().newLedgerIdxKey();
    newKeyLedgerIdx.setOptionalLedgerTenantId(Buff.getOptionalLedgerTenantId());
    newKeyLedgerIdx.setOptionalLedgerId(Buff.getOptionalLedgerId());

    // Check unique indexes

    // Validate foreign keys

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableAccount()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredTenantId(), Buff.getRequiredAccountId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), "updateFee", "Container", "Account", "Account", null);
        }
      }
    }

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableTenant()
                .readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), "updateFee", "Owner", "Tenant", "Tenant", null);
        }
      }
    }

    // Update is valid

    Map<CFAccFeePKey, CFAccFeeBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);

    subdict = dictByDateIdx.get(existingKeyDateIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByDateIdx.containsKey(newKeyDateIdx)) {
      subdict = dictByDateIdx.get(newKeyDateIdx);
    } else {
      subdict = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByDateIdx.put(newKeyDateIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByTenantIdx.get(existingKeyTenantIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByTenantIdx.containsKey(newKeyTenantIdx)) {
      subdict = dictByTenantIdx.get(newKeyTenantIdx);
    } else {
      subdict = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByTenantIdx.put(newKeyTenantIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByAcctIdx.get(existingKeyAcctIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByAcctIdx.containsKey(newKeyAcctIdx)) {
      subdict = dictByAcctIdx.get(newKeyAcctIdx);
    } else {
      subdict = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByAcctIdx.put(newKeyAcctIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByLedgerIdx.get(existingKeyLedgerIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByLedgerIdx.containsKey(newKeyLedgerIdx)) {
      subdict = dictByLedgerIdx.get(newKeyLedgerIdx);
    } else {
      subdict = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByLedgerIdx.put(newKeyLedgerIdx, subdict);
    }
    subdict.put(pkey, Buff);
  }
  public ICFAccTaxObj realizeTax(ICFAccTaxObj Obj) {
    ICFAccTaxObj obj = Obj;
    CFAccTaxPKey pkey = obj.getPKey();
    ICFAccTaxObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFAccTaxObj 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 (indexByTenantIdx != null) {
        CFAccTaxByTenantIdxKey keyTenantIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx);
        if (mapTenantIdx != null) {
          mapTenantIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByUNameIdx != null) {
        CFAccTaxByUNameIdxKey keyUNameIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.remove(keyUNameIdx);
      }

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

      if (indexByTenantIdx != null) {
        CFAccTaxByTenantIdxKey keyTenantIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx);
        if (mapTenantIdx != null) {
          mapTenantIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUNameIdx != null) {
        CFAccTaxByUNameIdxKey keyUNameIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
      if (allTax != null) {
        allTax.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 (allTax != null) {
        allTax.put(keepObj.getPKey(), keepObj);
      }

      if (indexByTenantIdx != null) {
        CFAccTaxByTenantIdxKey keyTenantIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
        keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        Map<CFAccTaxPKey, ICFAccTaxObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx);
        if (mapTenantIdx != null) {
          mapTenantIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUNameIdx != null) {
        CFAccTaxByUNameIdxKey keyUNameIdx =
            ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newUNameIdxKey();
        keyUNameIdx.setRequiredTenantId(keepObj.getRequiredTenantId());
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
    }
    return (keepObj);
  }
  public void createFee(CFSecurityAuthorization Authorization, CFAccFeeBuff Buff) {
    final String S_ProcName = "createFee";
    CFAccFeePKey pkey = schema.getFactoryFee().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredFeeId(
        ((CFAccRamTenantTable) schema.getTableTenant())
            .nextFeeIdGen(Authorization, Buff.getRequiredTenantId()));
    Buff.setRequiredTenantId(pkey.getRequiredTenantId());
    Buff.setRequiredFeeId(pkey.getRequiredFeeId());
    CFAccFeeByDateIdxKey keyDateIdx = schema.getFactoryFee().newDateIdxKey();
    keyDateIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    keyDateIdx.setRequiredAccountId(Buff.getRequiredAccountId());
    keyDateIdx.setRequiredFeeDate(Buff.getRequiredFeeDate());

    CFAccFeeByTenantIdxKey keyTenantIdx = schema.getFactoryFee().newTenantIdxKey();
    keyTenantIdx.setRequiredTenantId(Buff.getRequiredTenantId());

    CFAccFeeByAcctIdxKey keyAcctIdx = schema.getFactoryFee().newAcctIdxKey();
    keyAcctIdx.setRequiredTenantId(Buff.getRequiredTenantId());
    keyAcctIdx.setRequiredAccountId(Buff.getRequiredAccountId());

    CFAccFeeByLedgerIdxKey keyLedgerIdx = schema.getFactoryFee().newLedgerIdxKey();
    keyLedgerIdx.setOptionalLedgerTenantId(Buff.getOptionalLedgerTenantId());
    keyLedgerIdx.setOptionalLedgerId(Buff.getOptionalLedgerId());

    // Validate unique indexes

    if (dictByPKey.containsKey(pkey)) {
      throw CFLib.getDefaultExceptionFactory()
          .newPrimaryKeyNotNewException(getClass(), S_ProcName, pkey);
    }

    // Validate foreign keys

    {
      boolean allNull = true;
      allNull = false;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableAccount()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredTenantId(), Buff.getRequiredAccountId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Container", "Account", "Account", null);
        }
      }
    }

    {
      boolean allNull = true;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableTenant()
                .readDerivedByIdIdx(Authorization, Buff.getRequiredTenantId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Owner", "Tenant", "Tenant", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    Map<CFAccFeePKey, CFAccFeeBuff> subdictDateIdx;
    if (dictByDateIdx.containsKey(keyDateIdx)) {
      subdictDateIdx = dictByDateIdx.get(keyDateIdx);
    } else {
      subdictDateIdx = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByDateIdx.put(keyDateIdx, subdictDateIdx);
    }
    subdictDateIdx.put(pkey, Buff);

    Map<CFAccFeePKey, CFAccFeeBuff> subdictTenantIdx;
    if (dictByTenantIdx.containsKey(keyTenantIdx)) {
      subdictTenantIdx = dictByTenantIdx.get(keyTenantIdx);
    } else {
      subdictTenantIdx = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByTenantIdx.put(keyTenantIdx, subdictTenantIdx);
    }
    subdictTenantIdx.put(pkey, Buff);

    Map<CFAccFeePKey, CFAccFeeBuff> subdictAcctIdx;
    if (dictByAcctIdx.containsKey(keyAcctIdx)) {
      subdictAcctIdx = dictByAcctIdx.get(keyAcctIdx);
    } else {
      subdictAcctIdx = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByAcctIdx.put(keyAcctIdx, subdictAcctIdx);
    }
    subdictAcctIdx.put(pkey, Buff);

    Map<CFAccFeePKey, CFAccFeeBuff> subdictLedgerIdx;
    if (dictByLedgerIdx.containsKey(keyLedgerIdx)) {
      subdictLedgerIdx = dictByLedgerIdx.get(keyLedgerIdx);
    } else {
      subdictLedgerIdx = new HashMap<CFAccFeePKey, CFAccFeeBuff>();
      dictByLedgerIdx.put(keyLedgerIdx, subdictLedgerIdx);
    }
    subdictLedgerIdx.put(pkey, Buff);
  }
 public List<ICFAccTaxObj> readTaxByTenantIdx(long TenantId, boolean forceRead) {
   final String S_ProcName = "readTaxByTenantIdx";
   CFAccTaxByTenantIdxKey key =
       ((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newTenantIdxKey();
   key.setRequiredTenantId(TenantId);
   Map<CFAccTaxPKey, ICFAccTaxObj> dict;
   if (indexByTenantIdx == null) {
     indexByTenantIdx = new HashMap<CFAccTaxByTenantIdxKey, Map<CFAccTaxPKey, ICFAccTaxObj>>();
   }
   if ((!forceRead) && indexByTenantIdx.containsKey(key)) {
     dict = indexByTenantIdx.get(key);
   } else {
     dict = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     // Allow other threads to dirty-read while we're loading
     indexByTenantIdx.put(key, dict);
     ICFAccTaxObj obj;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readDerivedByTenantIdx(schema.getAuthorization(), TenantId);
     CFAccTaxBuff buff;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = schema.getTaxTableObj().newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = dict.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> 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<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }