public ICFBamDataScopeObj realizeDataScope(ICFBamDataScopeObj Obj) {
    ICFBamDataScopeObj obj = Obj;
    CFBamDataScopePKey pkey = obj.getPKey();
    ICFBamDataScopeObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFBamDataScopeObj existingObj = members.get(pkey);
      keepObj = existingObj;

      /*
       *	We always rebind the data because if we're being called, some index has
       *	been updated and is refreshing it's data, which may or may not have changed
       */

      // Detach object from alternate and duplicate indexes, leave PKey alone

      if (indexByUNameIdx != null) {
        CFBamDataScopeByUNameIdxKey keyUNameIdx =
            ((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newUNameIdxKey();
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.remove(keyUNameIdx);
      }

      keepObj.setBuff(Obj.getBuff());
      // Attach new object to alternate and duplicate indexes -- PKey stay stable

      if (indexByUNameIdx != null) {
        CFBamDataScopeByUNameIdxKey keyUNameIdx =
            ((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newUNameIdxKey();
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
      if (allDataScope != null) {
        allDataScope.put(keepObj.getPKey(), keepObj);
      }
    } else {
      keepObj = obj;
      keepObj.setIsNew(false);
      // Attach new object to PKey, all, alternate, and duplicate indexes
      members.put(keepObj.getPKey(), keepObj);
      if (allDataScope != null) {
        allDataScope.put(keepObj.getPKey(), keepObj);
      }

      if (indexByUNameIdx != null) {
        CFBamDataScopeByUNameIdxKey keyUNameIdx =
            ((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newUNameIdxKey();
        keyUNameIdx.setRequiredName(keepObj.getRequiredName());
        indexByUNameIdx.put(keyUNameIdx, keepObj);
      }
    }
    return (keepObj);
  }
 public ICFSecuritySecGroupIncludeObj readSecGroupIncludeByUIncludeIdx(
     long ClusterId, int SecGroupId, int IncludeGroupId, boolean forceRead) {
   if (indexByUIncludeIdx == null) {
     indexByUIncludeIdx =
         new HashMap<CFSecuritySecGroupIncludeByUIncludeIdxKey, ICFSecuritySecGroupIncludeObj>();
   }
   CFSecuritySecGroupIncludeByUIncludeIdxKey key =
       ((ICFInternetSchema) schema.getBackingStore())
           .getFactorySecGroupInclude()
           .newUIncludeIdxKey();
   key.setRequiredClusterId(ClusterId);
   key.setRequiredSecGroupId(SecGroupId);
   key.setRequiredIncludeGroupId(IncludeGroupId);
   ICFSecuritySecGroupIncludeObj obj = null;
   if ((!forceRead) && indexByUIncludeIdx.containsKey(key)) {
     obj = indexByUIncludeIdx.get(key);
   } else {
     CFSecuritySecGroupIncludeBuff buff =
         ((ICFInternetSchema) schema.getBackingStore())
             .getTableSecGroupInclude()
             .readDerivedByUIncludeIdx(
                 schema.getAuthorization(), ClusterId, SecGroupId, IncludeGroupId);
     if (buff != null) {
       obj = schema.getSecGroupIncludeTableObj().newInstance();
       obj.setPKey(
           ((ICFInternetSchema) schema.getBackingStore()).getFactorySecGroupInclude().newPKey());
       obj.setBuff(buff);
       obj = (ICFSecuritySecGroupIncludeObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByUIncludeIdx.put(key, null);
     }
   }
   return (obj);
 }
 public ICFSecuritySecGroupIncludeObj readSecGroupInclude(
     CFSecuritySecGroupIncludePKey pkey, boolean forceRead) {
   ICFSecuritySecGroupIncludeObj obj = null;
   if ((!forceRead) && members.containsKey(pkey)) {
     obj = members.get(pkey);
   } else {
     CFSecuritySecGroupIncludeBuff readBuff =
         ((ICFInternetSchema) schema.getBackingStore())
             .getTableSecGroupInclude()
             .readDerivedByIdIdx(
                 schema.getAuthorization(),
                 pkey.getRequiredClusterId(),
                 pkey.getRequiredSecGroupIncludeId());
     if (readBuff != null) {
       obj = schema.getSecGroupIncludeTableObj().newInstance();
       obj.setPKey(
           ((ICFInternetSchema) schema.getBackingStore()).getFactorySecGroupInclude().newPKey());
       obj.setBuff(readBuff);
       obj = (ICFSecuritySecGroupIncludeObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       members.put(pkey, null);
     }
   }
   return (obj);
 }
 public ICFBamDataScopeObj readDataScopeByUNameIdx(String Name, boolean forceRead) {
   if (indexByUNameIdx == null) {
     indexByUNameIdx = new HashMap<CFBamDataScopeByUNameIdxKey, ICFBamDataScopeObj>();
   }
   CFBamDataScopeByUNameIdxKey key =
       ((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newUNameIdxKey();
   key.setRequiredName(Name);
   ICFBamDataScopeObj obj = null;
   if ((!forceRead) && indexByUNameIdx.containsKey(key)) {
     obj = indexByUNameIdx.get(key);
   } else {
     CFBamDataScopeBuff buff =
         ((ICFBamSchema) schema.getBackingStore())
             .getTableDataScope()
             .readDerivedByUNameIdx(schema.getAuthorization(), Name);
     if (buff != null) {
       obj = schema.getDataScopeTableObj().newInstance();
       obj.setPKey(((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newPKey());
       obj.setBuff(buff);
       obj = (ICFBamDataScopeObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByUNameIdx.put(key, null);
     }
   }
   return (obj);
 }
 public ICFSecurityISOCountryObj readISOCountryByISOCodeIdx(String ISOCode, boolean forceRead) {
   if (indexByISOCodeIdx == null) {
     indexByISOCodeIdx =
         new HashMap<CFSecurityISOCountryByISOCodeIdxKey, ICFSecurityISOCountryObj>();
   }
   CFSecurityISOCountryByISOCodeIdxKey key =
       ((ICFInternetSchema) schema.getBackingStore()).getFactoryISOCountry().newISOCodeIdxKey();
   key.setRequiredISOCode(ISOCode);
   ICFSecurityISOCountryObj obj = null;
   if ((!forceRead) && indexByISOCodeIdx.containsKey(key)) {
     obj = indexByISOCodeIdx.get(key);
   } else {
     CFSecurityISOCountryBuff buff =
         ((ICFInternetSchema) schema.getBackingStore())
             .getTableISOCountry()
             .readDerivedByISOCodeIdx(schema.getAuthorization(), ISOCode);
     if (buff != null) {
       obj = schema.getISOCountryTableObj().newInstance();
       obj.setPKey(
           ((ICFInternetSchema) schema.getBackingStore()).getFactoryISOCountry().newPKey());
       obj.setBuff(buff);
       obj = (ICFSecurityISOCountryObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       indexByISOCodeIdx.put(key, null);
     }
   }
   return (obj);
 }
 public ICFBamDataScopeObj readDataScope(CFBamDataScopePKey pkey, boolean forceRead) {
   ICFBamDataScopeObj obj = null;
   if ((!forceRead) && members.containsKey(pkey)) {
     obj = members.get(pkey);
   } else {
     CFBamDataScopeBuff readBuff =
         ((ICFBamSchema) schema.getBackingStore())
             .getTableDataScope()
             .readDerivedByIdIdx(schema.getAuthorization(), pkey.getRequiredId());
     if (readBuff != null) {
       obj = schema.getDataScopeTableObj().newInstance();
       obj.setPKey(((ICFBamSchema) schema.getBackingStore()).getFactoryDataScope().newPKey());
       obj.setBuff(readBuff);
       obj = (ICFBamDataScopeObj) obj.realize();
     } else if (schema.getCacheMisses()) {
       members.put(pkey, null);
     }
   }
   return (obj);
 }
  public ICFSecuritySecGroupIncludeObj realizeSecGroupInclude(ICFSecuritySecGroupIncludeObj Obj) {
    ICFSecuritySecGroupIncludeObj obj = Obj;
    CFSecuritySecGroupIncludePKey pkey = obj.getPKey();
    ICFSecuritySecGroupIncludeObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFSecuritySecGroupIncludeObj existingObj = members.get(pkey);
      keepObj = existingObj;

      /*
       *	We always rebind the data because if we're being called, some index has
       *	been updated and is refreshing it's data, which may or may not have changed
       */

      // Detach object from alternate and duplicate indexes, leave PKey alone

      if (indexByClusterIdx != null) {
        CFSecuritySecGroupIncludeByClusterIdxKey keyClusterIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByGroupIdx != null) {
        CFSecuritySecGroupIncludeByGroupIdxKey keyGroupIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapGroupIdx =
            indexByGroupIdx.get(keyGroupIdx);
        if (mapGroupIdx != null) {
          mapGroupIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByIncludeIdx != null) {
        CFSecuritySecGroupIncludeByIncludeIdxKey keyIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newIncludeIdxKey();
        keyIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapIncludeIdx =
            indexByIncludeIdx.get(keyIncludeIdx);
        if (mapIncludeIdx != null) {
          mapIncludeIdx.remove(keepObj.getPKey());
        }
      }

      if (indexByUIncludeIdx != null) {
        CFSecuritySecGroupIncludeByUIncludeIdxKey keyUIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newUIncludeIdxKey();
        keyUIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUIncludeIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        keyUIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        indexByUIncludeIdx.remove(keyUIncludeIdx);
      }

      keepObj.setBuff(Obj.getBuff());
      // Attach new object to alternate and duplicate indexes -- PKey stay stable

      if (indexByClusterIdx != null) {
        CFSecuritySecGroupIncludeByClusterIdxKey keyClusterIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByGroupIdx != null) {
        CFSecuritySecGroupIncludeByGroupIdxKey keyGroupIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapGroupIdx =
            indexByGroupIdx.get(keyGroupIdx);
        if (mapGroupIdx != null) {
          mapGroupIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByIncludeIdx != null) {
        CFSecuritySecGroupIncludeByIncludeIdxKey keyIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newIncludeIdxKey();
        keyIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapIncludeIdx =
            indexByIncludeIdx.get(keyIncludeIdx);
        if (mapIncludeIdx != null) {
          mapIncludeIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUIncludeIdx != null) {
        CFSecuritySecGroupIncludeByUIncludeIdxKey keyUIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newUIncludeIdxKey();
        keyUIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUIncludeIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        keyUIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        indexByUIncludeIdx.put(keyUIncludeIdx, keepObj);
      }
      if (allSecGroupInclude != null) {
        allSecGroupInclude.put(keepObj.getPKey(), keepObj);
      }
    } else {
      keepObj = obj;
      keepObj.setIsNew(false);
      // Attach new object to PKey, all, alternate, and duplicate indexes
      members.put(keepObj.getPKey(), keepObj);
      if (allSecGroupInclude != null) {
        allSecGroupInclude.put(keepObj.getPKey(), keepObj);
      }

      if (indexByClusterIdx != null) {
        CFSecuritySecGroupIncludeByClusterIdxKey keyClusterIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newClusterIdxKey();
        keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapClusterIdx =
            indexByClusterIdx.get(keyClusterIdx);
        if (mapClusterIdx != null) {
          mapClusterIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByGroupIdx != null) {
        CFSecuritySecGroupIncludeByGroupIdxKey keyGroupIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newGroupIdxKey();
        keyGroupIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyGroupIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapGroupIdx =
            indexByGroupIdx.get(keyGroupIdx);
        if (mapGroupIdx != null) {
          mapGroupIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByIncludeIdx != null) {
        CFSecuritySecGroupIncludeByIncludeIdxKey keyIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newIncludeIdxKey();
        keyIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        Map<CFSecuritySecGroupIncludePKey, ICFSecuritySecGroupIncludeObj> mapIncludeIdx =
            indexByIncludeIdx.get(keyIncludeIdx);
        if (mapIncludeIdx != null) {
          mapIncludeIdx.put(keepObj.getPKey(), keepObj);
        }
      }

      if (indexByUIncludeIdx != null) {
        CFSecuritySecGroupIncludeByUIncludeIdxKey keyUIncludeIdx =
            ((ICFInternetSchema) schema.getBackingStore())
                .getFactorySecGroupInclude()
                .newUIncludeIdxKey();
        keyUIncludeIdx.setRequiredClusterId(keepObj.getRequiredClusterId());
        keyUIncludeIdx.setRequiredSecGroupId(keepObj.getRequiredSecGroupId());
        keyUIncludeIdx.setRequiredIncludeGroupId(keepObj.getRequiredIncludeGroupId());
        indexByUIncludeIdx.put(keyUIncludeIdx, keepObj);
      }
    }
    return (keepObj);
  }
  public void createSecSession(
      CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff Buff) {
    final String S_ProcName = "createSecSession";
    CFSecuritySecSessionPKey pkey = schema.getFactorySecSession().newPKey();
    pkey.setRequiredSecSessionId(schema.nextSecSessionIdGen());
    Buff.setRequiredSecSessionId(pkey.getRequiredSecSessionId());
    CFSecuritySecSessionBySecUserIdxKey keySecUserIdx =
        schema.getFactorySecSession().newSecUserIdxKey();
    keySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    CFSecuritySecSessionBySecDevIdxKey keySecDevIdx =
        schema.getFactorySecSession().newSecDevIdxKey();
    keySecDevIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    keySecDevIdx.setOptionalSecDevName(Buff.getOptionalSecDevName());

    CFSecuritySecSessionByStartIdxKey keyStartIdx = schema.getFactorySecSession().newStartIdxKey();
    keyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    keyStartIdx.setRequiredStart(Buff.getRequiredStart());

    CFSecuritySecSessionByFinishIdxKey keyFinishIdx =
        schema.getFactorySecSession().newFinishIdxKey();
    keyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    keyFinishIdx.setOptionalFinish(Buff.getOptionalFinish());

    CFSecuritySecSessionBySecProxyIdxKey keySecProxyIdx =
        schema.getFactorySecSession().newSecProxyIdxKey();
    keySecProxyIdx.setOptionalSecProxyId(Buff.getOptionalSecProxyId());

    // Validate unique indexes

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

    if (dictByStartIdx.containsKey(keyStartIdx)) {
      throw CFLib.getDefaultExceptionFactory()
          .newUniqueIndexViolationException(getClass(), S_ProcName, "SessionStartIdx", keyStartIdx);
    }

    // Validate foreign keys

    {
      boolean allNull = true;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableSecUser()
                .readDerivedByIdIdx(Authorization, Buff.getRequiredSecUserId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Container", "SecSessionUser", "SecUser", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdictSecUserIdx;
    if (dictBySecUserIdx.containsKey(keySecUserIdx)) {
      subdictSecUserIdx = dictBySecUserIdx.get(keySecUserIdx);
    } else {
      subdictSecUserIdx = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecUserIdx.put(keySecUserIdx, subdictSecUserIdx);
    }
    subdictSecUserIdx.put(pkey, Buff);

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdictSecDevIdx;
    if (dictBySecDevIdx.containsKey(keySecDevIdx)) {
      subdictSecDevIdx = dictBySecDevIdx.get(keySecDevIdx);
    } else {
      subdictSecDevIdx = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecDevIdx.put(keySecDevIdx, subdictSecDevIdx);
    }
    subdictSecDevIdx.put(pkey, Buff);

    dictByStartIdx.put(keyStartIdx, Buff);

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdictFinishIdx;
    if (dictByFinishIdx.containsKey(keyFinishIdx)) {
      subdictFinishIdx = dictByFinishIdx.get(keyFinishIdx);
    } else {
      subdictFinishIdx = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictByFinishIdx.put(keyFinishIdx, subdictFinishIdx);
    }
    subdictFinishIdx.put(pkey, Buff);

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdictSecProxyIdx;
    if (dictBySecProxyIdx.containsKey(keySecProxyIdx)) {
      subdictSecProxyIdx = dictBySecProxyIdx.get(keySecProxyIdx);
    } else {
      subdictSecProxyIdx = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecProxyIdx.put(keySecProxyIdx, subdictSecProxyIdx);
    }
    subdictSecProxyIdx.put(pkey, Buff);
  }
  public void updateSecSession(
      CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff Buff) {
    CFSecuritySecSessionPKey pkey = schema.getFactorySecSession().newPKey();
    pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
    CFSecuritySecSessionBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateSecSession", "Existing record not found", "SecSession", pkey);
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "updateSecSession", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFSecuritySecSessionBySecUserIdxKey existingKeySecUserIdx =
        schema.getFactorySecSession().newSecUserIdxKey();
    existingKeySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    CFSecuritySecSessionBySecUserIdxKey newKeySecUserIdx =
        schema.getFactorySecSession().newSecUserIdxKey();
    newKeySecUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    CFSecuritySecSessionBySecDevIdxKey existingKeySecDevIdx =
        schema.getFactorySecSession().newSecDevIdxKey();
    existingKeySecDevIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
    existingKeySecDevIdx.setOptionalSecDevName(existing.getOptionalSecDevName());

    CFSecuritySecSessionBySecDevIdxKey newKeySecDevIdx =
        schema.getFactorySecSession().newSecDevIdxKey();
    newKeySecDevIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    newKeySecDevIdx.setOptionalSecDevName(Buff.getOptionalSecDevName());

    CFSecuritySecSessionByStartIdxKey existingKeyStartIdx =
        schema.getFactorySecSession().newStartIdxKey();
    existingKeyStartIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
    existingKeyStartIdx.setRequiredStart(existing.getRequiredStart());

    CFSecuritySecSessionByStartIdxKey newKeyStartIdx =
        schema.getFactorySecSession().newStartIdxKey();
    newKeyStartIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    newKeyStartIdx.setRequiredStart(Buff.getRequiredStart());

    CFSecuritySecSessionByFinishIdxKey existingKeyFinishIdx =
        schema.getFactorySecSession().newFinishIdxKey();
    existingKeyFinishIdx.setRequiredSecUserId(existing.getRequiredSecUserId());
    existingKeyFinishIdx.setOptionalFinish(existing.getOptionalFinish());

    CFSecuritySecSessionByFinishIdxKey newKeyFinishIdx =
        schema.getFactorySecSession().newFinishIdxKey();
    newKeyFinishIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());
    newKeyFinishIdx.setOptionalFinish(Buff.getOptionalFinish());

    CFSecuritySecSessionBySecProxyIdxKey existingKeySecProxyIdx =
        schema.getFactorySecSession().newSecProxyIdxKey();
    existingKeySecProxyIdx.setOptionalSecProxyId(existing.getOptionalSecProxyId());

    CFSecuritySecSessionBySecProxyIdxKey newKeySecProxyIdx =
        schema.getFactorySecSession().newSecProxyIdxKey();
    newKeySecProxyIdx.setOptionalSecProxyId(Buff.getOptionalSecProxyId());

    // Check unique indexes

    if (!existingKeyStartIdx.equals(newKeyStartIdx)) {
      if (dictByStartIdx.containsKey(newKeyStartIdx)) {
        throw CFLib.getDefaultExceptionFactory()
            .newUniqueIndexViolationException(
                getClass(), "updateSecSession", "SessionStartIdx", newKeyStartIdx);
      }
    }

    // Validate foreign keys

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableSecUser()
                .readDerivedByIdIdx(Authorization, Buff.getRequiredSecUserId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), "updateSecSession", "Container", "SecSessionUser", "SecUser", null);
        }
      }
    }

    // Update is valid

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdict;

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

    subdict = dictBySecUserIdx.get(existingKeySecUserIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictBySecUserIdx.containsKey(newKeySecUserIdx)) {
      subdict = dictBySecUserIdx.get(newKeySecUserIdx);
    } else {
      subdict = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecUserIdx.put(newKeySecUserIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictBySecDevIdx.get(existingKeySecDevIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictBySecDevIdx.containsKey(newKeySecDevIdx)) {
      subdict = dictBySecDevIdx.get(newKeySecDevIdx);
    } else {
      subdict = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecDevIdx.put(newKeySecDevIdx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByStartIdx.remove(existingKeyStartIdx);
    dictByStartIdx.put(newKeyStartIdx, Buff);

    subdict = dictByFinishIdx.get(existingKeyFinishIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByFinishIdx.containsKey(newKeyFinishIdx)) {
      subdict = dictByFinishIdx.get(newKeyFinishIdx);
    } else {
      subdict = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictByFinishIdx.put(newKeyFinishIdx, subdict);
    }
    subdict.put(pkey, Buff);

    subdict = dictBySecProxyIdx.get(existingKeySecProxyIdx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictBySecProxyIdx.containsKey(newKeySecProxyIdx)) {
      subdict = dictBySecProxyIdx.get(newKeySecProxyIdx);
    } else {
      subdict = new HashMap<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff>();
      dictBySecProxyIdx.put(newKeySecProxyIdx, subdict);
    }
    subdict.put(pkey, Buff);
  }