public void deleteSecGroupMemberByClusterIdx(
     CFSecurityAuthorization Authorization, long argClusterId) {
   CFSecuritySecGroupMemberByClusterIdxKey key =
       schema.getFactorySecGroupMember().newClusterIdxKey();
   key.setRequiredClusterId(argClusterId);
   deleteSecGroupMemberByClusterIdx(Authorization, key);
 }
  public CFSecuritySecGroupMemberBuff[] readDerivedByClusterIdx(
      CFSecurityAuthorization Authorization, long ClusterId) {
    final String S_ProcName = "CFFreeSwitchRamSecGroupMember.readDerivedByClusterIdx";
    CFSecuritySecGroupMemberByClusterIdxKey key =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    key.setRequiredClusterId(ClusterId);

    CFSecuritySecGroupMemberBuff[] recArray;
    if (dictByClusterIdx.containsKey(key)) {
      Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdictClusterIdx =
          dictByClusterIdx.get(key);
      recArray = new CFSecuritySecGroupMemberBuff[subdictClusterIdx.size()];
      Iterator<CFSecuritySecGroupMemberBuff> iter = subdictClusterIdx.values().iterator();
      int idx = 0;
      while (iter.hasNext()) {
        recArray[idx++] = iter.next();
      }
    } else {
      Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdictClusterIdx =
          new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByClusterIdx.put(key, subdictClusterIdx);
      recArray = new CFSecuritySecGroupMemberBuff[0];
    }
    return (recArray);
  }
  public void deleteSecGroupMember(
      CFSecurityAuthorization Authorization, CFSecuritySecGroupMemberBuff Buff) {
    final String S_ProcName = "CFFreeSwitchRamSecGroupMemberTable.deleteSecGroupMember() ";
    CFSecuritySecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
    CFSecuritySecGroupMemberBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteSecGroupMember", pkey);
    }
    CFSecuritySecGroupMemberByClusterIdxKey keyClusterIdx =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    keyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

    CFSecuritySecGroupMemberByGroupIdxKey keyGroupIdx =
        schema.getFactorySecGroupMember().newGroupIdxKey();
    keyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
    keyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

    CFSecuritySecGroupMemberByUserIdxKey keyUserIdx =
        schema.getFactorySecGroupMember().newUserIdxKey();
    keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    CFSecuritySecGroupMemberByUUserIdxKey keyUUserIdx =
        schema.getFactorySecGroupMember().newUUserIdxKey();
    keyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId());
    keyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
    keyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    // Validate reverse foreign keys

    // Delete is valid

    Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdict;

    dictByPKey.remove(pkey);

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

    subdict = dictByGroupIdx.get(keyGroupIdx);
    subdict.remove(pkey);

    subdict = dictByUserIdx.get(keyUserIdx);
    subdict.remove(pkey);

    dictByUUserIdx.remove(keyUUserIdx);
  }
  public CFSecurityCursor openSecGroupMemberCursorByClusterIdx(
      CFSecurityAuthorization Authorization, long ClusterId) {
    CFSecurityCursor cursor;
    CFSecuritySecGroupMemberByClusterIdxKey key =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    key.setRequiredClusterId(ClusterId);

    if (dictByClusterIdx.containsKey(key)) {
      Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdictClusterIdx =
          dictByClusterIdx.get(key);
      cursor =
          new CFFreeSwitchRamSecGroupMemberCursor(
              Authorization, schema, subdictClusterIdx.values());
    } else {
      cursor =
          new CFFreeSwitchRamSecGroupMemberCursor(
              Authorization, schema, new ArrayList<CFSecuritySecGroupMemberBuff>());
    }
    return (cursor);
  }
  public void createSecGroupMember(
      CFSecurityAuthorization Authorization, CFSecuritySecGroupMemberBuff Buff) {
    final String S_ProcName = "createSecGroupMember";
    CFSecuritySecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredSecGroupMemberId(
        ((CFFreeSwitchRamClusterTable) schema.getTableCluster())
            .nextSecGroupMemberIdGen(Authorization, Buff.getRequiredClusterId()));
    Buff.setRequiredClusterId(pkey.getRequiredClusterId());
    Buff.setRequiredSecGroupMemberId(pkey.getRequiredSecGroupMemberId());
    CFSecuritySecGroupMemberByClusterIdxKey keyClusterIdx =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    keyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

    CFSecuritySecGroupMemberByGroupIdxKey keyGroupIdx =
        schema.getFactorySecGroupMember().newGroupIdxKey();
    keyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    keyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

    CFSecuritySecGroupMemberByUserIdxKey keyUserIdx =
        schema.getFactorySecGroupMember().newUserIdxKey();
    keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    CFSecuritySecGroupMemberByUUserIdxKey keyUUserIdx =
        schema.getFactorySecGroupMember().newUUserIdxKey();
    keyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    keyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
    keyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    // Validate unique indexes

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

    if (dictByUUserIdx.containsKey(keyUUserIdx)) {
      throw CFLib.getDefaultExceptionFactory()
          .newUniqueIndexViolationException(
              getClass(), S_ProcName, "SecGroupMemberUUserIdx", keyUUserIdx);
    }

    // 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", "SecGroupMemberCluster", "Cluster", null);
        }
      }
    }

    {
      boolean allNull = true;
      allNull = false;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableSecGroup()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecGroupId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Container", "SecGroupMemberGroup", "SecGroup", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

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

    Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdictGroupIdx;
    if (dictByGroupIdx.containsKey(keyGroupIdx)) {
      subdictGroupIdx = dictByGroupIdx.get(keyGroupIdx);
    } else {
      subdictGroupIdx = new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByGroupIdx.put(keyGroupIdx, subdictGroupIdx);
    }
    subdictGroupIdx.put(pkey, Buff);

    Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> subdictUserIdx;
    if (dictByUserIdx.containsKey(keyUserIdx)) {
      subdictUserIdx = dictByUserIdx.get(keyUserIdx);
    } else {
      subdictUserIdx = new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByUserIdx.put(keyUserIdx, subdictUserIdx);
    }
    subdictUserIdx.put(pkey, Buff);

    dictByUUserIdx.put(keyUUserIdx, Buff);
  }
  public void updateSecGroupMember(
      CFSecurityAuthorization Authorization, CFSecuritySecGroupMemberBuff Buff) {
    CFSecuritySecGroupMemberPKey pkey = schema.getFactorySecGroupMember().newPKey();
    pkey.setRequiredClusterId(Buff.getRequiredClusterId());
    pkey.setRequiredSecGroupMemberId(Buff.getRequiredSecGroupMemberId());
    CFSecuritySecGroupMemberBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(),
              "updateSecGroupMember",
              "Existing record not found",
              "SecGroupMember",
              pkey);
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "updateSecGroupMember", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFSecuritySecGroupMemberByClusterIdxKey existingKeyClusterIdx =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    existingKeyClusterIdx.setRequiredClusterId(existing.getRequiredClusterId());

    CFSecuritySecGroupMemberByClusterIdxKey newKeyClusterIdx =
        schema.getFactorySecGroupMember().newClusterIdxKey();
    newKeyClusterIdx.setRequiredClusterId(Buff.getRequiredClusterId());

    CFSecuritySecGroupMemberByGroupIdxKey existingKeyGroupIdx =
        schema.getFactorySecGroupMember().newGroupIdxKey();
    existingKeyGroupIdx.setRequiredClusterId(existing.getRequiredClusterId());
    existingKeyGroupIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());

    CFSecuritySecGroupMemberByGroupIdxKey newKeyGroupIdx =
        schema.getFactorySecGroupMember().newGroupIdxKey();
    newKeyGroupIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    newKeyGroupIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());

    CFSecuritySecGroupMemberByUserIdxKey existingKeyUserIdx =
        schema.getFactorySecGroupMember().newUserIdxKey();
    existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    CFSecuritySecGroupMemberByUserIdxKey newKeyUserIdx =
        schema.getFactorySecGroupMember().newUserIdxKey();
    newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    CFSecuritySecGroupMemberByUUserIdxKey existingKeyUUserIdx =
        schema.getFactorySecGroupMember().newUUserIdxKey();
    existingKeyUUserIdx.setRequiredClusterId(existing.getRequiredClusterId());
    existingKeyUUserIdx.setRequiredSecGroupId(existing.getRequiredSecGroupId());
    existingKeyUUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    CFSecuritySecGroupMemberByUUserIdxKey newKeyUUserIdx =
        schema.getFactorySecGroupMember().newUUserIdxKey();
    newKeyUUserIdx.setRequiredClusterId(Buff.getRequiredClusterId());
    newKeyUUserIdx.setRequiredSecGroupId(Buff.getRequiredSecGroupId());
    newKeyUUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    // Check unique indexes

    if (!existingKeyUUserIdx.equals(newKeyUUserIdx)) {
      if (dictByUUserIdx.containsKey(newKeyUUserIdx)) {
        throw CFLib.getDefaultExceptionFactory()
            .newUniqueIndexViolationException(
                getClass(), "updateSecGroupMember", "SecGroupMemberUUserIdx", newKeyUUserIdx);
      }
    }

    // Validate foreign keys

    {
      boolean allNull = true;

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

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableSecGroup()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredClusterId(), Buff.getRequiredSecGroupId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(),
                  "updateSecGroupMember",
                  "Container",
                  "SecGroupMemberGroup",
                  "SecGroup",
                  null);
        }
      }
    }

    // Update is valid

    Map<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff> 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<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByClusterIdx.put(newKeyClusterIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByGroupIdx.get(existingKeyGroupIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByGroupIdx.containsKey(newKeyGroupIdx)) {
      subdict = dictByGroupIdx.get(newKeyGroupIdx);
    } else {
      subdict = new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByGroupIdx.put(newKeyGroupIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictByUserIdx.get(existingKeyUserIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByUserIdx.containsKey(newKeyUserIdx)) {
      subdict = dictByUserIdx.get(newKeyUserIdx);
    } else {
      subdict = new HashMap<CFSecuritySecGroupMemberPKey, CFSecuritySecGroupMemberBuff>();
      dictByUserIdx.put(newKeyUserIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByUUserIdx.remove(existingKeyUUserIdx);
    dictByUUserIdx.put(newKeyUUserIdx, Buff);
  }