@Test void testFindAllFetchSplitsIdsOnTransactionInformation() { when(transactionInformation.isEntireRepositoryDirty(emd)).thenReturn(false); when(transactionInformation.isEntityDirty(EntityKey.create(emd, "0"))).thenReturn(true); when(transactionInformation.isEntityDirty(EntityKey.create(emd, "1"))).thenReturn(true); when(transactionInformation.isEntityDirty(EntityKey.create(emd, "2"))).thenReturn(false); when(transactionInformation.isEntityDirty(EntityKey.create(emd, "3"))).thenReturn(false); Fetch fetch = new Fetch().field("id"); Stream<Object> ids = Lists.<Object>newArrayList("0", "1", "2", "3").stream(); when(l2Cache.getBatch(eq(delegateRepository), cacheIdCaptor.capture(), eq(fetch))) .thenReturn(newArrayList(entities.get(3))); when(delegateRepository.findAll(repoIdCaptor.capture(), eq(fetch))) .thenReturn(of(entities.get(1))); List<Entity> retrievedEntities = l2CacheRepositoryDecorator.findAll(ids, fetch).collect(toList()); List<Object> decoratedRepoIds = repoIdCaptor.getValue().collect(toList()); assertEquals(newArrayList("0", "1"), decoratedRepoIds); List<Object> cacheIds = Lists.newArrayList(cacheIdCaptor.getValue()); assertEquals(newArrayList("2", "3"), cacheIds); assertEquals(2, retrievedEntities.size()); assertTrue(EntityUtils.equals(retrievedEntities.get(0), entities.get(1))); assertTrue(EntityUtils.equals(retrievedEntities.get(1), entities.get(3))); }
@SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); @Override Entity findOneById(Object id); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override Entity findOneById(Object id, Fetch fetch); }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); @Override Entity findOneById(Object id); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override Entity findOneById(Object id, Fetch fetch);  }