public void deleteSecSessionByStartIdx(
     CFSecurityAuthorization Authorization, CFSecuritySecSessionByStartIdxKey argKey) {
   CFSecuritySecSessionBuff cur;
   LinkedList<CFSecuritySecSessionBuff> matchSet = new LinkedList<CFSecuritySecSessionBuff>();
   Iterator<CFSecuritySecSessionBuff> values = dictByPKey.values().iterator();
   while (values.hasNext()) {
     cur = values.next();
     if (argKey.equals(cur)) {
       matchSet.add(cur);
     }
   }
   Iterator<CFSecuritySecSessionBuff> iterMatch = matchSet.iterator();
   while (iterMatch.hasNext()) {
     cur = iterMatch.next();
     deleteSecSession(Authorization, cur);
   }
 }
 public void deleteSecSessionByStartIdx(
     CFSecurityAuthorization Authorization, UUID argSecUserId, Calendar argStart) {
   CFSecuritySecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
   key.setRequiredSecUserId(argSecUserId);
   key.setRequiredStart(argStart);
   deleteSecSessionByStartIdx(Authorization, key);
 }
  public void deleteSecSession(
      CFSecurityAuthorization Authorization, CFSecuritySecSessionBuff Buff) {
    final String S_ProcName = "CFSecurityRamSecSessionTable.deleteSecSession() ";
    CFSecuritySecSessionPKey pkey = schema.getFactorySecSession().newPKey();
    pkey.setRequiredSecSessionId(Buff.getRequiredSecSessionId());
    CFSecuritySecSessionBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteSecSession", pkey);
    }
    CFSecuritySecSessionBySecUserIdxKey keySecUserIdx =
        schema.getFactorySecSession().newSecUserIdxKey();
    keySecUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

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

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

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

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

    // Validate reverse foreign keys

    // Delete is valid

    Map<CFSecuritySecSessionPKey, CFSecuritySecSessionBuff> subdict;

    dictByPKey.remove(pkey);

    subdict = dictBySecUserIdx.get(keySecUserIdx);
    subdict.remove(pkey);

    subdict = dictBySecDevIdx.get(keySecDevIdx);
    subdict.remove(pkey);

    dictByStartIdx.remove(keyStartIdx);

    subdict = dictByFinishIdx.get(keyFinishIdx);
    subdict.remove(pkey);

    subdict = dictBySecProxyIdx.get(keySecProxyIdx);
    subdict.remove(pkey);
  }
  public CFSecuritySecSessionBuff readDerivedByStartIdx(
      CFSecurityAuthorization Authorization, UUID SecUserId, Calendar Start) {
    final String S_ProcName = "CFSecurityRamSecSession.readDerivedByStartIdx";
    CFSecuritySecSessionByStartIdxKey key = schema.getFactorySecSession().newStartIdxKey();
    key.setRequiredSecUserId(SecUserId);
    key.setRequiredStart(Start);

    CFSecuritySecSessionBuff buff;
    if (dictByStartIdx.containsKey(key)) {
      buff = dictByStartIdx.get(key);
    } else {
      buff = null;
    }
    return (buff);
  }
  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);
  }