protected ReferenceDataProviderGetResult loadAndPersistUnknownFields(
Map<String, ReferenceData> cachedResults,
Map<Set<String>, Set<String>> identifiersByFields) {
// TODO kirk 2009-10-23 -- Also need to maintain securities we don't need to put back in the database.
ReferenceDataProviderGetResult result = new ReferenceDataProviderGetResult();
// REVIEW kirk 2009-10-23 -- Candidate for scatter/gather.
for (Map.Entry<Set<String>, Set<String>> entry : identifiersByFields.entrySet()) {
Set<String> requestedIdentifiers = entry.getValue();
Set<String> requestedFields = entry.getKey();
assert !requestedIdentifiers.isEmpty();
if (entry.getKey().isEmpty()) {
s_logger.debug("Satisfied entire request for securities {} from cache", requestedIdentifiers);
for (String securityKey : requestedIdentifiers) {
result.addReferenceData(cachedResults.get(securityKey));
}
continue;
}
s_logger.info("Loading {} fields for {} securities from underlying", entry.getKey().size(), requestedIdentifiers.size());
final ReferenceDataProviderGetRequest underlyingRequest = ReferenceDataProviderGetRequest.createGet(requestedIdentifiers, requestedFields, false);
ReferenceDataProviderGetResult loadedResult = getUnderlying().getReferenceData(underlyingRequest);
for (String identifier : requestedIdentifiers) {
ReferenceData cachedResult = cachedResults.get(identifier);
ReferenceData freshResult = loadedResult.getReferenceDataOrNull(identifier);
freshResult = (freshResult != null ? freshResult : new ReferenceData(identifier));
ReferenceData resolvedResult = getCombinedResult(requestedFields, cachedResult, freshResult);
saveFieldValues(resolvedResult);
result.addReferenceData(resolvedResult);