public void deleteServiceByUTypeIdx(
     CFSecurityAuthorization Authorization, CFSecurityServiceByUTypeIdxKey argKey) {
   CFSecurityServiceBuff cur;
   LinkedList<CFSecurityServiceBuff> matchSet = new LinkedList<CFSecurityServiceBuff>();
   Iterator<CFSecurityServiceBuff> values = dictByPKey.values().iterator();
   while (values.hasNext()) {
     cur = values.next();
     if (argKey.equals(cur)) {
       matchSet.add(cur);
     }
   }
   Iterator<CFSecurityServiceBuff> iterMatch = matchSet.iterator();
   while (iterMatch.hasNext()) {
     cur = iterMatch.next();
     deleteService(Authorization, cur);
   }
 }
  public void updateService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) {
    CFSecurityServicePKey pkey = schema.getFactoryService().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredServiceId(Buff.getRequiredServiceId());
    CFSecurityServiceBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateService", "Existing record not found", "Service", pkey);
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "updateService", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFSecurityServiceByClusterIdxKey existingKeyClusterIdx =
        schema.getFactoryService().newClusterIdxKey();
    existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

    CFSecurityServiceByClusterIdxKey newKeyClusterIdx =
        schema.getFactoryService().newClusterIdxKey();
    newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

    CFSecurityServiceByHostIdxKey existingKeyHostIdx = schema.getFactoryService().newHostIdxKey();
    existingKeyHostIdx.setRequiredClusterId(existing.getRequiredClusterId());
    existingKeyHostIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());

    CFSecurityServiceByHostIdxKey newKeyHostIdx = schema.getFactoryService().newHostIdxKey();
    newKeyHostIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    newKeyHostIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());

    CFSecurityServiceByTypeIdxKey existingKeyTypeIdx = schema.getFactoryService().newTypeIdxKey();
    existingKeyTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

    CFSecurityServiceByTypeIdxKey newKeyTypeIdx = schema.getFactoryService().newTypeIdxKey();
    newKeyTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

    CFSecurityServiceByUTypeIdxKey existingKeyUTypeIdx =
        schema.getFactoryService().newUTypeIdxKey();
    existingKeyUTypeIdx.setRequiredClusterId(existing.getRequiredClusterId());
    existingKeyUTypeIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
    existingKeyUTypeIdx.setRequiredServiceTypeId(existing.getRequiredServiceTypeId());

    CFSecurityServiceByUTypeIdxKey newKeyUTypeIdx = schema.getFactoryService().newUTypeIdxKey();
    newKeyUTypeIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    newKeyUTypeIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
    newKeyUTypeIdx.setRequiredServiceTypeId(Buff.getRequiredServiceTypeId());

    CFSecurityServiceByUHostPortIdxKey existingKeyUHostPortIdx =
        schema.getFactoryService().newUHostPortIdxKey();
    existingKeyUHostPortIdx.setRequiredClusterId(existing.getRequiredClusterId());
    existingKeyUHostPortIdx.setRequiredHostNodeId(existing.getRequiredHostNodeId());
    existingKeyUHostPortIdx.setRequiredHostPort(existing.getRequiredHostPort());

    CFSecurityServiceByUHostPortIdxKey newKeyUHostPortIdx =
        schema.getFactoryService().newUHostPortIdxKey();
    newKeyUHostPortIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    newKeyUHostPortIdx.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
    newKeyUHostPortIdx.setRequiredHostPort(Buff.getRequiredHostPort());

    // Check unique indexes

    if (!existingKeyUTypeIdx.equals(newKeyUTypeIdx)) {
      if (dictByUTypeIdx.containsKey(newKeyUTypeIdx)) {
        throw CFLib.getDefaultExceptionFactory()
            .newUniqueIndexViolationException(
                getClass(), "updateService", "ServiceUTypeIdx", newKeyUTypeIdx);
      }
    }

    if (!existingKeyUHostPortIdx.equals(newKeyUHostPortIdx)) {
      if (dictByUHostPortIdx.containsKey(newKeyUHostPortIdx)) {
        throw CFLib.getDefaultExceptionFactory()
            .newUniqueIndexViolationException(
                getClass(), "updateService", "ServiceUHostPort", newKeyUHostPortIdx);
      }
    }

    // Validate foreign keys

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableCluster()
                .readDerivedByIdIdx(Authorization, Buff.getRequiredClusterId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), "updateService", "Owner", "ServiceCluster", "Cluster", null);
        }
      }
    }

    // Update is valid

    Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdict;

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

    subdict = dictByClusterIdx.get(existingKeyClusterIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByClusterIdx.containsKey(newKeyClusterIdx)) {
      subdict = dictByClusterIdx.get(newKeyClusterIdx);
    } else {
      subdict = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByClusterIdx.put(newKeyClusterIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByHostIdx.get(existingKeyHostIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByHostIdx.containsKey(newKeyHostIdx)) {
      subdict = dictByHostIdx.get(newKeyHostIdx);
    } else {
      subdict = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByHostIdx.put(newKeyHostIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByTypeIdx.get(existingKeyTypeIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByTypeIdx.containsKey(newKeyTypeIdx)) {
      subdict = dictByTypeIdx.get(newKeyTypeIdx);
    } else {
      subdict = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByTypeIdx.put(newKeyTypeIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByUTypeIdx.remove(existingKeyUTypeIdx);
    dictByUTypeIdx.put(newKeyUTypeIdx, Buff);

    dictByUHostPortIdx.remove(existingKeyUHostPortIdx);
    dictByUHostPortIdx.put(newKeyUHostPortIdx, Buff);
  }