Source:
<code>public List<ResourceHistoryTable> fetchEntities(RequestPartitionId thePartitionId, int theFromIndex, int theToIndex) { CriteriaBuilder cb = myEntityManager.getCriteriaBuilder(); CriteriaQuery<ResourceHistoryTable> criteriaQuery = cb.createQuery(ResourceHistoryTable.class); Root<ResourceHistoryTable> from = criteriaQuery.from(ResourceHistoryTable.class); addPredicatesToQuery(cb, thePartitionId, criteriaQuery, from); from.fetch("myProvenance", JoinType.LEFT); criteriaQuery.orderBy(cb.desc(from.get("myUpdated"))); TypedQuery<ResourceHistoryTable> query = myEntityManager.createQuery(criteriaQuery); query.setFirstResult(theFromIndex); query.setMaxResults(theToIndex - theFromIndex); List<ResourceHistoryTable> tables = query.getResultList(); if (tables.size() > 0) { ImmutableListMultimap<Long, ResourceHistoryTable> resourceIdToHistoryEntries = Multimaps.index(tables, ResourceHistoryTable::getResourceId); <START> Map<Long, Optional<String>> pidToForcedId = myIdHelperService.translatePidsToForcedIds(resourceIdToHistoryEntries.keySet()); <END> for (Long nextResourceId : resourceIdToHistoryEntries.keySet()) { List<ResourceHistoryTable> historyTables = resourceIdToHistoryEntries.get(nextResourceId); Optional<String> forcedId = myIdHelperService.translatePidIdToForcedId(new ResourcePersistentId(nextResourceId)); String resourceId; if (forcedId.isPresent()) { resourceId = historyTables.get(0).getResourceType() + '/' + forcedId.get(); } else { resourceId = historyTables.get(0).getResourceType() + '/' + nextResourceId; } for (ResourceHistoryTable nextHistoryTable : historyTables) { nextHistoryTable.setTransientForcedId(resourceId); } } } return tables; }</code><technical_language>used. If this is called build cache, store results</technical_language>

Target:
public List<ResourceHistoryTable> fetchEntities(RequestPartitionId thePartitionId, int theFromIndex, int theToIndex) { CriteriaBuilder cb = myEntityManager.getCriteriaBuilder(); CriteriaQuery<ResourceHistoryTable> criteriaQuery = cb.createQuery(ResourceHistoryTable.class); Root<ResourceHistoryTable> from = criteriaQuery.from(ResourceHistoryTable.class); addPredicatesToQuery(cb, thePartitionId, criteriaQuery, from); from.fetch("myProvenance", JoinType.LEFT); criteriaQuery.orderBy(cb.desc(from.get("myUpdated"))); TypedQuery<ResourceHistoryTable> query = myEntityManager.createQuery(criteriaQuery); query.setFirstResult(theFromIndex); query.setMaxResults(theToIndex - theFromIndex); List<ResourceHistoryTable> tables = query.getResultList(); if (tables.size() > 0) { ImmutableListMultimap<Long, ResourceHistoryTable> resourceIdToHistoryEntries = Multimaps.index(tables, ResourceHistoryTable::getResourceId); Map<Long, Optional<String>> pidToForcedId = myIdHelperService.translatePidsToForcedIds(resourceIdToHistoryEntries.keySet()); ourLog.trace("Translated IDs: {}", pidToForcedId); for (Long nextResourceId : resourceIdToHistoryEntries.keySet()) { List<ResourceHistoryTable> historyTables = resourceIdToHistoryEntries.get(nextResourceId); String resourceId; Optional<String> forcedId = pidToForcedId.get(nextResourceId); if (forcedId.isPresent()) { resourceId = forcedId.get(); } else { resourceId = nextResourceId.toString(); } for (ResourceHistoryTable nextHistoryTable : historyTables) { nextHistoryTable.setTransientForcedId(resourceId); } } } return tables; }