public void deleteServiceByIdIdx(
     CFSecurityAuthorization Authorization, long argClusterId, long argServiceId) {
   CFSecurityServicePKey key = schema.getFactoryService().newPKey();
   key.setRequiredClusterId(argClusterId);
   key.setRequiredServiceId(argServiceId);
   deleteServiceByIdIdx(Authorization, key);
 }
  public void deleteService(CFSecurityAuthorization Authorization, CFSecurityServiceBuff Buff) {
    final String S_ProcName = "CFBamRamServiceTable.deleteService() ";
    CFSecurityServicePKey pkey = schema.getFactoryService().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredServiceId(Buff.getRequiredServiceId());
    CFSecurityServiceBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteService", pkey);
    }
    CFSecurityServiceByClusterIdxKey keyClusterIdx = schema.getFactoryService().newClusterIdxKey();
    keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

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

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

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

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

    // Validate reverse foreign keys

    // Delete is valid

    Map<CFSecurityServicePKey, CFSecurityServiceBuff> subdict;

    dictByPKey.remove(pkey);

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

    subdict = dictByHostIdx.get(keyHostIdx);
    subdict.remove(pkey);

    subdict = dictByTypeIdx.get(keyTypeIdx);
    subdict.remove(pkey);

    dictByUTypeIdx.remove(keyUTypeIdx);

    dictByUHostPortIdx.remove(keyUHostPortIdx);
  }
 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 deleteServiceByIdIdx(
     CFSecurityAuthorization Authorization, CFSecurityServicePKey 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 startElement(String uri, String localName, String qName, Attributes attrs)
      throws SAXException {
    CFCrmXMsgSchemaMessageFormatter schemaFormatter = null;
    try {
      // Common XML Attributes
      String attrId = null;
      String attrRevision = null;
      // Primary Key Attributes for Constant Enum support
      String attrClusterId = null;
      String attrServiceId = null;
      // Attribute Extraction
      String attrLocalName;
      int numAttrs;
      int idxAttr;
      final String S_ProcName = "startElement";
      final String S_LocalName = "LocalName";

      assert qName.equals("RqstServiceDelete");

      CFCrmXMsgRqstHandler xmsgRqstHandler = (CFCrmXMsgRqstHandler) getParser();
      if (xmsgRqstHandler == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()");
      }

      schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();

      ICFCrmSchemaObj schemaObj = xmsgRqstHandler.getSchemaObj();
      if (schemaObj == null) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()");
      }

      // Instantiate a PKey buffer for the parsed information
      CFSecurityServicePKey pkey =
          ((ICFCrmSchema) schemaObj.getBackingStore()).getFactoryService().newPKey();

      // Extract Attributes
      numAttrs = attrs.getLength();
      for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) {
        attrLocalName = attrs.getLocalName(idxAttr);
        if (attrLocalName.equals("Id")) {
          if (attrId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("Revision")) {
          if (attrRevision != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrRevision = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("ClusterId")) {
          if (attrClusterId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrClusterId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("ServiceId")) {
          if (attrServiceId != null) {
            throw CFLib.getDefaultExceptionFactory()
                .newUniqueIndexViolationException(
                    getClass(), S_ProcName, S_LocalName, attrLocalName);
          }
          attrServiceId = attrs.getValue(idxAttr);
        } else if (attrLocalName.equals("schemaLocation")) {
          // ignored
        } else {
          throw CFLib.getDefaultExceptionFactory()
              .newUnrecognizedAttributeException(
                  getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName);
        }
      }

      // Ensure that required attributes have values
      if ((attrClusterId == null) || (attrClusterId.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "ClusterId");
      }
      if ((attrServiceId == null) || (attrServiceId.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "ServiceId");
      }
      if ((attrRevision == null) || (attrRevision.length() <= 0)) {
        throw CFLib.getDefaultExceptionFactory()
            .newNullArgumentException(getClass(), S_ProcName, 0, "Revision");
      }

      // Get current context
      CFLibXmlCoreContext curContext = getParser().getCurContext();
      // Convert string attributes to native Java types
      // and apply the converted attributes to the editBuff.

      long natClusterId;
      natClusterId = Long.parseLong(attrClusterId);
      pkey.setRequiredClusterId(natClusterId);

      pkey.setRequiredClusterId(natClusterId);
      long natServiceId;
      natServiceId = Long.parseLong(attrServiceId);
      pkey.setRequiredServiceId(natServiceId);

      pkey.setRequiredServiceId(natServiceId);
      int natRevision = Integer.parseInt(attrRevision);
      // Delete the object
      ICFCrmServiceObj read = ((ICFCrmServiceObj) schemaObj.getServiceTableObj().readService(pkey));
      if (read != null) {
        if (read.getServiceBuff().getRequiredRevision() > natRevision) {
          throw CFLib.getDefaultExceptionFactory()
              .newCollisionDetectedException(
                  getClass(), S_ProcName, "Collision detected preparing to delete Service");
        } else {
          ICFCrmServiceEditObj editBuff = (ICFCrmServiceEditObj) read.beginEdit();
          if (editBuff != null) {
            editBuff.delete();
            editBuff.endEdit();
            String response =
                schemaFormatter.formatRspnXmlPreamble()
                    + "\n"
                    + "\t"
                    + CFCrmXMsgServiceMessageFormatter.formatServiceRspnDeleted()
                    + "\n"
                    + schemaFormatter.formatRspnXmlPostamble();
            ((CFCrmXMsgRqstHandler) getParser()).appendResponse(response);
          } else {
            throw CFLib.getDefaultExceptionFactory()
                .newNullArgumentException(getClass(), S_ProcName, 0, "read.beginEdit()");
          }
        }
      } else {
        String response =
            schemaFormatter.formatRspnXmlPreamble()
                + "\n"
                + "\t"
                + CFCrmXMsgSchemaMessageFormatter.formatRspnNoDataFound()
                + "\n"
                + schemaFormatter.formatRspnXmlPostamble();
        ((CFCrmXMsgRqstHandler) getParser()).appendResponse(response);
      }
    } catch (RuntimeException e) {
      CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
      schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
      String response =
          schemaFormatter.formatRspnXmlPreamble()
              + "\n"
              + "\t"
              + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e)
              + "\n"
              + schemaFormatter.formatRspnXmlPostamble();
      xmsgRqstHandler.resetResponse();
      xmsgRqstHandler.appendResponse(response);
      xmsgRqstHandler.setCaughtException(true);
    } catch (Error e) {
      CFCrmXMsgRqstHandler xmsgRqstHandler = ((CFCrmXMsgRqstHandler) getParser());
      schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter();
      String response =
          schemaFormatter.formatRspnXmlPreamble()
              + "\n"
              + "\t"
              + CFCrmXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e)
              + "\n"
              + schemaFormatter.formatRspnXmlPostamble();
      xmsgRqstHandler.resetResponse();
      xmsgRqstHandler.appendResponse(response);
      xmsgRqstHandler.setCaughtException(true);
    }
  }
  public int compareTo(Object obj) {
    if (obj == null) {
      return (-1);
    } else if (obj instanceof CFSecurityServiceBuff) {
      CFSecurityServiceBuff rhs = (CFSecurityServiceBuff) obj;
      int retval = 0;
      {
        int cmp = getCreatedByUserId().compareTo(rhs.getCreatedByUserId());
        if (cmp != 0) {
          return (cmp);
        }

        cmp = getCreatedAt().compareTo(rhs.getCreatedAt());
        if (cmp != 0) {
          return (cmp);
        }

        cmp = getUpdatedByUserId().compareTo(rhs.getUpdatedByUserId());
        if (cmp != 0) {
          return (cmp);
        }

        cmp = getUpdatedAt().compareTo(rhs.getUpdatedAt());
        if (cmp != 0) {
          return (cmp);
        }
      }
      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredServiceId() < rhs.getRequiredServiceId()) {
        return (-1);
      } else if (getRequiredServiceId() > rhs.getRequiredServiceId()) {
        return (1);
      }
      if (getRequiredHostNodeId() < rhs.getRequiredHostNodeId()) {
        return (-1);
      } else if (getRequiredHostNodeId() > rhs.getRequiredHostNodeId()) {
        return (1);
      }
      if (getRequiredServiceTypeId() < rhs.getRequiredServiceTypeId()) {
        return (-1);
      } else if (getRequiredServiceTypeId() > rhs.getRequiredServiceTypeId()) {
        return (1);
      }
      if (getRequiredHostPort() < rhs.getRequiredHostPort()) {
        return (-1);
      } else if (getRequiredHostPort() > rhs.getRequiredHostPort()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServicePKey) {
      CFSecurityServicePKey rhs = (CFSecurityServicePKey) obj;
      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredServiceId() < rhs.getRequiredServiceId()) {
        return (-1);
      } else if (getRequiredServiceId() > rhs.getRequiredServiceId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceHPKey) {
      CFSecurityServiceHPKey rhs = (CFSecurityServiceHPKey) obj;
      {
        int lhsRequiredRevision = getRequiredRevision();
        int rhsRequiredRevision = rhs.getRequiredRevision();
        if (lhsRequiredRevision < rhsRequiredRevision) {
          return (-1);
        } else if (lhsRequiredRevision > rhsRequiredRevision) {
          return (1);
        }
      }
      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredServiceId() < rhs.getRequiredServiceId()) {
        return (-1);
      } else if (getRequiredServiceId() > rhs.getRequiredServiceId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceHBuff) {
      CFSecurityServiceHBuff rhs = (CFSecurityServiceHBuff) obj;
      int retval = 0;
      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredServiceId() < rhs.getRequiredServiceId()) {
        return (-1);
      } else if (getRequiredServiceId() > rhs.getRequiredServiceId()) {
        return (1);
      }
      if (getRequiredHostNodeId() < rhs.getRequiredHostNodeId()) {
        return (-1);
      } else if (getRequiredHostNodeId() > rhs.getRequiredHostNodeId()) {
        return (1);
      }
      if (getRequiredServiceTypeId() < rhs.getRequiredServiceTypeId()) {
        return (-1);
      } else if (getRequiredServiceTypeId() > rhs.getRequiredServiceTypeId()) {
        return (1);
      }
      if (getRequiredHostPort() < rhs.getRequiredHostPort()) {
        return (-1);
      } else if (getRequiredHostPort() > rhs.getRequiredHostPort()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceByClusterIdxKey) {
      CFSecurityServiceByClusterIdxKey rhs = (CFSecurityServiceByClusterIdxKey) obj;

      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceByHostIdxKey) {
      CFSecurityServiceByHostIdxKey rhs = (CFSecurityServiceByHostIdxKey) obj;

      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredHostNodeId() < rhs.getRequiredHostNodeId()) {
        return (-1);
      } else if (getRequiredHostNodeId() > rhs.getRequiredHostNodeId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceByTypeIdxKey) {
      CFSecurityServiceByTypeIdxKey rhs = (CFSecurityServiceByTypeIdxKey) obj;

      if (getRequiredServiceTypeId() < rhs.getRequiredServiceTypeId()) {
        return (-1);
      } else if (getRequiredServiceTypeId() > rhs.getRequiredServiceTypeId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceByUTypeIdxKey) {
      CFSecurityServiceByUTypeIdxKey rhs = (CFSecurityServiceByUTypeIdxKey) obj;

      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredHostNodeId() < rhs.getRequiredHostNodeId()) {
        return (-1);
      } else if (getRequiredHostNodeId() > rhs.getRequiredHostNodeId()) {
        return (1);
      }
      if (getRequiredServiceTypeId() < rhs.getRequiredServiceTypeId()) {
        return (-1);
      } else if (getRequiredServiceTypeId() > rhs.getRequiredServiceTypeId()) {
        return (1);
      }
      return (0);
    } else if (obj instanceof CFSecurityServiceByUHostPortIdxKey) {
      CFSecurityServiceByUHostPortIdxKey rhs = (CFSecurityServiceByUHostPortIdxKey) obj;

      if (getRequiredClusterId() < rhs.getRequiredClusterId()) {
        return (-1);
      } else if (getRequiredClusterId() > rhs.getRequiredClusterId()) {
        return (1);
      }
      if (getRequiredHostNodeId() < rhs.getRequiredHostNodeId()) {
        return (-1);
      } else if (getRequiredHostNodeId() > rhs.getRequiredHostNodeId()) {
        return (1);
      }
      if (getRequiredHostPort() < rhs.getRequiredHostPort()) {
        return (-1);
      } else if (getRequiredHostPort() > rhs.getRequiredHostPort()) {
        return (1);
      }
      return (0);
    } else {
      throw CFLib.getDefaultExceptionFactory()
          .newUnsupportedClassException(getClass(), "compareTo", "obj", obj, null);
    }
  }
 public boolean equals(Object obj) {
   if (obj == null) {
     return (false);
   } else if (obj instanceof CFSecurityServiceBuff) {
     CFSecurityServiceBuff rhs = (CFSecurityServiceBuff) obj;
     if (!getCreatedByUserId().equals(rhs.getCreatedByUserId())) {
       return (false);
     }
     if (!getCreatedAt().equals(rhs.getCreatedAt())) {
       return (false);
     }
     if (!getUpdatedByUserId().equals(rhs.getUpdatedByUserId())) {
       return (false);
     }
     if (!getUpdatedAt().equals(rhs.getUpdatedAt())) {
       return (false);
     }
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredServiceId() != rhs.getRequiredServiceId()) {
       return (false);
     }
     if (getRequiredHostNodeId() != rhs.getRequiredHostNodeId()) {
       return (false);
     }
     if (getRequiredServiceTypeId() != rhs.getRequiredServiceTypeId()) {
       return (false);
     }
     if (getRequiredHostPort() != rhs.getRequiredHostPort()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServicePKey) {
     CFSecurityServicePKey rhs = (CFSecurityServicePKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredServiceId() != rhs.getRequiredServiceId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceHBuff) {
     CFSecurityServiceHBuff rhs = (CFSecurityServiceHBuff) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredServiceId() != rhs.getRequiredServiceId()) {
       return (false);
     }
     if (getRequiredHostNodeId() != rhs.getRequiredHostNodeId()) {
       return (false);
     }
     if (getRequiredServiceTypeId() != rhs.getRequiredServiceTypeId()) {
       return (false);
     }
     if (getRequiredHostPort() != rhs.getRequiredHostPort()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceHPKey) {
     CFSecurityServiceHPKey rhs = (CFSecurityServiceHPKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredServiceId() != rhs.getRequiredServiceId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceByClusterIdxKey) {
     CFSecurityServiceByClusterIdxKey rhs = (CFSecurityServiceByClusterIdxKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceByHostIdxKey) {
     CFSecurityServiceByHostIdxKey rhs = (CFSecurityServiceByHostIdxKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredHostNodeId() != rhs.getRequiredHostNodeId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceByTypeIdxKey) {
     CFSecurityServiceByTypeIdxKey rhs = (CFSecurityServiceByTypeIdxKey) obj;
     if (getRequiredServiceTypeId() != rhs.getRequiredServiceTypeId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceByUTypeIdxKey) {
     CFSecurityServiceByUTypeIdxKey rhs = (CFSecurityServiceByUTypeIdxKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredHostNodeId() != rhs.getRequiredHostNodeId()) {
       return (false);
     }
     if (getRequiredServiceTypeId() != rhs.getRequiredServiceTypeId()) {
       return (false);
     }
     return (true);
   } else if (obj instanceof CFSecurityServiceByUHostPortIdxKey) {
     CFSecurityServiceByUHostPortIdxKey rhs = (CFSecurityServiceByUHostPortIdxKey) obj;
     if (getRequiredClusterId() != rhs.getRequiredClusterId()) {
       return (false);
     }
     if (getRequiredHostNodeId() != rhs.getRequiredHostNodeId()) {
       return (false);
     }
     if (getRequiredHostPort() != rhs.getRequiredHostPort()) {
       return (false);
     }
     return (true);
   } else {
     boolean retval = super.equals(obj);
     return (retval);
   }
 }
  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);
  }