public void deleteSecDeviceByUserIdx(UUID SecUserId) {
   CFSecuritySecDeviceByUserIdxKey key =
       ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
   key.setRequiredSecUserId(SecUserId);
   if (indexByUserIdx == null) {
     indexByUserIdx =
         new HashMap<
             CFSecuritySecDeviceByUserIdxKey,
             Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>>();
   }
   if (indexByUserIdx.containsKey(key)) {
     Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> dict = indexByUserIdx.get(key);
     ((ICFAsteriskSchema) schema.getBackingStore())
         .getTableSecDevice()
         .deleteSecDeviceByUserIdx(schema.getAuthorization(), SecUserId);
     Iterator<ICFSecuritySecDeviceObj> iter = dict.values().iterator();
     ICFSecuritySecDeviceObj obj;
     List<ICFSecuritySecDeviceObj> toForget = new LinkedList<ICFSecuritySecDeviceObj>();
     while (iter.hasNext()) {
       obj = iter.next();
       toForget.add(obj);
     }
     iter = toForget.iterator();
     while (iter.hasNext()) {
       obj = iter.next();
       obj.forget(true);
     }
     indexByUserIdx.remove(key);
   } else {
     ((ICFAsteriskSchema) schema.getBackingStore())
         .getTableSecDevice()
         .deleteSecDeviceByUserIdx(schema.getAuthorization(), SecUserId);
   }
 }
  public void forgetSecDeviceByUserIdx(UUID SecUserId) {
    if (indexByUserIdx == null) {
      return;
    }
    CFSecuritySecDeviceByUserIdxKey key =
        ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
    key.setRequiredSecUserId(SecUserId);
    if (indexByUserIdx.containsKey(key)) {
      Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx = indexByUserIdx.get(key);
      if (mapUserIdx != null) {
        List<ICFSecuritySecDeviceObj> toForget = new LinkedList<ICFSecuritySecDeviceObj>();
        ICFSecuritySecDeviceObj cur = null;
        Iterator<ICFSecuritySecDeviceObj> iter = mapUserIdx.values().iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          toForget.add(cur);
        }
        iter = toForget.iterator();
        while (iter.hasNext()) {
          cur = iter.next();
          cur.forget(true);
        }
      }

      indexByUserIdx.remove(key);
    }
  }
  public void deleteSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "CFAsteriskRamSecDeviceTable.deleteSecDevice() ";
    CFSecuritySecDevicePKey pkey = schema.getFactorySecDevice().newPKey();
    pkey.setRequiredSecUserId(Buff.getRequiredSecUserId());
    pkey.setRequiredDevName(Buff.getRequiredDevName());
    CFSecuritySecDeviceBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      return;
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "deleteSecDevice", pkey);
    }
    CFSecuritySecDeviceByUserIdxKey keyUserIdx = schema.getFactorySecDevice().newUserIdxKey();
    keyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    // Validate reverse foreign keys

    // Delete is valid

    Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdict;

    dictByPKey.remove(pkey);

    subdict = dictByUserIdx.get(keyUserIdx);
    subdict.remove(pkey);
  }
  public void forgetSecDevice(ICFSecuritySecDeviceObj Obj, boolean forgetSubObjects) {
    ICFSecuritySecDeviceObj obj = Obj;
    CFSecuritySecDevicePKey pkey = obj.getPKey();
    if (members.containsKey(pkey)) {
      ICFSecuritySecDeviceObj keepObj = members.get(pkey);
      // Detach object from alternate, duplicate, all and PKey indexes

      if (indexByUserIdx != null) {
        CFSecuritySecDeviceByUserIdxKey keyUserIdx =
            ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(keepObj.getRequiredSecUserId());
        Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx =
            indexByUserIdx.get(keyUserIdx);
        if (mapUserIdx != null) {
          mapUserIdx.remove(keepObj.getPKey());
        }
      }

      if (allSecDevice != null) {
        allSecDevice.remove(keepObj.getPKey());
      }
      members.remove(pkey);
      if (forgetSubObjects) {}
    }
  }
  public void updateSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    CFSecuritySecDevicePKey pkey = schema.getFactorySecDevice().newPKey();
    pkey.setRequiredSecUserId(Buff.getRequiredSecUserId());
    pkey.setRequiredDevName(Buff.getRequiredDevName());
    CFSecuritySecDeviceBuff existing = dictByPKey.get(pkey);
    if (existing == null) {
      throw CFLib.getDefaultExceptionFactory()
          .newStaleCacheDetectedException(
              getClass(), "updateSecDevice", "Existing record not found", "SecDevice", pkey);
    }
    if (existing.getRequiredRevision() != Buff.getRequiredRevision()) {
      throw CFLib.getDefaultExceptionFactory()
          .newCollisionDetectedException(getClass(), "updateSecDevice", pkey);
    }
    Buff.setRequiredRevision(Buff.getRequiredRevision() + 1);
    CFSecuritySecDeviceByUserIdxKey existingKeyUserIdx =
        schema.getFactorySecDevice().newUserIdxKey();
    existingKeyUserIdx.setRequiredSecUserId(existing.getRequiredSecUserId());

    CFSecuritySecDeviceByUserIdxKey newKeyUserIdx = schema.getFactorySecDevice().newUserIdxKey();
    newKeyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    // Check unique indexes

    // Validate foreign keys

    {
      boolean allNull = true;

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

    // Update is valid

    Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdict;

    dictByPKey.remove(pkey);
    dictByPKey.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<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff>();
      dictByUserIdx.put(newKeyUserIdx, subdict);
    }
    subdict.put(pkey, Buff);
  }
  public CFSecurityCursor openSecDeviceCursorByUserIdx(
      CFSecurityAuthorization Authorization, UUID SecUserId) {
    CFSecurityCursor cursor;
    CFSecuritySecDeviceByUserIdxKey key = schema.getFactorySecDevice().newUserIdxKey();
    key.setRequiredSecUserId(SecUserId);

    if (dictByUserIdx.containsKey(key)) {
      Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdictUserIdx = dictByUserIdx.get(key);
      cursor = new CFAsteriskRamSecDeviceCursor(Authorization, schema, subdictUserIdx.values());
    } else {
      cursor =
          new CFAsteriskRamSecDeviceCursor(
              Authorization, schema, new ArrayList<CFSecuritySecDeviceBuff>());
    }
    return (cursor);
  }
  public void createSecDevice(CFSecurityAuthorization Authorization, CFSecuritySecDeviceBuff Buff) {
    final String S_ProcName = "createSecDevice";
    CFSecuritySecDevicePKey pkey = schema.getFactorySecDevice().newPKey();
    pkey.setRequiredSecUserId(Buff.getRequiredSecUserId());
    pkey.setRequiredDevName(Buff.getRequiredDevName());
    Buff.setRequiredSecUserId(pkey.getRequiredSecUserId());
    Buff.setRequiredDevName(pkey.getRequiredDevName());
    CFSecuritySecDeviceByUserIdxKey keyUserIdx = schema.getFactorySecDevice().newUserIdxKey();
    keyUserIdx.setRequiredSecUserId(Buff.getRequiredSecUserId());

    // Validate unique indexes

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

    // 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", "SecDeviceSecUser", "SecUser", null);
        }
      }
    }

    // Proceed with adding the new record

    dictByPKey.put(pkey, Buff);

    Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdictUserIdx;
    if (dictByUserIdx.containsKey(keyUserIdx)) {
      subdictUserIdx = dictByUserIdx.get(keyUserIdx);
    } else {
      subdictUserIdx = new HashMap<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff>();
      dictByUserIdx.put(keyUserIdx, subdictUserIdx);
    }
    subdictUserIdx.put(pkey, Buff);
  }
  public CFSecuritySecDeviceBuff[] readDerivedByUserIdx(
      CFSecurityAuthorization Authorization, UUID SecUserId) {
    final String S_ProcName = "CFAsteriskRamSecDevice.readDerivedByUserIdx";
    CFSecuritySecDeviceByUserIdxKey key = schema.getFactorySecDevice().newUserIdxKey();
    key.setRequiredSecUserId(SecUserId);

    CFSecuritySecDeviceBuff[] recArray;
    if (dictByUserIdx.containsKey(key)) {
      Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdictUserIdx = dictByUserIdx.get(key);
      recArray = new CFSecuritySecDeviceBuff[subdictUserIdx.size()];
      Iterator<CFSecuritySecDeviceBuff> iter = subdictUserIdx.values().iterator();
      int idx = 0;
      while (iter.hasNext()) {
        recArray[idx++] = iter.next();
      }
    } else {
      Map<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff> subdictUserIdx =
          new HashMap<CFSecuritySecDevicePKey, CFSecuritySecDeviceBuff>();
      dictByUserIdx.put(key, subdictUserIdx);
      recArray = new CFSecuritySecDeviceBuff[0];
    }
    return (recArray);
  }
 public void deleteSecDeviceByUserIdx(
     CFSecurityAuthorization Authorization, CFSecuritySecDeviceByUserIdxKey argKey) {
   CFSecuritySecDeviceBuff cur;
   LinkedList<CFSecuritySecDeviceBuff> matchSet = new LinkedList<CFSecuritySecDeviceBuff>();
   Iterator<CFSecuritySecDeviceBuff> values = dictByPKey.values().iterator();
   while (values.hasNext()) {
     cur = values.next();
     if (argKey.equals(cur)) {
       matchSet.add(cur);
     }
   }
   Iterator<CFSecuritySecDeviceBuff> iterMatch = matchSet.iterator();
   while (iterMatch.hasNext()) {
     cur = iterMatch.next();
     deleteSecDevice(Authorization, cur);
   }
 }
 public List<ICFSecuritySecDeviceObj> readSecDeviceByUserIdx(UUID SecUserId, boolean forceRead) {
   final String S_ProcName = "readSecDeviceByUserIdx";
   CFSecuritySecDeviceByUserIdxKey key =
       ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
   key.setRequiredSecUserId(SecUserId);
   Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> dict;
   if (indexByUserIdx == null) {
     indexByUserIdx =
         new HashMap<
             CFSecuritySecDeviceByUserIdxKey,
             Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>>();
   }
   if ((!forceRead) && indexByUserIdx.containsKey(key)) {
     dict = indexByUserIdx.get(key);
   } else {
     dict = new HashMap<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>();
     // Allow other threads to dirty-read while we're loading
     indexByUserIdx.put(key, dict);
     ICFSecuritySecDeviceObj obj;
     CFSecuritySecDeviceBuff[] buffList =
         ((ICFAsteriskSchema) schema.getBackingStore())
             .getTableSecDevice()
             .readDerivedByUserIdx(schema.getAuthorization(), SecUserId);
     CFSecuritySecDeviceBuff buff;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = schema.getSecDeviceTableObj().newInstance();
       obj.setPKey(((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newPKey());
       obj.setBuff(buff);
       ICFSecuritySecDeviceObj realized = (ICFSecuritySecDeviceObj) obj.realize();
     }
   }
   Comparator<ICFSecuritySecDeviceObj> cmp =
       new Comparator<ICFSecuritySecDeviceObj>() {
         public int compare(ICFSecuritySecDeviceObj lhs, ICFSecuritySecDeviceObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFSecuritySecDevicePKey lhsPKey = lhs.getPKey();
             CFSecuritySecDevicePKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = dict.size();
   ICFSecuritySecDeviceObj arr[] = new ICFSecuritySecDeviceObj[len];
   Iterator<ICFSecuritySecDeviceObj> valIter = dict.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFSecuritySecDeviceObj> arrayList = new ArrayList<ICFSecuritySecDeviceObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFSecuritySecDeviceObj> sortedList = arrayList;
   return (sortedList);
 }
  public ICFSecuritySecDeviceObj realizeSecDevice(ICFSecuritySecDeviceObj Obj) {
    ICFSecuritySecDeviceObj obj = Obj;
    CFSecuritySecDevicePKey pkey = obj.getPKey();
    ICFSecuritySecDeviceObj keepObj = null;
    if (members.containsKey(pkey) && (null != members.get(pkey))) {
      ICFSecuritySecDeviceObj 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 (indexByUserIdx != null) {
        CFSecuritySecDeviceByUserIdxKey keyUserIdx =
            ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(keepObj.getRequiredSecUserId());
        Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx =
            indexByUserIdx.get(keyUserIdx);
        if (mapUserIdx != null) {
          mapUserIdx.remove(keepObj.getPKey());
        }
      }

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

      if (indexByUserIdx != null) {
        CFSecuritySecDeviceByUserIdxKey keyUserIdx =
            ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(keepObj.getRequiredSecUserId());
        Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx =
            indexByUserIdx.get(keyUserIdx);
        if (mapUserIdx != null) {
          mapUserIdx.put(keepObj.getPKey(), keepObj);
        }
      }
      if (allSecDevice != null) {
        allSecDevice.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 (allSecDevice != null) {
        allSecDevice.put(keepObj.getPKey(), keepObj);
      }

      if (indexByUserIdx != null) {
        CFSecuritySecDeviceByUserIdxKey keyUserIdx =
            ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newUserIdxKey();
        keyUserIdx.setRequiredSecUserId(keepObj.getRequiredSecUserId());
        Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> mapUserIdx =
            indexByUserIdx.get(keyUserIdx);
        if (mapUserIdx != null) {
          mapUserIdx.put(keepObj.getPKey(), keepObj);
        }
      }
    }
    return (keepObj);
  }
 public void deleteSecDeviceByUserIdx(CFSecurityAuthorization Authorization, UUID argSecUserId) {
   CFSecuritySecDeviceByUserIdxKey key = schema.getFactorySecDevice().newUserIdxKey();
   key.setRequiredSecUserId(argSecUserId);
   deleteSecDeviceByUserIdx(Authorization, key);
 }