public void deleteUuidDefByContPrevIdx(
     CFSecurityAuthorization Authorization, CFBamValueByContPrevIdxKey argKey) {
   final String S_ProcName = "deleteUuidDefByContPrevIdx";
   CFBamUuidDefBuff cur;
   LinkedList<CFBamUuidDefBuff> matchSet = new LinkedList<CFBamUuidDefBuff>();
   Iterator<CFBamUuidDefBuff> values = dictByPKey.values().iterator();
   while (values.hasNext()) {
     cur = values.next();
     if (argKey.equals(cur)) {
       matchSet.add(cur);
     }
   }
   Iterator<CFBamUuidDefBuff> iterMatch = matchSet.iterator();
   while (iterMatch.hasNext()) {
     cur = iterMatch.next();
     String subClassCode = cur.getClassCode();
     if ("UIDD".equals(subClassCode)) {
       schema.getTableUuidDef().deleteUuidDef(Authorization, cur);
     } else if ("UIDC".equals(subClassCode)) {
       schema.getTableUuidCol().deleteUuidCol(Authorization, (CFBamUuidColBuff) cur);
     } else if ("UIDT".equals(subClassCode)) {
       schema.getTableUuidType().deleteUuidType(Authorization, (CFBamUuidTypeBuff) cur);
     } else if ("IGUU".equals(subClassCode)) {
       schema.getTableUuidGen().deleteUuidGen(Authorization, (CFBamUuidGenBuff) cur);
     } else {
       throw CFLib.getDefaultExceptionFactory()
           .newUnsupportedClassException(
               getClass(),
               S_ProcName,
               "subClassCode",
               cur,
               "Instance of or subclass of UuidDef must not be \"" + subClassCode + "\"");
     }
   }
 }
 public void deleteUuidDefByNextIdx(
     CFSecurityAuthorization Authorization, Long argNextTenantId, Long argNextId) {
   CFBamValueByNextIdxKey key = schema.getFactoryValue().newNextIdxKey();
   key.setOptionalNextTenantId(argNextTenantId);
   key.setOptionalNextId(argNextId);
   deleteUuidDefByNextIdx(Authorization, key);
 }
 public void deleteUuidDefByScopeIdx(
     CFSecurityAuthorization Authorization, long argTenantId, long argScopeId) {
   CFBamValueByScopeIdxKey key = schema.getFactoryValue().newScopeIdxKey();
   key.setRequiredTenantId(argTenantId);
   key.setRequiredScopeId(argScopeId);
   deleteUuidDefByScopeIdx(Authorization, key);
 }
 public void deleteServiceByHostIdx(
     CFSecurityAuthorization Authorization, long argClusterId, long argHostNodeId) {
   CFSecurityServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
   key.setRequiredClusterId(argClusterId);
   key.setRequiredHostNodeId(argHostNodeId);
   deleteServiceByHostIdx(Authorization, key);
 }
 public void deleteHostNodeByHostNameIdx(
     CFSecurityAuthorization Authorization, long argClusterId, String argHostName) {
   CFSecurityHostNodeByHostNameIdxKey key = schema.getFactoryHostNode().newHostNameIdxKey();
   key.setRequiredClusterId(argClusterId);
   key.setRequiredHostName(argHostName);
   deleteHostNodeByHostNameIdx(Authorization, key);
 }
 public void deleteHostNodeByUDescrIdx(
     CFSecurityAuthorization Authorization, long argClusterId, String argDescription) {
   CFSecurityHostNodeByUDescrIdxKey key = schema.getFactoryHostNode().newUDescrIdxKey();
   key.setRequiredClusterId(argClusterId);
   key.setRequiredDescription(argDescription);
   deleteHostNodeByUDescrIdx(Authorization, key);
 }
 public void deleteUuidDefByVAccSecIdx(
     CFSecurityAuthorization Authorization,
     ICFBamSchema.AccessSecurityEnum argViewAccessSecurity) {
   CFBamValueByVAccSecIdxKey key = schema.getFactoryValue().newVAccSecIdxKey();
   key.setOptionalViewAccessSecurity(argViewAccessSecurity);
   deleteUuidDefByVAccSecIdx(Authorization, key);
 }
  public void deleteHostNode(CFSecurityAuthorization Authorization, CFSecurityHostNodeBuff Buff) {
    final String S_ProcName = "CFBamRamHostNodeTable.deleteHostNode() ";
    CFSecurityHostNodePKey pkey = schema.getFactoryHostNode().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredHostNodeId(Buff.getRequiredHostNodeId());
    CFSecurityHostNodeBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteHostNode", pkey);
    }
    CFSecurityHostNodeByClusterIdxKey keyClusterIdx =
        schema.getFactoryHostNode().newClusterIdxKey();
    keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

    CFSecurityHostNodeByUDescrIdxKey keyUDescrIdx = schema.getFactoryHostNode().newUDescrIdxKey();
    keyUDescrIdx.setRequiredClusterId(existing.getRequiredClusterId());
    keyUDescrIdx.setRequiredDescription(existing.getRequiredDescription());

    CFSecurityHostNodeByHostNameIdxKey keyHostNameIdx =
        schema.getFactoryHostNode().newHostNameIdxKey();
    keyHostNameIdx.setRequiredClusterId(existing.getRequiredClusterId());
    keyHostNameIdx.setRequiredHostName(existing.getRequiredHostName());

    // Validate reverse foreign keys

    // Delete is valid

    schema
        .getTableService()
        .deleteServiceByHostIdx(
            Authorization, Buff.getRequiredClusterId(), Buff.getRequiredHostNodeId());
    Map<CFSecurityHostNodePKey, CFSecurityHostNodeBuff> subdict;

    dictByPKey.remove(pkey);

    subdict = dictByClusterIdx.get(keyClusterIdx);
    subdict.remove(pkey);

    dictByUDescrIdx.remove(keyUDescrIdx);

    dictByHostNameIdx.remove(keyHostNameIdx);
  }
  public void deleteUuidDef(CFSecurityAuthorization Authorization, CFBamUuidDefBuff Buff) {
    final String S_ProcName = "CFBamRamUuidDefTable.deleteUuidDef() ";
    CFBamValuePKey pkey = schema.getFactoryValue().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFBamUuidDefBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteUuidDef", pkey);
    }

    // Validate reverse foreign keys

    if (schema
            .getTableUuidCol()
            .readDerivedByIdIdx(
                Authorization, existing.getRequiredTenantId(), existing.getRequiredId())
        != null) {
      throw CFLib.getDefaultExceptionFactory()
          .newDependentsDetectedException(
              getClass(), "deleteUuidDef", "Superclass", "SuperClass", "UuidCol", pkey);
    }

    if (schema
            .getTableUuidType()
            .readDerivedByIdIdx(
                Authorization, existing.getRequiredTenantId(), existing.getRequiredId())
        != null) {
      throw CFLib.getDefaultExceptionFactory()
          .newDependentsDetectedException(
              getClass(), "deleteUuidDef", "Superclass", "SuperClass", "UuidType", pkey);
    }

    // Delete is valid

    Map<CFBamValuePKey, CFBamUuidDefBuff> subdict;

    dictByPKey.remove(pkey);

    schema.getTableAtom().deleteAtom(Authorization, Buff);
  }
 public CFBamUuidDefBuff readDerived(CFSecurityAuthorization Authorization, CFBamValuePKey PKey) {
   final String S_ProcName = "CFBamRamUuidDef.readDerived";
   CFBamValuePKey key = schema.getFactoryValue().newPKey();
   key.setRequiredTenantId(PKey.getRequiredTenantId());
   key.setRequiredId(PKey.getRequiredId());
   CFBamUuidDefBuff buff;
   if (dictByPKey.containsKey(key)) {
     buff = dictByPKey.get(key);
   } else {
     buff = null;
   }
   return (buff);
 }
 public CFBamUuidDefBuff readDerivedByUNameIdx(
     CFSecurityAuthorization Authorization, long TenantId, long ScopeId, String Name) {
   final String S_ProcName = "CFBamRamValue.readDerivedByUNameIdx";
   CFBamValueBuff buff =
       schema.getTableValue().readDerivedByUNameIdx(Authorization, TenantId, ScopeId, Name);
   if (buff == null) {
     return (null);
   } else if (buff instanceof CFBamUuidDefBuff) {
     return ((CFBamUuidDefBuff) buff);
   } else {
     return (null);
   }
 }
  public void updateUuidDef(CFSecurityAuthorization Authorization, CFBamUuidDefBuff Buff) {
    schema.getTableAtom().updateAtom(Authorization, Buff);
    CFBamValuePKey pkey = schema.getFactoryValue().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFBamUuidDefBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateUuidDef", "Existing record not found", "UuidDef", pkey);
    }
    // Check unique indexes

    // Validate foreign keys

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableAtom()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredTenantId(), Buff.getRequiredId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), "updateUuidDef", "Superclass", "SuperClass", "Atom", null);
        }
      }
    }

    // Update is valid

    Map<CFBamValuePKey, CFBamUuidDefBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.put(pkey, Buff);
  }
 public CFSecurityServiceBuff lockDerived(
     CFSecurityAuthorization Authorization, CFSecurityServicePKey PKey) {
   final String S_ProcName = "CFBamRamService.readDerived";
   CFSecurityServicePKey key = schema.getFactoryService().newPKey();
   key.setRequiredClusterId(PKey.getRequiredClusterId());
   key.setRequiredServiceId(PKey.getRequiredServiceId());
   CFSecurityServiceBuff buff;
   if (dictByPKey.containsKey(key)) {
     buff = dictByPKey.get(key);
   } else {
     buff = null;
   }
   return (buff);
 }
  public void createUuidDef(CFSecurityAuthorization Authorization, CFBamUuidDefBuff Buff) {
    final String S_ProcName = "createUuidDef";
    schema.getTableAtom().createAtom(Authorization, Buff);
    CFBamValuePKey pkey = schema.getFactoryValue().newPKey();
    pkey.setClassCode(Buff.getClassCode());
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    // 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
                .getTableAtom()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredTenantId(), Buff.getRequiredId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Superclass", "SuperClass", "Atom", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);
  }
  public CFSecurityHostNodeBuff readDerivedByIdIdx(
      CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId) {
    final String S_ProcName = "CFBamRamHostNode.readDerivedByIdIdx() ";
    CFSecurityHostNodePKey key = schema.getFactoryHostNode().newPKey();
    key.setRequiredClusterId(ClusterId);
    key.setRequiredHostNodeId(HostNodeId);

    CFSecurityHostNodeBuff buff;
    if (dictByPKey.containsKey(key)) {
      buff = dictByPKey.get(key);
    } else {
      buff = null;
    }
    return (buff);
  }
  public CFSecurityCursor openServiceCursorByTypeIdx(
      CFSecurityAuthorization Authorization, int ServiceTypeId) {
    CFSecurityCursor cursor;
    CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
    key.setRequiredServiceTypeId(ServiceTypeId);

    if (dictByTypeIdx.containsKey(key)) {
      Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx = dictByTypeIdx.get(key);
      cursor = new CFBamRamServiceCursor(Authorization, schema, subdictTypeIdx.values());
    } else {
      cursor =
          new CFBamRamServiceCursor(Authorization, schema, new ArrayList<CFSecurityServiceBuff>());
    }
    return (cursor);
  }
  public CFSecurityHostNodeBuff readDerivedByUDescrIdx(
      CFSecurityAuthorization Authorization, long ClusterId, String Description) {
    final String S_ProcName = "CFBamRamHostNode.readDerivedByUDescrIdx";
    CFSecurityHostNodeByUDescrIdxKey key = schema.getFactoryHostNode().newUDescrIdxKey();
    key.setRequiredClusterId(ClusterId);
    key.setRequiredDescription(Description);

    CFSecurityHostNodeBuff buff;
    if (dictByUDescrIdx.containsKey(key)) {
      buff = dictByUDescrIdx.get(key);
    } else {
      buff = null;
    }
    return (buff);
  }
  public CFSecurityCursor openServiceCursorByHostIdx(
      CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId) {
    CFSecurityCursor cursor;
    CFSecurityServiceByHostIdxKey key = schema.getFactoryService().newHostIdxKey();
    key.setRequiredClusterId(ClusterId);
    key.setRequiredHostNodeId(HostNodeId);

    if (dictByHostIdx.containsKey(key)) {
      Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictHostIdx = dictByHostIdx.get(key);
      cursor = new CFBamRamServiceCursor(Authorization, schema, subdictHostIdx.values());
    } else {
      cursor =
          new CFBamRamServiceCursor(Authorization, schema, new ArrayList<CFSecurityServiceBuff>());
    }
    return (cursor);
  }
  public CFSecurityServiceBuff readDerivedByUHostPortIdx(
      CFSecurityAuthorization Authorization, long ClusterId, long HostNodeId, short HostPort) {
    final String S_ProcName = "CFBamRamService.readDerivedByUHostPortIdx";
    CFSecurityServiceByUHostPortIdxKey key = schema.getFactoryService().newUHostPortIdxKey();
    key.setRequiredClusterId(ClusterId);
    key.setRequiredHostNodeId(HostNodeId);
    key.setRequiredHostPort(HostPort);

    CFSecurityServiceBuff buff;
    if (dictByUHostPortIdx.containsKey(key)) {
      buff = dictByUHostPortIdx.get(key);
    } else {
      buff = null;
    }
    return (buff);
  }
 public CFBamUuidDefBuff[] readDerivedByVAccSecIdx(
     CFSecurityAuthorization Authorization, ICFBamSchema.AccessSecurityEnum ViewAccessSecurity) {
   final String S_ProcName = "CFBamRamValue.readDerivedByVAccSecIdx";
   CFBamValueBuff buffList[] =
       schema.getTableValue().readDerivedByVAccSecIdx(Authorization, ViewAccessSecurity);
   if (buffList == null) {
     return (null);
   } else {
     CFBamValueBuff buff;
     ArrayList<CFBamUuidDefBuff> filteredList = new ArrayList<CFBamUuidDefBuff>();
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       if ((buff != null) && (buff instanceof CFBamUuidDefBuff)) {
         filteredList.add((CFBamUuidDefBuff) buff);
       }
     }
     return (filteredList.toArray(new CFBamUuidDefBuff[0]));
   }
 }
 public CFBamUuidDefBuff[] readDerivedByContNextIdx(
     CFSecurityAuthorization Authorization, long TenantId, long ScopeId, Long NextId) {
   final String S_ProcName = "CFBamRamValue.readDerivedByContNextIdx";
   CFBamValueBuff buffList[] =
       schema.getTableValue().readDerivedByContNextIdx(Authorization, TenantId, ScopeId, NextId);
   if (buffList == null) {
     return (null);
   } else {
     CFBamValueBuff buff;
     ArrayList<CFBamUuidDefBuff> filteredList = new ArrayList<CFBamUuidDefBuff>();
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       if ((buff != null) && (buff instanceof CFBamUuidDefBuff)) {
         filteredList.add((CFBamUuidDefBuff) buff);
       }
     }
     return (filteredList.toArray(new CFBamUuidDefBuff[0]));
   }
 }
  public CFSecurityServiceBuff[] readDerivedByTypeIdx(
      CFSecurityAuthorization Authorization, int ServiceTypeId) {
    final String S_ProcName = "CFBamRamService.readDerivedByTypeIdx";
    CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
    key.setRequiredServiceTypeId(ServiceTypeId);

    CFSecurityServiceBuff[] recArray;
    if (dictByTypeIdx.containsKey(key)) {
      Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx = dictByTypeIdx.get(key);
      recArray = new CFSecurityServiceBuff[subdictTypeIdx.size()];
      Iterator<CFSecurityServiceBuff> iter = subdictTypeIdx.values().iterator();
      int idx = 0;
      while (iter.hasNext()) {
        recArray[idx++] = iter.next();
      }
    } else {
      Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx =
          new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByTypeIdx.put(key, subdictTypeIdx);
      recArray = new CFSecurityServiceBuff[0];
    }
    return (recArray);
  }
 public void deleteServiceByTypeIdx(CFSecurityAuthorization Authorization, int argServiceTypeId) {
   CFSecurityServiceByTypeIdxKey key = schema.getFactoryService().newTypeIdxKey();
   key.setRequiredServiceTypeId(argServiceTypeId);
   deleteServiceByTypeIdx(Authorization, key);
 }
  public void createService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) {
    final String S_ProcName = "createService";
    CFSecurityServicePKey pkey = schema.getFactoryService().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredServiceId(
        ((CFBamRamClusterTable) schema.getTableCluster())
            .nextServiceIdGen(Authorization, Buff.getRequiredClusterId()));
    Buff.setRequiredClusterId(pkey.getRequiredClusterId());
    Buff.setRequiredServiceId(pkey.getRequiredServiceId());
    CFSecurityServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
    keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

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

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

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

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

    // Validate unique indexes

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

    if (dictByUTypeIdx.containsKey(keyUTypeIdx)) {
      throw CFLib.getDefaultExceptionFactory()
          .newUniqueIndexViolationException(getClass(), S_ProcName, "ServiceUTypeIdx", keyUTypeIdx);
    }

    if (dictByUHostPortIdx.containsKey(keyUHostPortIdx)) {
      throw CFLib.getDefaultExceptionFactory()
          .newUniqueIndexViolationException(
              getClass(), S_ProcName, "ServiceUHostPort", keyUHostPortIdx);
    }

    // Validate foreign keys

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

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictClusterIdx;
    if (dictByClusterIdx.containsKey(keyClusterIdx)) {
      subdictClusterIdx = dictByClusterIdx.get(keyClusterIdx);
    } else {
      subdictClusterIdx = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByClusterIdx.put(keyClusterIdx, subdictClusterIdx);
    }
    subdictClusterIdx.put(pkey, Buff);

    Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictHostIdx;
    if (dictByHostIdx.containsKey(keyHostIdx)) {
      subdictHostIdx = dictByHostIdx.get(keyHostIdx);
    } else {
      subdictHostIdx = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByHostIdx.put(keyHostIdx, subdictHostIdx);
    }
    subdictHostIdx.put(pkey, Buff);

    Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdictTypeIdx;
    if (dictByTypeIdx.containsKey(keyTypeIdx)) {
      subdictTypeIdx = dictByTypeIdx.get(keyTypeIdx);
    } else {
      subdictTypeIdx = new HashMap<CFSecurityServicePKey, CFSecurityServiceBuff>();
      dictByTypeIdx.put(keyTypeIdx, subdictTypeIdx);
    }
    subdictTypeIdx.put(pkey, Buff);

    dictByUTypeIdx.put(keyUTypeIdx, Buff);

    dictByUHostPortIdx.put(keyUHostPortIdx, Buff);
  }
  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);
  }