@Test public void testFindAll() { Object result1 = new Object(); Object result2 = new Object(); Object result3 = new Object(); context.checking(new Expectations() { { oneOf(suffixKeyTransformer).transform("one"); will(returnValue("ONE")); oneOf(suffixKeyTransformer).transform("two"); will(returnValue("TWO")); oneOf(suffixKeyTransformer).transform("three"); will(returnValue("THREE")); } }); cache.set(cacheKeyPrefix + "ONE", result1); cache.set(cacheKeyPrefix + "TWO", result2); cache.set(cacheKeyPrefix + "THREE", result3); PartialMapperResponse<List<String>, List<Object>> response = sut.execute(cacheKeySuffixes); assertFalse(response.hasUnhandledRequest()); assertEquals(3, response.getResponse().size()); assertTrue(response.getResponse().contains(result1)); assertTrue(response.getResponse().contains(result2)); assertTrue(response.getResponse().contains(result3)); context.assertIsSatisfied(); }
public PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute( final List<KeySuffixType> inKeySuffixes) { if (null == inKeySuffixes) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>( new ArrayList<CachedValueType>()); } List<String> keys = new ArrayList<String>(); Map<KeySuffixType, String> suffixToCacheKeyMap = new HashMap<KeySuffixType, String>(); for (KeySuffixType suffix : inKeySuffixes) { String cacheKey = cacheKeyPrefix + keySuffixTransformer.transform(suffix); suffixToCacheKeyMap.put(suffix, cacheKey); keys.add(cacheKey); } Map<String, CachedValueType> cachedResults = null; if (listOfLists) { cachedResults = (Map<String, CachedValueType>) getCache().multiGetList(keys); } else { cachedResults = (Map<String, CachedValueType>) getCache().multiGet(keys); } List<CachedValueType> foundResults = new LinkedList<CachedValueType>(); List<KeySuffixType> suffixesNotFound = new LinkedList<KeySuffixType>(); for (KeySuffixType suffix : inKeySuffixes) { if (!cachedResults.containsKey(suffixToCacheKeyMap.get(suffix)) || cachedResults.get(suffixToCacheKeyMap.get(suffix)) == null) { suffixesNotFound.add(suffix); } else { foundResults.add(cachedResults.get(suffixToCacheKeyMap.get(suffix))); } } if (suffixesNotFound.size() == 0) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults); } else { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults, suffixesNotFound); } }
PartialCacheResultsMapper extends CachedDomainMapper implements
        DomainMapper<List<KeySuffixType>,
        // line break
        PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>> { public PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute( final List<KeySuffixType> inKeySuffixes) { if (null == inKeySuffixes) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>( new ArrayList<CachedValueType>()); } List<String> keys = new ArrayList<String>(); Map<KeySuffixType, String> suffixToCacheKeyMap = new HashMap<KeySuffixType, String>(); for (KeySuffixType suffix : inKeySuffixes) { String cacheKey = cacheKeyPrefix + keySuffixTransformer.transform(suffix); suffixToCacheKeyMap.put(suffix, cacheKey); keys.add(cacheKey); } Map<String, CachedValueType> cachedResults = null; if (listOfLists) { cachedResults = (Map<String, CachedValueType>) getCache().multiGetList(keys); } else { cachedResults = (Map<String, CachedValueType>) getCache().multiGet(keys); } List<CachedValueType> foundResults = new LinkedList<CachedValueType>(); List<KeySuffixType> suffixesNotFound = new LinkedList<KeySuffixType>(); for (KeySuffixType suffix : inKeySuffixes) { if (!cachedResults.containsKey(suffixToCacheKeyMap.get(suffix)) || cachedResults.get(suffixToCacheKeyMap.get(suffix)) == null) { suffixesNotFound.add(suffix); } else { foundResults.add(cachedResults.get(suffixToCacheKeyMap.get(suffix))); } } if (suffixesNotFound.size() == 0) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults); } else { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults, suffixesNotFound); } } }
PartialCacheResultsMapper extends CachedDomainMapper implements
        DomainMapper<List<KeySuffixType>,
        // line break
        PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>> { public PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute( final List<KeySuffixType> inKeySuffixes) { if (null == inKeySuffixes) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>( new ArrayList<CachedValueType>()); } List<String> keys = new ArrayList<String>(); Map<KeySuffixType, String> suffixToCacheKeyMap = new HashMap<KeySuffixType, String>(); for (KeySuffixType suffix : inKeySuffixes) { String cacheKey = cacheKeyPrefix + keySuffixTransformer.transform(suffix); suffixToCacheKeyMap.put(suffix, cacheKey); keys.add(cacheKey); } Map<String, CachedValueType> cachedResults = null; if (listOfLists) { cachedResults = (Map<String, CachedValueType>) getCache().multiGetList(keys); } else { cachedResults = (Map<String, CachedValueType>) getCache().multiGet(keys); } List<CachedValueType> foundResults = new LinkedList<CachedValueType>(); List<KeySuffixType> suffixesNotFound = new LinkedList<KeySuffixType>(); for (KeySuffixType suffix : inKeySuffixes) { if (!cachedResults.containsKey(suffixToCacheKeyMap.get(suffix)) || cachedResults.get(suffixToCacheKeyMap.get(suffix)) == null) { suffixesNotFound.add(suffix); } else { foundResults.add(cachedResults.get(suffixToCacheKeyMap.get(suffix))); } } if (suffixesNotFound.size() == 0) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults); } else { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults, suffixesNotFound); } } PartialCacheResultsMapper(final Transformer<KeySuffixType, String> inKeySuffixTransformer,
            final String inCacheKeyPrefix, final Boolean isListOfLists); }
PartialCacheResultsMapper extends CachedDomainMapper implements
        DomainMapper<List<KeySuffixType>,
        // line break
        PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>> { public PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute( final List<KeySuffixType> inKeySuffixes) { if (null == inKeySuffixes) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>( new ArrayList<CachedValueType>()); } List<String> keys = new ArrayList<String>(); Map<KeySuffixType, String> suffixToCacheKeyMap = new HashMap<KeySuffixType, String>(); for (KeySuffixType suffix : inKeySuffixes) { String cacheKey = cacheKeyPrefix + keySuffixTransformer.transform(suffix); suffixToCacheKeyMap.put(suffix, cacheKey); keys.add(cacheKey); } Map<String, CachedValueType> cachedResults = null; if (listOfLists) { cachedResults = (Map<String, CachedValueType>) getCache().multiGetList(keys); } else { cachedResults = (Map<String, CachedValueType>) getCache().multiGet(keys); } List<CachedValueType> foundResults = new LinkedList<CachedValueType>(); List<KeySuffixType> suffixesNotFound = new LinkedList<KeySuffixType>(); for (KeySuffixType suffix : inKeySuffixes) { if (!cachedResults.containsKey(suffixToCacheKeyMap.get(suffix)) || cachedResults.get(suffixToCacheKeyMap.get(suffix)) == null) { suffixesNotFound.add(suffix); } else { foundResults.add(cachedResults.get(suffixToCacheKeyMap.get(suffix))); } } if (suffixesNotFound.size() == 0) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults); } else { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults, suffixesNotFound); } } PartialCacheResultsMapper(final Transformer<KeySuffixType, String> inKeySuffixTransformer,
            final String inCacheKeyPrefix, final Boolean isListOfLists); PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute(
            final List<KeySuffixType> inKeySuffixes); }
PartialCacheResultsMapper extends CachedDomainMapper implements
        DomainMapper<List<KeySuffixType>,
        // line break
        PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>> { public PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute( final List<KeySuffixType> inKeySuffixes) { if (null == inKeySuffixes) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>( new ArrayList<CachedValueType>()); } List<String> keys = new ArrayList<String>(); Map<KeySuffixType, String> suffixToCacheKeyMap = new HashMap<KeySuffixType, String>(); for (KeySuffixType suffix : inKeySuffixes) { String cacheKey = cacheKeyPrefix + keySuffixTransformer.transform(suffix); suffixToCacheKeyMap.put(suffix, cacheKey); keys.add(cacheKey); } Map<String, CachedValueType> cachedResults = null; if (listOfLists) { cachedResults = (Map<String, CachedValueType>) getCache().multiGetList(keys); } else { cachedResults = (Map<String, CachedValueType>) getCache().multiGet(keys); } List<CachedValueType> foundResults = new LinkedList<CachedValueType>(); List<KeySuffixType> suffixesNotFound = new LinkedList<KeySuffixType>(); for (KeySuffixType suffix : inKeySuffixes) { if (!cachedResults.containsKey(suffixToCacheKeyMap.get(suffix)) || cachedResults.get(suffixToCacheKeyMap.get(suffix)) == null) { suffixesNotFound.add(suffix); } else { foundResults.add(cachedResults.get(suffixToCacheKeyMap.get(suffix))); } } if (suffixesNotFound.size() == 0) { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults); } else { return new PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>>(foundResults, suffixesNotFound); } } PartialCacheResultsMapper(final Transformer<KeySuffixType, String> inKeySuffixTransformer,
            final String inCacheKeyPrefix, final Boolean isListOfLists); PartialMapperResponse<List<KeySuffixType>, List<CachedValueType>> execute(
            final List<KeySuffixType> inKeySuffixes);  }