public ICFSecuritySecDeviceObj lockSecDevice(CFSecuritySecDevicePKey pkey) { ICFSecuritySecDeviceObj locked = null; CFSecuritySecDeviceBuff lockBuff = ((ICFAsteriskSchema) schema.getBackingStore()) .getTableSecDevice() .lockDerived(schema.getAuthorization(), pkey); if (lockBuff != null) { locked = schema.getSecDeviceTableObj().newInstance(); locked.setPKey( ((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newPKey()); locked.setBuff(lockBuff); locked = (ICFSecuritySecDeviceObj) locked.realize(); } else { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "lockSecDevice", pkey); } return (locked); }
public ICFSecuritySecDeviceObj readSecDevice(CFSecuritySecDevicePKey pkey, boolean forceRead) { ICFSecuritySecDeviceObj obj = null; if ((!forceRead) && members.containsKey(pkey)) { obj = members.get(pkey); } else { CFSecuritySecDeviceBuff readBuff = ((ICFAsteriskSchema) schema.getBackingStore()) .getTableSecDevice() .readDerivedByIdIdx( schema.getAuthorization(), pkey.getRequiredSecUserId(), pkey.getRequiredDevName()); if (readBuff != null) { obj = schema.getSecDeviceTableObj().newInstance(); obj.setPKey(((ICFAsteriskSchema) schema.getBackingStore()).getFactorySecDevice().newPKey()); obj.setBuff(readBuff); obj = (ICFSecuritySecDeviceObj) obj.realize(); } else if (schema.getCacheMisses()) { members.put(pkey, null); } } return (obj); }
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 List<ICFSecuritySecDeviceObj> readAllSecDevice(boolean forceRead) { final String S_ProcName = "readAllSecDevice"; if ((allSecDevice == null) || forceRead) { Map<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj> map = new HashMap<CFSecuritySecDevicePKey, ICFSecuritySecDeviceObj>(); allSecDevice = map; CFSecuritySecDeviceBuff[] buffList = ((ICFAsteriskSchema) schema.getBackingStore()) .getTableSecDevice() .readAllDerived(schema.getAuthorization()); CFSecuritySecDeviceBuff buff; ICFSecuritySecDeviceObj obj; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = 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 = allSecDevice.size(); ICFSecuritySecDeviceObj arr[] = new ICFSecuritySecDeviceObj[len]; Iterator<ICFSecuritySecDeviceObj> valIter = allSecDevice.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); }