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);
  }