public CFBamDelSubDep3Buff lockBuff(CFBamAuthorization Authorization, CFBamScopePKey PKey) {
   final String S_ProcName = "CFBamRamDelSubDep3.readBuff() ";
   CFBamDelSubDep3Buff buff = readDerived(Authorization, PKey);
   if ((buff != null) && (!buff.getClassCode().equals("DEL3"))) {
     buff = null;
   }
   return (buff);
 }
 public CFBamDelSubDep3Buff readBuffByUNameIdx(
     CFBamAuthorization Authorization, long ContTenantId, long ContDelDep2Id, String Name) {
   final String S_ProcName = "CFBamRamDelSubDep3.readBuffByUNameIdx() ";
   CFBamDelSubDep3Buff buff =
       readDerivedByUNameIdx(Authorization, ContTenantId, ContDelDep2Id, Name);
   if ((buff != null) && buff.getClassCode().equals("DEL3")) {
     return ((CFBamDelSubDep3Buff) buff);
   } else {
     return (null);
   }
 }
 public CFBamDelSubDep3Buff[] readAllBuff(CFBamAuthorization Authorization) {
   final String S_ProcName = "CFBamRamDelSubDep3.readAllBuff() ";
   CFBamDelSubDep3Buff buff;
   ArrayList<CFBamDelSubDep3Buff> filteredList = new ArrayList<CFBamDelSubDep3Buff>();
   CFBamDelSubDep3Buff[] buffList = readAllDerived(Authorization);
   for (int idx = 0; idx < buffList.length; idx++) {
     buff = buffList[idx];
     if ((buff != null) && buff.getClassCode().equals("DEL3")) {
       filteredList.add(buff);
     }
   }
   return (filteredList.toArray(new CFBamDelSubDep3Buff[0]));
 }
 public CFBamDelSubDep3Buff[] readBuffByContDelDep2Idx(
     CFBamAuthorization Authorization, long ContTenantId, long ContDelDep2Id) {
   final String S_ProcName = "CFBamRamDelSubDep3.readBuffByContDelDep2Idx() ";
   CFBamDelSubDep3Buff buff;
   ArrayList<CFBamDelSubDep3Buff> filteredList = new ArrayList<CFBamDelSubDep3Buff>();
   CFBamDelSubDep3Buff[] buffList =
       readDerivedByContDelDep2Idx(Authorization, ContTenantId, ContDelDep2Id);
   for (int idx = 0; idx < buffList.length; idx++) {
     buff = buffList[idx];
     if ((buff != null) && buff.getClassCode().equals("DEL3")) {
       filteredList.add((CFBamDelSubDep3Buff) buff);
     }
   }
   return (filteredList.toArray(new CFBamDelSubDep3Buff[0]));
 }
  public void deleteDelSubDep3(CFBamAuthorization Authorization, CFBamDelSubDep3Buff Buff) {
    final String S_ProcName = "CFBamRamDelSubDep3Table.deleteDelSubDep3() ";
    CFBamScopePKey pkey = schema.getFactoryScope().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFBamDelSubDep3Buff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteDelSubDep3", pkey);
    }
    CFBamDelSubDep3ByContDelDep2IdxKey keyContDelDep2Idx =
        schema.getFactoryDelSubDep3().newContDelDep2IdxKey();
    keyContDelDep2Idx.setRequiredContTenantId(existing.getRequiredContTenantId());
    keyContDelDep2Idx.setRequiredContDelDep2Id(existing.getRequiredContDelDep2Id());

    CFBamDelSubDep3ByUNameIdxKey keyUNameIdx = schema.getFactoryDelSubDep3().newUNameIdxKey();
    keyUNameIdx.setRequiredContTenantId(existing.getRequiredContTenantId());
    keyUNameIdx.setRequiredContDelDep2Id(existing.getRequiredContDelDep2Id());
    keyUNameIdx.setRequiredName(existing.getRequiredName());

    // Validate reverse foreign keys

    // Delete is valid

    Map<CFBamScopePKey, CFBamDelSubDep3Buff> subdict;

    dictByPKey.remove(pkey);

    subdict = dictByContDelDep2Idx.get(keyContDelDep2Idx);
    subdict.remove(pkey);

    dictByUNameIdx.remove(keyUNameIdx);

    schema.getTableDelDep().deleteDelDep(Authorization, Buff);
  }
  public void createDelSubDep3(CFBamAuthorization Authorization, CFBamDelSubDep3Buff Buff) {
    final String S_ProcName = "createDelSubDep3";
    schema.getTableDelDep().createDelDep(Authorization, Buff);
    CFBamScopePKey pkey = schema.getFactoryScope().newPKey();
    pkey.setClassCode(Buff.getClassCode());
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFBamDelSubDep3ByContDelDep2IdxKey keyContDelDep2Idx =
        schema.getFactoryDelSubDep3().newContDelDep2IdxKey();
    keyContDelDep2Idx.setRequiredContTenantId(Buff.getRequiredContTenantId());
    keyContDelDep2Idx.setRequiredContDelDep2Id(Buff.getRequiredContDelDep2Id());

    CFBamDelSubDep3ByUNameIdxKey keyUNameIdx = schema.getFactoryDelSubDep3().newUNameIdxKey();
    keyUNameIdx.setRequiredContTenantId(Buff.getRequiredContTenantId());
    keyUNameIdx.setRequiredContDelDep2Id(Buff.getRequiredContDelDep2Id());
    keyUNameIdx.setRequiredName(Buff.getRequiredName());

    // Validate unique indexes

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

    if (dictByUNameIdx.containsKey(keyUNameIdx)) {
      throw CFLib.getDefaultExceptionFactory()
          .newUniqueIndexViolationException(
              getClass(), S_ProcName, "DelSubDep3UNameIdx", keyUNameIdx);
    }

    // Validate foreign keys

    {
      boolean allNull = true;
      allNull = false;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableDelDep()
                .readDerivedByIdIdx(
                    Authorization, Buff.getRequiredTenantId(), Buff.getRequiredId())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Superclass", "SuperClass", "DelDep", null);
        }
      }
    }

    {
      boolean allNull = true;
      allNull = false;
      allNull = false;
      if (!allNull) {
        if (null
            == schema
                .getTableDelSubDep2()
                .readDerivedByIdIdx(
                    Authorization,
                    Buff.getRequiredContTenantId(),
                    Buff.getRequiredContDelDep2Id())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(), S_ProcName, "Container", "ContDelSubDep3", "DelSubDep2", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    Map<CFBamScopePKey, CFBamDelSubDep3Buff> subdictContDelDep2Idx;
    if (dictByContDelDep2Idx.containsKey(keyContDelDep2Idx)) {
      subdictContDelDep2Idx = dictByContDelDep2Idx.get(keyContDelDep2Idx);
    } else {
      subdictContDelDep2Idx = new HashMap<CFBamScopePKey, CFBamDelSubDep3Buff>();
      dictByContDelDep2Idx.put(keyContDelDep2Idx, subdictContDelDep2Idx);
    }
    subdictContDelDep2Idx.put(pkey, Buff);

    dictByUNameIdx.put(keyUNameIdx, Buff);
  }
  public void updateDelSubDep3(CFBamAuthorization Authorization, CFBamDelSubDep3Buff Buff) {
    schema.getTableDelDep().updateDelDep(Authorization, Buff);
    CFBamScopePKey pkey = schema.getFactoryScope().newPKey();
    pkey.setRequiredTenantId(Buff.getRequiredTenantId());
    pkey.setRequiredId(Buff.getRequiredId());
    CFBamDelSubDep3Buff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateDelSubDep3", "Existing record not found", "DelSubDep3", pkey);
    }
    CFBamDelSubDep3ByContDelDep2IdxKey existingKeyContDelDep2Idx =
        schema.getFactoryDelSubDep3().newContDelDep2IdxKey();
    existingKeyContDelDep2Idx.setRequiredContTenantId(existing.getRequiredContTenantId());
    existingKeyContDelDep2Idx.setRequiredContDelDep2Id(existing.getRequiredContDelDep2Id());

    CFBamDelSubDep3ByContDelDep2IdxKey newKeyContDelDep2Idx =
        schema.getFactoryDelSubDep3().newContDelDep2IdxKey();
    newKeyContDelDep2Idx.setRequiredContTenantId(Buff.getRequiredContTenantId());
    newKeyContDelDep2Idx.setRequiredContDelDep2Id(Buff.getRequiredContDelDep2Id());

    CFBamDelSubDep3ByUNameIdxKey existingKeyUNameIdx =
        schema.getFactoryDelSubDep3().newUNameIdxKey();
    existingKeyUNameIdx.setRequiredContTenantId(existing.getRequiredContTenantId());
    existingKeyUNameIdx.setRequiredContDelDep2Id(existing.getRequiredContDelDep2Id());
    existingKeyUNameIdx.setRequiredName(existing.getRequiredName());

    CFBamDelSubDep3ByUNameIdxKey newKeyUNameIdx = schema.getFactoryDelSubDep3().newUNameIdxKey();
    newKeyUNameIdx.setRequiredContTenantId(Buff.getRequiredContTenantId());
    newKeyUNameIdx.setRequiredContDelDep2Id(Buff.getRequiredContDelDep2Id());
    newKeyUNameIdx.setRequiredName(Buff.getRequiredName());

    // Check unique indexes

    if (!existingKeyUNameIdx.equals(newKeyUNameIdx)) {
      if (dictByUNameIdx.containsKey(newKeyUNameIdx)) {
        throw CFLib.getDefaultExceptionFactory()
            .newUniqueIndexViolationException(
                getClass(), "updateDelSubDep3", "DelSubDep3UNameIdx", newKeyUNameIdx);
      }
    }

    // Validate foreign keys

    {
      boolean allNull = true;

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

    {
      boolean allNull = true;

      if (allNull) {
        if (null
            == schema
                .getTableDelSubDep2()
                .readDerivedByIdIdx(
                    Authorization,
                    Buff.getRequiredContTenantId(),
                    Buff.getRequiredContDelDep2Id())) {
          throw CFLib.getDefaultExceptionFactory()
              .newUnresolvedRelationException(
                  getClass(),
                  "updateDelSubDep3",
                  "Container",
                  "ContDelSubDep3",
                  "DelSubDep2",
                  null);
        }
      }
    }

    // Update is valid

    Map<CFBamScopePKey, CFBamDelSubDep3Buff> subdict;

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

    subdict = dictByContDelDep2Idx.get(existingKeyContDelDep2Idx);
    if (subdict != null) {
      subdict.remove(pkey);
    }
    if (dictByContDelDep2Idx.containsKey(newKeyContDelDep2Idx)) {
      subdict = dictByContDelDep2Idx.get(newKeyContDelDep2Idx);
    } else {
      subdict = new HashMap<CFBamScopePKey, CFBamDelSubDep3Buff>();
      dictByContDelDep2Idx.put(newKeyContDelDep2Idx, subdict);
    }
    subdict.put(pkey, Buff);

    dictByUNameIdx.remove(existingKeyUNameIdx);
    dictByUNameIdx.put(newKeyUNameIdx, Buff);
  }