public void deleteMemoByMemoContactIdx(long TenantId, long ContactId) { CFCrmMemoByMemoContactIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredContactId(ContactId); if (indexByMemoContactIdx == null) { indexByMemoContactIdx = new HashMap<CFCrmMemoByMemoContactIdxKey, Map<CFCrmMemoPKey, ICFCrmMemoObj>>(); } if (indexByMemoContactIdx.containsKey(key)) { Map<CFCrmMemoPKey, ICFCrmMemoObj> dict = indexByMemoContactIdx.get(key); ((ICFAccSchema) schema.getBackingStore()) .getTableMemo() .deleteMemoByMemoContactIdx(schema.getAuthorization(), TenantId, ContactId); Iterator<ICFCrmMemoObj> iter = dict.values().iterator(); ICFCrmMemoObj obj; List<ICFCrmMemoObj> toForget = new LinkedList<ICFCrmMemoObj>(); while (iter.hasNext()) { obj = iter.next(); toForget.add(obj); } iter = toForget.iterator(); while (iter.hasNext()) { obj = iter.next(); obj.forget(true); } indexByMemoContactIdx.remove(key); } else { ((ICFAccSchema) schema.getBackingStore()) .getTableMemo() .deleteMemoByMemoContactIdx(schema.getAuthorization(), TenantId, ContactId); } }
public void forgetMemoByMemoContactIdx(long TenantId, long ContactId) { if (indexByMemoContactIdx == null) { return; } CFCrmMemoByMemoContactIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredContactId(ContactId); if (indexByMemoContactIdx.containsKey(key)) { Map<CFCrmMemoPKey, ICFCrmMemoObj> mapMemoContactIdx = indexByMemoContactIdx.get(key); if (mapMemoContactIdx != null) { List<ICFCrmMemoObj> toForget = new LinkedList<ICFCrmMemoObj>(); ICFCrmMemoObj cur = null; Iterator<ICFCrmMemoObj> iter = mapMemoContactIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByMemoContactIdx.remove(key); } }
public void forgetMemo(ICFCrmMemoObj Obj, boolean forgetSubObjects) { ICFCrmMemoObj obj = Obj; CFCrmMemoPKey pkey = obj.getPKey(); if (members.containsKey(pkey)) { ICFCrmMemoObj keepObj = members.get(pkey); // Detach object from alternate, duplicate, all and PKey indexes if (indexByTenantIdx != null) { CFCrmMemoByTenantIdxKey keyTenantIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx); if (mapTenantIdx != null) { mapTenantIdx.remove(keepObj.getPKey()); } } if (indexByMemoContactIdx != null) { CFCrmMemoByMemoContactIdxKey keyMemoContactIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); keyMemoContactIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyMemoContactIdx.setRequiredContactId(keepObj.getRequiredContactId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapMemoContactIdx = indexByMemoContactIdx.get(keyMemoContactIdx); if (mapMemoContactIdx != null) { mapMemoContactIdx.remove(keepObj.getPKey()); } } if (indexByUDescrIdx != null) { CFCrmMemoByUDescrIdxKey keyUDescrIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newUDescrIdxKey(); keyUDescrIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyUDescrIdx.setRequiredContactId(keepObj.getRequiredContactId()); keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription()); indexByUDescrIdx.remove(keyUDescrIdx); } if (allMemo != null) { allMemo.remove(keepObj.getPKey()); } members.remove(pkey); if (forgetSubObjects) { ((ICFCrmSchemaObj) schema) .getMemoTagTableObj() .forgetMemoTagByMemoIdx(keepObj.getRequiredTenantId(), keepObj.getRequiredMemoId()); } } }
public List<ICFCrmMemoObj> readMemoByMemoContactIdx( long TenantId, long ContactId, boolean forceRead) { final String S_ProcName = "readMemoByMemoContactIdx"; CFCrmMemoByMemoContactIdxKey key = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); key.setRequiredTenantId(TenantId); key.setRequiredContactId(ContactId); Map<CFCrmMemoPKey, ICFCrmMemoObj> dict; if (indexByMemoContactIdx == null) { indexByMemoContactIdx = new HashMap<CFCrmMemoByMemoContactIdxKey, Map<CFCrmMemoPKey, ICFCrmMemoObj>>(); } if ((!forceRead) && indexByMemoContactIdx.containsKey(key)) { dict = indexByMemoContactIdx.get(key); } else { dict = new HashMap<CFCrmMemoPKey, ICFCrmMemoObj>(); // Allow other threads to dirty-read while we're loading indexByMemoContactIdx.put(key, dict); ICFCrmMemoObj obj; CFCrmMemoBuff[] buffList = ((ICFAccSchema) schema.getBackingStore()) .getTableMemo() .readDerivedByMemoContactIdx(schema.getAuthorization(), TenantId, ContactId); CFCrmMemoBuff buff; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = schema.getMemoTableObj().newInstance(); obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newPKey()); obj.setBuff(buff); ICFCrmMemoObj realized = (ICFCrmMemoObj) obj.realize(); } } Comparator<ICFCrmMemoObj> cmp = new Comparator<ICFCrmMemoObj>() { public int compare(ICFCrmMemoObj lhs, ICFCrmMemoObj rhs) { if (lhs == null) { if (rhs == null) { return (0); } else { return (-1); } } else if (rhs == null) { return (1); } else { CFCrmMemoPKey lhsPKey = lhs.getPKey(); CFCrmMemoPKey rhsPKey = rhs.getPKey(); int ret = lhsPKey.compareTo(rhsPKey); return (ret); } } }; int len = dict.size(); ICFCrmMemoObj arr[] = new ICFCrmMemoObj[len]; Iterator<ICFCrmMemoObj> 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<ICFCrmMemoObj> arrayList = new ArrayList<ICFCrmMemoObj>(len); for (idx = 0; idx < len; idx++) { arrayList.add(arr[idx]); } List<ICFCrmMemoObj> sortedList = arrayList; return (sortedList); }
public ICFCrmMemoObj realizeMemo(ICFCrmMemoObj Obj) { ICFCrmMemoObj obj = Obj; CFCrmMemoPKey pkey = obj.getPKey(); ICFCrmMemoObj keepObj = null; if (members.containsKey(pkey) && (null != members.get(pkey))) { ICFCrmMemoObj 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 (indexByTenantIdx != null) { CFCrmMemoByTenantIdxKey keyTenantIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx); if (mapTenantIdx != null) { mapTenantIdx.remove(keepObj.getPKey()); } } if (indexByMemoContactIdx != null) { CFCrmMemoByMemoContactIdxKey keyMemoContactIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); keyMemoContactIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyMemoContactIdx.setRequiredContactId(keepObj.getRequiredContactId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapMemoContactIdx = indexByMemoContactIdx.get(keyMemoContactIdx); if (mapMemoContactIdx != null) { mapMemoContactIdx.remove(keepObj.getPKey()); } } if (indexByUDescrIdx != null) { CFCrmMemoByUDescrIdxKey keyUDescrIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newUDescrIdxKey(); keyUDescrIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyUDescrIdx.setRequiredContactId(keepObj.getRequiredContactId()); keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription()); indexByUDescrIdx.remove(keyUDescrIdx); } keepObj.setBuff(Obj.getBuff()); // Attach new object to alternate and duplicate indexes -- PKey stay stable if (indexByTenantIdx != null) { CFCrmMemoByTenantIdxKey keyTenantIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx); if (mapTenantIdx != null) { mapTenantIdx.put(keepObj.getPKey(), keepObj); } } if (indexByMemoContactIdx != null) { CFCrmMemoByMemoContactIdxKey keyMemoContactIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); keyMemoContactIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyMemoContactIdx.setRequiredContactId(keepObj.getRequiredContactId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapMemoContactIdx = indexByMemoContactIdx.get(keyMemoContactIdx); if (mapMemoContactIdx != null) { mapMemoContactIdx.put(keepObj.getPKey(), keepObj); } } if (indexByUDescrIdx != null) { CFCrmMemoByUDescrIdxKey keyUDescrIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newUDescrIdxKey(); keyUDescrIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyUDescrIdx.setRequiredContactId(keepObj.getRequiredContactId()); keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription()); indexByUDescrIdx.put(keyUDescrIdx, keepObj); } if (allMemo != null) { allMemo.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 (allMemo != null) { allMemo.put(keepObj.getPKey(), keepObj); } if (indexByTenantIdx != null) { CFCrmMemoByTenantIdxKey keyTenantIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newTenantIdxKey(); keyTenantIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapTenantIdx = indexByTenantIdx.get(keyTenantIdx); if (mapTenantIdx != null) { mapTenantIdx.put(keepObj.getPKey(), keepObj); } } if (indexByMemoContactIdx != null) { CFCrmMemoByMemoContactIdxKey keyMemoContactIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newMemoContactIdxKey(); keyMemoContactIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyMemoContactIdx.setRequiredContactId(keepObj.getRequiredContactId()); Map<CFCrmMemoPKey, ICFCrmMemoObj> mapMemoContactIdx = indexByMemoContactIdx.get(keyMemoContactIdx); if (mapMemoContactIdx != null) { mapMemoContactIdx.put(keepObj.getPKey(), keepObj); } } if (indexByUDescrIdx != null) { CFCrmMemoByUDescrIdxKey keyUDescrIdx = ((ICFAccSchema) schema.getBackingStore()).getFactoryMemo().newUDescrIdxKey(); keyUDescrIdx.setRequiredTenantId(keepObj.getRequiredTenantId()); keyUDescrIdx.setRequiredContactId(keepObj.getRequiredContactId()); keyUDescrIdx.setRequiredDescription(keepObj.getRequiredDescription()); indexByUDescrIdx.put(keyUDescrIdx, keepObj); } } return (keepObj); }