public String getLookupLongValue(String lookupName, String value) { LookupType lookupType = findLookupType(lookupName, value); if (lookupType == null) { return null; } return lookupType.getLongValue(); }
/** * 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); }
private void addLookups(String fieldName, boolean standardNames, Lookup lookup) { if (lookup == null) { LOG.warn("Ignoring null lookup for field: " + fieldName); return; } boolean generateDbValues; Map dbValues; if (fieldName.equals("ListingStatus") && standardNames) { dbValues = LISTING_STATUS_VALUES; generateDbValues = false; } else { dbValues = new ListOrderedMap(); generateDbValues = true; } Map lookupTypesMap = new ListOrderedMap(); Set lookupTypes = lookup.getLookupTypes(); Long saveId = new Long(-1); String saveLevel = null; for (Iterator iterator = lookupTypes.iterator(); iterator.hasNext(); ) { LookupType lookupType = (LookupType) iterator.next(); if (lookupType.getId() > saveId) saveId = lookupType.getId(); if (saveLevel == null) saveLevel = lookupType.getLevel(); String lookupValue = lookupType.getValue(); lookupTypesMap.put(lookupValue, lookupType); if (generateDbValues) { // Assume lookups are stored in the database using the // lookup value. dbValues.put(lookupValue, lookupValue); } } /* * Dummy up an entry to handle .ANY. */ LookupType lookupType = new LookupType(); lookupType.setId(saveId + 1); lookupType.setLevel(saveLevel); lookupType.setLongValue(".ANY."); lookupType.setMetadataEntryID(".ANY."); lookupType.setShortValue(".ANY."); lookupType.setValue(".ANY."); dbValues.put(".ANY.", ".ANY."); lookupTypesMap.put(".ANY.", lookupType); /* * Dummy up an entry to handle .EMPTY. */ lookupType.setId(saveId + 2); lookupType.setLevel(saveLevel); lookupType.setLongValue(".EMPTY."); lookupType.setMetadataEntryID(".EMPTY."); lookupType.setShortValue(".EMPTY."); lookupType.setValue(".EMPTY."); dbValues.put(".EMPTY.", ".EMPTY."); lookupTypesMap.put(".EMPTY.", lookupType); mLookupsDbMap.put(fieldName, dbValues); mLookupTypesMap.put(fieldName, lookupTypesMap); }