/** * Merge a new reference Type into an existing Cache item. Typically done when a Constant * Reference Type item is merged with its Database equivalent. * * @param lookupType * @param referenceMap */ protected static boolean mergeExistingItem(LookupType lookupType) { LookupType cachedItem = getFromCacheByCode(lookupType.getCode(), lookupType.getClass()); if (cachedItem == null) { return false; } BeanUtils.copyProperties(lookupType, cachedItem); return true; }
/** * Adds the passed in reference type to the cache. Types are cached by their Id and Value Fields. * * @param lookupType */ protected static void addToCache(LookupType lookupType) { Map<String, LookupType> referenceMap = lookupTypeCache.get(lookupType.getClass()); if (referenceMap == null) { referenceMap = new HashMap<String, LookupType>(); lookupTypeCache.put(lookupType.getClass(), referenceMap); } // If this is an existing item, update the Cache object if (mergeExistingItem(lookupType)) { return; } referenceMap.put("CODE_" + lookupType.getCode().toUpperCase(), lookupType); referenceMap.put("ID_" + lookupType.getId(), lookupType); }